Committed by
GitHub
support specifying output filename (#380)
正在显示
4 个修改的文件
包含
18 行增加
和
9 行删除
| @@ -146,6 +146,7 @@ void CNonStreamingTextToSpeechDlg::DoDataExchange(CDataExchange* pDX) | @@ -146,6 +146,7 @@ void CNonStreamingTextToSpeechDlg::DoDataExchange(CDataExchange* pDX) | ||
| 146 | DDX_Control(pDX, IDC_SPEED, speed_); | 146 | DDX_Control(pDX, IDC_SPEED, speed_); |
| 147 | DDX_Control(pDX, IDOK, generate_btn_); | 147 | DDX_Control(pDX, IDOK, generate_btn_); |
| 148 | DDX_Control(pDX, IDC_TEXT, my_text_); | 148 | DDX_Control(pDX, IDC_TEXT, my_text_); |
| 149 | + DDX_Control(pDX, IDC_OUTPUT_FILENAME, output_filename_); | ||
| 149 | } | 150 | } |
| 150 | 151 | ||
| 151 | BEGIN_MESSAGE_MAP(CNonStreamingTextToSpeechDlg, CDialogEx) | 152 | BEGIN_MESSAGE_MAP(CNonStreamingTextToSpeechDlg, CDialogEx) |
| @@ -251,6 +252,7 @@ void CNonStreamingTextToSpeechDlg::Init() { | @@ -251,6 +252,7 @@ void CNonStreamingTextToSpeechDlg::Init() { | ||
| 251 | InitHint(); | 252 | InitHint(); |
| 252 | speaker_id_.SetWindowText(Utf8ToUtf16("0").c_str()); | 253 | speaker_id_.SetWindowText(Utf8ToUtf16("0").c_str()); |
| 253 | speed_.SetWindowText(Utf8ToUtf16("1.0").c_str()); | 254 | speed_.SetWindowText(Utf8ToUtf16("1.0").c_str()); |
| 255 | + output_filename_.SetWindowText(Utf8ToUtf16("./generated.wav").c_str()); | ||
| 254 | 256 | ||
| 255 | bool ok = true; | 257 | bool ok = true; |
| 256 | std::string error_message = "--------------------"; | 258 | std::string error_message = "--------------------"; |
| @@ -313,6 +315,10 @@ void CNonStreamingTextToSpeechDlg::Init() { | @@ -313,6 +315,10 @@ void CNonStreamingTextToSpeechDlg::Init() { | ||
| 313 | } | 315 | } |
| 314 | 316 | ||
| 315 | 317 | ||
| 318 | + static std::string ToString(const CString &s) { | ||
| 319 | + CT2CA pszConvertedAnsiString( s); | ||
| 320 | + return std::string(pszConvertedAnsiString); | ||
| 321 | + } | ||
| 316 | 322 | ||
| 317 | void CNonStreamingTextToSpeechDlg::OnBnClickedOk() { | 323 | void CNonStreamingTextToSpeechDlg::OnBnClickedOk() { |
| 318 | // TODO: Add your control notification handler code here | 324 | // TODO: Add your control notification handler code here |
| @@ -325,32 +331,32 @@ void CNonStreamingTextToSpeechDlg::OnBnClickedOk() { | @@ -325,32 +331,32 @@ void CNonStreamingTextToSpeechDlg::OnBnClickedOk() { | ||
| 325 | } | 331 | } |
| 326 | 332 | ||
| 327 | speed_.GetWindowText(s); | 333 | speed_.GetWindowText(s); |
| 328 | - float speed = _ttof(s); | 334 | + float speed = static_cast<float>(_ttof(s)); |
| 329 | if (speed < 0) { | 335 | if (speed < 0) { |
| 330 | AfxMessageBox(Utf8ToUtf16("Please input a valid speed").c_str(), MB_OK); | 336 | AfxMessageBox(Utf8ToUtf16("Please input a valid speed").c_str(), MB_OK); |
| 331 | return; | 337 | return; |
| 332 | } | 338 | } |
| 333 | 339 | ||
| 334 | my_text_.GetWindowText(s); | 340 | my_text_.GetWindowText(s); |
| 335 | - CT2CA pszConvertedAnsiString(s); | ||
| 336 | - std::string ss(pszConvertedAnsiString); | 341 | + std::string ss = ToString(s); |
| 337 | if (ss.empty()) { | 342 | if (ss.empty()) { |
| 338 | AfxMessageBox(Utf8ToUtf16("Please input your text").c_str(), MB_OK); | 343 | AfxMessageBox(Utf8ToUtf16("Please input your text").c_str(), MB_OK); |
| 339 | return; | 344 | return; |
| 340 | } | 345 | } |
| 341 | 346 | ||
| 342 | -const SherpaOnnxGeneratedAudio *audio = | 347 | + const SherpaOnnxGeneratedAudio *audio = |
| 343 | SherpaOnnxOfflineTtsGenerate(tts_, ss.c_str(), speaker_id, speed); | 348 | SherpaOnnxOfflineTtsGenerate(tts_, ss.c_str(), speaker_id, speed); |
| 344 | - std::string filename = "./generated.wav"; | ||
| 345 | -int ok = SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate, | 349 | + output_filename_.GetWindowText(s); |
| 350 | + std::string filename = ToString(s); | ||
| 351 | + int ok = SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate, | ||
| 346 | filename.c_str()); | 352 | filename.c_str()); |
| 347 | 353 | ||
| 348 | SherpaOnnxDestroyOfflineTtsGeneratedAudio(audio); | 354 | SherpaOnnxDestroyOfflineTtsGeneratedAudio(audio); |
| 349 | 355 | ||
| 350 | if (ok) { | 356 | if (ok) { |
| 351 | - AfxMessageBox(Utf8ToUtf16("Saved to ./generated.wav successfully").c_str(), MB_OK); | 357 | + AfxMessageBox(Utf8ToUtf16(std::string("Saved to ") + filename + " successfully").c_str(), MB_OK); |
| 352 | } else { | 358 | } else { |
| 353 | - AfxMessageBox(Utf8ToUtf16("Failed to save to ./generated.wav").c_str(), MB_OK); | 359 | + AfxMessageBox(Utf8ToUtf16(std::string("Failed to save to ") + filename).c_str(), MB_OK); |
| 354 | } | 360 | } |
| 355 | 361 | ||
| 356 | //CDialogEx::OnOK(); | 362 | //CDialogEx::OnOK(); |
| @@ -11,6 +11,8 @@ | @@ -11,6 +11,8 @@ | ||
| 11 | #define IDC_SPEED 1003 | 11 | #define IDC_SPEED 1003 |
| 12 | #define IDC_TEXT 1004 | 12 | #define IDC_TEXT 1004 |
| 13 | #define IDC_HINT 1005 | 13 | #define IDC_HINT 1005 |
| 14 | +#define IDC_EDIT1 1006 | ||
| 15 | +#define IDC_OUTPUT_FILENAME 1006 | ||
| 14 | 16 | ||
| 15 | // Next default values for new objects | 17 | // Next default values for new objects |
| 16 | // | 18 | // |
| @@ -18,7 +20,7 @@ | @@ -18,7 +20,7 @@ | ||
| 18 | #ifndef APSTUDIO_READONLY_SYMBOLS | 20 | #ifndef APSTUDIO_READONLY_SYMBOLS |
| 19 | #define _APS_NEXT_RESOURCE_VALUE 130 | 21 | #define _APS_NEXT_RESOURCE_VALUE 130 |
| 20 | #define _APS_NEXT_COMMAND_VALUE 32771 | 22 | #define _APS_NEXT_COMMAND_VALUE 32771 |
| 21 | -#define _APS_NEXT_CONTROL_VALUE 1006 | 23 | +#define _APS_NEXT_CONTROL_VALUE 1007 |
| 22 | #define _APS_NEXT_SYMED_VALUE 101 | 24 | #define _APS_NEXT_SYMED_VALUE 101 |
| 23 | #endif | 25 | #endif |
| 24 | #endif | 26 | #endif |
-
请 注册 或 登录 后发表评论