support specifying output filename (#380)
This commit is contained in:
Binary file not shown.
@@ -146,6 +146,7 @@ void CNonStreamingTextToSpeechDlg::DoDataExchange(CDataExchange* pDX)
|
|||||||
DDX_Control(pDX, IDC_SPEED, speed_);
|
DDX_Control(pDX, IDC_SPEED, speed_);
|
||||||
DDX_Control(pDX, IDOK, generate_btn_);
|
DDX_Control(pDX, IDOK, generate_btn_);
|
||||||
DDX_Control(pDX, IDC_TEXT, my_text_);
|
DDX_Control(pDX, IDC_TEXT, my_text_);
|
||||||
|
DDX_Control(pDX, IDC_OUTPUT_FILENAME, output_filename_);
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_MESSAGE_MAP(CNonStreamingTextToSpeechDlg, CDialogEx)
|
BEGIN_MESSAGE_MAP(CNonStreamingTextToSpeechDlg, CDialogEx)
|
||||||
@@ -251,6 +252,7 @@ void CNonStreamingTextToSpeechDlg::Init() {
|
|||||||
InitHint();
|
InitHint();
|
||||||
speaker_id_.SetWindowText(Utf8ToUtf16("0").c_str());
|
speaker_id_.SetWindowText(Utf8ToUtf16("0").c_str());
|
||||||
speed_.SetWindowText(Utf8ToUtf16("1.0").c_str());
|
speed_.SetWindowText(Utf8ToUtf16("1.0").c_str());
|
||||||
|
output_filename_.SetWindowText(Utf8ToUtf16("./generated.wav").c_str());
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
std::string error_message = "--------------------";
|
std::string error_message = "--------------------";
|
||||||
@@ -313,6 +315,10 @@ void CNonStreamingTextToSpeechDlg::Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static std::string ToString(const CString &s) {
|
||||||
|
CT2CA pszConvertedAnsiString( s);
|
||||||
|
return std::string(pszConvertedAnsiString);
|
||||||
|
}
|
||||||
|
|
||||||
void CNonStreamingTextToSpeechDlg::OnBnClickedOk() {
|
void CNonStreamingTextToSpeechDlg::OnBnClickedOk() {
|
||||||
// TODO: Add your control notification handler code here
|
// TODO: Add your control notification handler code here
|
||||||
@@ -325,32 +331,32 @@ void CNonStreamingTextToSpeechDlg::OnBnClickedOk() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
speed_.GetWindowText(s);
|
speed_.GetWindowText(s);
|
||||||
float speed = _ttof(s);
|
float speed = static_cast<float>(_ttof(s));
|
||||||
if (speed < 0) {
|
if (speed < 0) {
|
||||||
AfxMessageBox(Utf8ToUtf16("Please input a valid speed").c_str(), MB_OK);
|
AfxMessageBox(Utf8ToUtf16("Please input a valid speed").c_str(), MB_OK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my_text_.GetWindowText(s);
|
my_text_.GetWindowText(s);
|
||||||
CT2CA pszConvertedAnsiString(s);
|
std::string ss = ToString(s);
|
||||||
std::string ss(pszConvertedAnsiString);
|
|
||||||
if (ss.empty()) {
|
if (ss.empty()) {
|
||||||
AfxMessageBox(Utf8ToUtf16("Please input your text").c_str(), MB_OK);
|
AfxMessageBox(Utf8ToUtf16("Please input your text").c_str(), MB_OK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SherpaOnnxGeneratedAudio *audio =
|
const SherpaOnnxGeneratedAudio *audio =
|
||||||
SherpaOnnxOfflineTtsGenerate(tts_, ss.c_str(), speaker_id, speed);
|
SherpaOnnxOfflineTtsGenerate(tts_, ss.c_str(), speaker_id, speed);
|
||||||
std::string filename = "./generated.wav";
|
output_filename_.GetWindowText(s);
|
||||||
int ok = SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate,
|
std::string filename = ToString(s);
|
||||||
|
int ok = SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate,
|
||||||
filename.c_str());
|
filename.c_str());
|
||||||
|
|
||||||
SherpaOnnxDestroyOfflineTtsGeneratedAudio(audio);
|
SherpaOnnxDestroyOfflineTtsGeneratedAudio(audio);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
AfxMessageBox(Utf8ToUtf16("Saved to ./generated.wav successfully").c_str(), MB_OK);
|
AfxMessageBox(Utf8ToUtf16(std::string("Saved to ") + filename + " successfully").c_str(), MB_OK);
|
||||||
} else {
|
} else {
|
||||||
AfxMessageBox(Utf8ToUtf16("Failed to save to ./generated.wav").c_str(), MB_OK);
|
AfxMessageBox(Utf8ToUtf16(std::string("Failed to save to ") + filename).c_str(), MB_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
//CDialogEx::OnOK();
|
//CDialogEx::OnOK();
|
||||||
|
|||||||
@@ -45,4 +45,5 @@ protected:
|
|||||||
|
|
||||||
SherpaOnnxOfflineTts *tts_;
|
SherpaOnnxOfflineTts *tts_;
|
||||||
CEdit my_text_;
|
CEdit my_text_;
|
||||||
|
CEdit output_filename_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#define IDC_SPEED 1003
|
#define IDC_SPEED 1003
|
||||||
#define IDC_TEXT 1004
|
#define IDC_TEXT 1004
|
||||||
#define IDC_HINT 1005
|
#define IDC_HINT 1005
|
||||||
|
#define IDC_EDIT1 1006
|
||||||
|
#define IDC_OUTPUT_FILENAME 1006
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
//
|
//
|
||||||
@@ -18,7 +20,7 @@
|
|||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 130
|
#define _APS_NEXT_RESOURCE_VALUE 130
|
||||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1006
|
#define _APS_NEXT_CONTROL_VALUE 1007
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user