eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

espeakedit.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2013 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * Copyright (C) 2013 by Reece H. Dunn *
  5. * *
  6. * This program is free software; you can redistribute it and/or modify *
  7. * it under the terms of the GNU General Public License as published by *
  8. * the Free Software Foundation; either version 3 of the License, or *
  9. * (at your option) any later version. *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with this program; if not, see: *
  18. * <http://www.gnu.org/licenses/>. *
  19. ***************************************************************************/
  20. #include "wx/wx.h"
  21. #include "wx/wfstream.h"
  22. #include "wx/image.h"
  23. #include "wx/filename.h"
  24. #include "wx/numdlg.h"
  25. #include "wx/mdi.h"
  26. #include "wx/laywin.h"
  27. #include "wx/sashwin.h"
  28. #include "wx/utils.h"
  29. #include "wx/html/htmlwin.h"
  30. #include <locale.h>
  31. #include "speak_lib.h"
  32. #include "main.h"
  33. #include "speech.h"
  34. #include "options.h"
  35. #include "phoneme.h"
  36. #include "synthesize.h"
  37. #include "voice.h"
  38. #include "spect.h"
  39. #include "translate.h"
  40. #include "prosodydisplay.h"
  41. #if wxCHECK_VERSION(3, 0, 0)
  42. #define wxOPEN wxFD_OPEN
  43. #define wxSAVE wxFD_SAVE
  44. #endif
  45. static const char *about_string2 = "espeakedit: %s\nAuthor: Jonathan Duddington (c) 2009\n\n"
  46. "Licensed under GNU General Public License version 3\n"
  47. "http://espeak.sourceforge.net/";
  48. static const char *about_string = "<font size=0><b>espeakedit </b> %s<br>Author: Jonathan Duddington (c) 2009<br>"
  49. "<a href=\"http://espeak.sourceforge.net/\">http://espeak.sourceforge.net</a><br>"
  50. "Licensed under <a href=\"http://espeak.sourceforge.net/license.html\">GNU General Public License version 3</a></font>";
  51. const char *path_data;
  52. extern void TestTest(int control);
  53. extern void CompareLexicon(int);
  54. extern void ConvertToUtf8();
  55. extern void DictionaryFormat(const char *dictname);
  56. extern void DictionarySort(const char *dictname);
  57. extern void init_z();
  58. extern void CompilePhonemeData(void);
  59. extern void CompileSampleRate(void);
  60. extern void CompileMbrola();
  61. extern void CompileIntonation();
  62. extern void InitSpectrumDisplay();
  63. extern void InitProsodyDisplay();
  64. extern void InitWaveDisplay();
  65. extern void VowelChart(int control, char *fname);
  66. extern void MakeVowelLists(void);
  67. extern void MakeWordFreqList();
  68. extern wxMenu *speak_menu;
  69. extern wxMenu *data_menu;
  70. MyFrame *myframe = NULL;
  71. SpectDisplay *currentcanvas = NULL;
  72. ProsodyDisplay *prosodycanvas = NULL;
  73. wxNotebook *notebook = NULL;
  74. wxNotebook *screenpages = NULL;
  75. wxProgressDialog *progress;
  76. int progress_max;
  77. int gui_flag = 0;
  78. int frame_x, frame_y, frame_w, frame_h;
  79. int adding_page = 0; // fix for wxWidgets (2,8,7) bug, adding first page to a wxNotebook gives emptystring for GetPageTex() in Notebook_Page_Changed event.
  80. IMPLEMENT_APP(MyApp)
  81. wxString AppName = _T("espeakedit");
  82. int MyApp::OnExit()
  83. {//================
  84. ConfigSave(1);
  85. return(0);
  86. }
  87. static const char *help_text =
  88. "\n\nespeakedit\n"
  89. "\tRun with GUI\n"
  90. "espeakedit --compile\n"
  91. "\tCompile phoneme data in espeak-data/phsource\n"
  92. "\tand dictionary data in espeak-data/dictsource\n";
  93. // Initialise this in OnInit, not statically
  94. bool MyApp::OnInit(void)
  95. {//=====================
  96. int j;
  97. const wxChar *p;
  98. char param[80];
  99. if(argc > 1)
  100. {
  101. p = argv[1];
  102. j = 0;
  103. while((param[j] = p[j]) != 0) j++;
  104. if((strcmp(param,"--help")==0) || (strcmp(param,"-h")==0))
  105. {
  106. printf(about_string2,espeak_Info(NULL));
  107. printf("%s", help_text);
  108. exit(0);
  109. }
  110. ConfigInit(true);
  111. if(strcmp(param,"--compile")==0)
  112. {
  113. samplerate_native = samplerate = 22050;
  114. CompilePhonemeData();
  115. CompileIntonation();
  116. }
  117. exit(0);
  118. }
  119. ConfigInit(false);
  120. gui_flag = 1;
  121. // It seems that the wctype functions don't work until the locale has been set
  122. // to something other than the default "C". Then, not only Latin1 but also the
  123. // other characters give the correct results with iswalpha() etc.
  124. if(setlocale(LC_CTYPE,"en_US.UTF-8") == NULL)
  125. {
  126. if(setlocale(LC_CTYPE,"UTF-8") == NULL)
  127. setlocale(LC_CTYPE,"");
  128. }
  129. if((frame_w == 0) || (frame_h == 0))
  130. {
  131. frame_w = 800;
  132. frame_h = 768;
  133. }
  134. // Create the main frame window
  135. myframe = new MyFrame(NULL, -1, AppName, wxPoint(frame_x, frame_y), wxSize(frame_w, frame_h),
  136. wxDEFAULT_FRAME_STYLE |
  137. wxNO_FULL_REPAINT_ON_RESIZE |
  138. wxHSCROLL | wxVSCROLL);
  139. // Make a menubar
  140. myframe->SetMenuBar(MakeMenu(0, voice_name2));
  141. myframe->CreateStatusBar();
  142. myframe->SetVoiceTitle(voice_name2);
  143. // myframe->Maximize();
  144. myframe->Show(TRUE);
  145. SetTopWindow(myframe);
  146. wxInitAllImageHandlers();
  147. // wxImage::AddHandler(wxPNGHandler);
  148. return TRUE;
  149. }
  150. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  151. EVT_CHAR(MyFrame::OnKey)
  152. EVT_MENU(MENU_ABOUT, MyFrame::OnAbout)
  153. EVT_MENU(MENU_DOCS, MyFrame::OnAbout)
  154. EVT_MENU(MENU_SPECTRUM, MyFrame::OnNewWindow)
  155. EVT_MENU(MENU_SPECTRUM2, MyFrame::OnNewWindow)
  156. EVT_MENU(MENU_PROSODY, MyFrame::OnProsody)
  157. EVT_MENU(MENU_OPT_SPEED, MyFrame::OnOptions)
  158. EVT_MENU(MENU_OPT_PUNCT, MyFrame::OnOptions)
  159. EVT_MENU(MENU_OPT_SPELL, MyFrame::OnOptions)
  160. EVT_MENU(MENU_OPT_SPELL2, MyFrame::OnOptions)
  161. EVT_MENU(MENU_PATH0, MyFrame::OnOptions)
  162. EVT_MENU(MENU_PATH1, MyFrame::OnOptions)
  163. EVT_MENU(MENU_PATH2, MyFrame::OnOptions)
  164. EVT_MENU(MENU_PATH3, MyFrame::OnOptions)
  165. EVT_MENU(MENU_PATH4, MyFrame::OnOptions)
  166. EVT_MENU(MENU_COMPILE_PH, MyFrame::OnTools)
  167. EVT_MENU(MENU_COMPILE_PH2, MyFrame::OnTools)
  168. EVT_MENU(MENU_COMPILE_DICT, MyFrame::OnTools)
  169. EVT_MENU(MENU_COMPILE_DICT_DEBUG, MyFrame::OnTools)
  170. EVT_MENU(MENU_FORMAT_DICTIONARY, MyFrame::OnTools)
  171. EVT_MENU(MENU_SORT_DICTIONARY, MyFrame::OnTools)
  172. EVT_MENU(MENU_COMPILE_MBROLA, MyFrame::OnTools)
  173. EVT_MENU(MENU_COMPILE_INTONATION, MyFrame::OnTools)
  174. EVT_MENU(MENU_QUIT, MyFrame::OnQuit)
  175. EVT_MENU(MENU_SPEAK_TRANSLATE, MyFrame::OnSpeak)
  176. EVT_MENU(MENU_SPEAK_RULES, MyFrame::OnSpeak)
  177. EVT_MENU(MENU_SPEAK_IPA, MyFrame::OnSpeak)
  178. EVT_MENU(MENU_SPEAK_TEXT, MyFrame::OnSpeak)
  179. EVT_MENU(MENU_SPEAK_FILE, MyFrame::OnSpeak)
  180. EVT_MENU(MENU_SPEAK_STOP, MyFrame::OnSpeak)
  181. EVT_MENU(MENU_SPEAK_PAUSE, MyFrame::OnSpeak)
  182. EVT_MENU(MENU_SPEAK_VOICE, MyFrame::OnSpeak)
  183. EVT_MENU(MENU_SPEAK_VOICE_VARIANT, MyFrame::OnSpeak)
  184. EVT_MENU(MENU_LOAD_WAV, MyFrame::OnTools)
  185. EVT_MENU(MENU_VOWELCHART1, MyFrame::OnTools)
  186. EVT_MENU(MENU_VOWELCHART2, MyFrame::OnTools)
  187. EVT_MENU(MENU_VOWELCHART3, MyFrame::OnTools)
  188. EVT_MENU(MENU_LEXICON_RU, MyFrame::OnTools)
  189. EVT_MENU(MENU_LEXICON_BG, MyFrame::OnTools)
  190. EVT_MENU(MENU_LEXICON_DE, MyFrame::OnTools)
  191. EVT_MENU(MENU_LEXICON_IT, MyFrame::OnTools)
  192. EVT_MENU(MENU_LEXICON_TEST, MyFrame::OnTools)
  193. EVT_MENU(MENU_TO_UTF8, MyFrame::OnTools)
  194. EVT_MENU(MENU_COUNT_WORDS, MyFrame::OnTools)
  195. EVT_MENU(MENU_TEST, MyFrame::OnTools)
  196. EVT_MENU(MENU_TEST2, MyFrame::OnTools)
  197. EVT_MENU(SPECTSEQ_SAVE, MyFrame::PageCmd)
  198. EVT_MENU(SPECTSEQ_SAVEAS, MyFrame::PageCmd)
  199. EVT_MENU(SPECTSEQ_SAVESELECT, MyFrame::PageCmd)
  200. EVT_MENU(SPECTSEQ_CLOSE, MyFrame::PageCmd)
  201. EVT_MENU(SPECTSEQ_SAVEPITCH, MyFrame::PageCmd)
  202. EVT_MENU(MENU_CLOSE_ALL, MyFrame::PageCmd)
  203. EVT_NOTEBOOK_PAGE_CHANGED(ID_SCREENPAGES, MyFrame::OnPageChanged)
  204. EVT_TIMER(1, MyFrame::OnTimer)
  205. END_EVENT_TABLE()
  206. MyFrame::~MyFrame(void)
  207. {//====================
  208. myframe->Maximize(false);
  209. myframe->Show(false);
  210. myframe->Iconize(false); // os=Windows, get the non-iconsized size
  211. myframe->GetPosition(&frame_x, &frame_y);
  212. myframe->GetSize(&frame_w, &frame_h);
  213. }
  214. MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
  215. const long style):
  216. wxFrame(parent, id, title, pos, size, style)
  217. {//===================================================================================================================
  218. // Main Frame constructor
  219. int error_flag = 0;
  220. int result;
  221. int param;
  222. int srate;
  223. notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxSize(312,760));
  224. // notebook->AddPage(voicedlg,_T("Voice"),FALSE);
  225. formantdlg = new FormantDlg(notebook);
  226. notebook->AddPage(formantdlg,_T(" Spect"),FALSE);
  227. voicedlg = new VoiceDlg(notebook);
  228. transldlg = new TranslDlg(notebook);
  229. notebook->AddPage(transldlg,_T("Text"),TRUE);
  230. screenpages = new wxNotebook(this, ID_SCREENPAGES, wxDefaultPosition, wxSize(554,702));
  231. wxBoxSizer *framesizer = new wxBoxSizer( wxHORIZONTAL );
  232. framesizer->Add(
  233. notebook,
  234. 0, // make horizontally stretchable
  235. wxEXPAND | // make vertically stretchable
  236. wxALL, // and make border all around
  237. 4 ); // set border width
  238. framesizer->Add(
  239. screenpages,
  240. 1, // make horizontally stretchable
  241. wxEXPAND | // make vertically stretchable
  242. wxALL, // and make border all around
  243. 4 ); // set border width
  244. SetSizer( framesizer ); // use the sizer for layout
  245. framesizer->SetSizeHints( this ); // set size hints to honour minimum size
  246. SetSize(pos.x, pos.y, size.GetWidth(), size.GetHeight());
  247. LoadConfig();
  248. if((result = LoadPhData(&srate)) != 1)
  249. {
  250. if(result == -1)
  251. wxLogError(_T("Failed to read espeak-data/phontab,phondata,phonindex\nPath = ")+wxString(path_home,wxConvLocal)+_T("\n\nThe 'eSpeak' package needs to be installed"));
  252. else
  253. wxLogError(_T("Wrong version of espeak-data at:\n")+ wxString(path_home,wxConvLocal)+_T("\nVersion 0x%x (expects 0x%x)"),result,version_phdata);
  254. error_flag = 1;
  255. srate = 22050;
  256. }
  257. WavegenInit(srate,0);
  258. WavegenInitSound();
  259. f_trans = stdout;
  260. option_ssml = 1;
  261. option_phoneme_input = 1;
  262. // if(LoadVoice(voice_name,0) == NULL)
  263. if(SetVoiceByName(voice_name2) != EE_OK)
  264. {
  265. if(error_flag==0)
  266. wxLogError(_T("Failed to load voice data"));
  267. strcpy(dictionary_name,"en");
  268. }
  269. WavegenSetVoice(voice);
  270. for(param=0; param<N_SPEECH_PARAM; param++)
  271. param_stack[0].parameter[param] = param_defaults[param];
  272. SetParameter(espeakRATE,option_speed,0);
  273. SetSpeed(3);
  274. SynthesizeInit();
  275. InitSpectrumDisplay();
  276. InitProsodyDisplay();
  277. // InitWaveDisplay();
  278. espeak_ListVoices(NULL);
  279. m_timer.SetOwner(this,1);
  280. m_timer.Start(500); /* 0.5 timer */
  281. } // end of MyFrame::MyFrame
  282. void MyFrame::SetVoiceTitle(char *voice_name)
  283. {//==========================================
  284. char buf[100];
  285. if(samplerate_native == 22050)
  286. sprintf(buf, " - %s voice", voice_name);
  287. else
  288. sprintf(buf, " - %s voice %dHz", voice_name, samplerate_native);
  289. SetTitle(AppName + wxString(buf,wxConvLocal));
  290. if((data_menu != NULL) && (translator != NULL))
  291. {
  292. sprintf(buf,"Compile &dictionary '%s'",translator->dictionary_name);
  293. data_menu->SetLabel(MENU_COMPILE_DICT, wxString(buf,wxConvLocal));
  294. sprintf(buf,"&Layout '%s_rules' file",translator->dictionary_name);
  295. data_menu->SetLabel(MENU_FORMAT_DICTIONARY, wxString(buf,wxConvLocal));
  296. sprintf(buf,"&Sort '%s_rules' file",translator->dictionary_name);
  297. data_menu->SetLabel(MENU_SORT_DICTIONARY, wxString(buf,wxConvLocal));
  298. }
  299. }
  300. void MyFrame::PageCmd(wxCommandEvent& event)
  301. {//=========================================
  302. int pagenum;
  303. int ix;
  304. int n_pages;
  305. SpectDisplay *page;
  306. // if(currentcanvas != NULL)
  307. {
  308. pagenum = screenpages->GetSelection();
  309. switch(event.GetId())
  310. {
  311. case SPECTSEQ_SAVE:
  312. currentcanvas->Save(currentcanvas->savepath);
  313. break;
  314. case SPECTSEQ_SAVEAS:
  315. currentcanvas->Save();
  316. break;
  317. case SPECTSEQ_SAVESELECT:
  318. currentcanvas->Save(_T(""), 1);
  319. break;
  320. case SPECTSEQ_CLOSE:
  321. if(screenpages->GetPageText(pagenum) != _T("Prosody"))
  322. {
  323. currentcanvas->OnActivate(0);
  324. }
  325. screenpages->DeletePage(pagenum);
  326. if((n_pages = screenpages->GetPageCount()) > 0)
  327. {
  328. if(pagenum >= n_pages)
  329. pagenum--;
  330. page = (SpectDisplay *)screenpages->GetPage(pagenum);
  331. if(screenpages->GetPageText(pagenum) == _T("Prosody"))
  332. {
  333. MakeMenu(3, NULL);
  334. }
  335. else
  336. {
  337. page->OnActivate(1);
  338. MakeMenu(2, NULL);
  339. }
  340. }
  341. else
  342. {
  343. MakeMenu(1, NULL);
  344. }
  345. break;
  346. case MENU_CLOSE_ALL:
  347. n_pages = screenpages->GetPageCount();
  348. for(ix=n_pages-1; ix>=0; ix--)
  349. {
  350. screenpages->DeletePage(ix);
  351. }
  352. currentcanvas = NULL;
  353. MakeMenu(1, NULL);
  354. break;
  355. case SPECTSEQ_SAVEPITCH:
  356. currentcanvas->SavePitchenv(currentcanvas->spectseq->pitchenv);
  357. break;
  358. }
  359. }
  360. }
  361. void MyFrame::OnPageChanged(wxNotebookEvent& event)
  362. {//=================================================
  363. int pagenum;
  364. wxString title;
  365. SpectDisplay *page;
  366. pagenum = event.GetSelection();
  367. if(event.GetId() == ID_SCREENPAGES)
  368. {
  369. title = screenpages->GetPageText(pagenum);
  370. if((title != _T("Prosody")) && (adding_page != 2))
  371. {
  372. page = (SpectDisplay *)screenpages->GetPage(pagenum);
  373. if(page != currentcanvas)
  374. {
  375. if(currentcanvas != NULL)
  376. {
  377. currentcanvas->OnActivate(0);
  378. }
  379. page->OnActivate(1);
  380. }
  381. MakeMenu(2, NULL);
  382. }
  383. else
  384. {
  385. MakeMenu(3, NULL);
  386. }
  387. }
  388. adding_page = 0; // work around for wxNotebook bug (version 2.8.7)
  389. }
  390. void MyFrame::OnKey(wxKeyEvent& event)
  391. {
  392. int key;
  393. key = event.GetKeyCode();
  394. if((currentcanvas != NULL) && (currentcanvas != FindFocus()))
  395. {
  396. if((key == WXK_F1) || (key == WXK_F2))
  397. {
  398. currentcanvas->OnKey(event);
  399. currentcanvas->SetFocus();
  400. return;
  401. }
  402. }
  403. event.Skip();
  404. }
  405. void MyFrame::OnTimer(wxTimerEvent &event)
  406. //****************************************
  407. {
  408. SynthOnTimer();
  409. }
  410. void MyFrame::OnQuit(wxCommandEvent& event)
  411. {
  412. switch(event.GetId())
  413. {
  414. case MENU_QUIT:
  415. Close(TRUE);
  416. break;
  417. case MENU_CLOSE_ALL:
  418. break;
  419. }
  420. }
  421. class HtmlWindow: public wxHtmlWindow
  422. {
  423. public:
  424. HtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style);
  425. void OnLinkClicked(const wxHtmlLinkInfo& link);
  426. };
  427. HtmlWindow::HtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
  428. wxHtmlWindow(parent, id, pos, size, style)
  429. {
  430. }
  431. void HtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
  432. {
  433. if(wxLaunchDefaultBrowser(link.GetHref()) == FALSE)
  434. wxLogStatus(_T("Failed to launch default browser: "+link.GetHref()));
  435. }
  436. void MyFrame::OnAbout(wxCommandEvent& event)
  437. {//=========================================
  438. int result;
  439. char buf[300];
  440. wxString url_docs;
  441. wxBoxSizer *topsizer;
  442. HtmlWindow *html;
  443. wxDialog dlg(this, wxID_ANY, wxString(_("About")));
  444. topsizer = new wxBoxSizer(wxVERTICAL);
  445. switch(event.GetId())
  446. {
  447. case MENU_ABOUT:
  448. {
  449. sprintf(buf,about_string,espeak_Info(NULL));
  450. html = new HtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
  451. html -> SetBorders(0);
  452. html -> SetPage(wxString(buf,wxConvLocal));
  453. html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
  454. html -> GetInternalRepresentation() -> GetHeight());
  455. topsizer -> Add(html, 1, wxALL, 10);
  456. //#if wxUSE_STATLINE
  457. // topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  458. //#endif // wxUSE_STATLINE
  459. wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
  460. bu1 -> SetDefault();
  461. topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
  462. dlg.SetSizer(topsizer);
  463. topsizer -> Fit(&dlg);
  464. dlg.ShowModal();
  465. }
  466. break;
  467. case MENU_DOCS:
  468. strcpy(buf,"/docs/docindex.html");
  469. url_docs = wxGetCwd() + wxString(buf,wxConvLocal); // look for "docs" in the current directory
  470. if(!wxFileExists(url_docs))
  471. {
  472. strcpy(buf,"http://espeak.sourceforge.net/docindex.html");
  473. url_docs = wxString(buf,wxConvLocal);
  474. }
  475. else
  476. {
  477. url_docs = _T("file://") + url_docs;
  478. }
  479. result = wxLaunchDefaultBrowser(url_docs);
  480. if(result == 0)
  481. wxLogStatus(_T("Failed to launch default browser: "+url_docs));
  482. break;
  483. }
  484. }
  485. void OnOptions2(int event_id)
  486. {//==========================
  487. wxString string;
  488. int value;
  489. switch(event_id)
  490. {
  491. case MENU_OPT_SPEED:
  492. value = wxGetNumberFromUser(_T(""),_T(""),_T("Speed"),option_speed,80,500);
  493. if(value > 0)
  494. {
  495. option_speed = value;
  496. SetParameter(espeakRATE,option_speed,0);
  497. SetSpeed(3);
  498. }
  499. break;
  500. case MENU_OPT_PUNCT:
  501. transldlg->t_source->SetValue(_T("<tts:style field=\"punctuation\" mode=\"all\">\n"));
  502. transldlg->t_source->SetInsertionPointEnd();
  503. notebook->SetSelection(1);
  504. break;
  505. case MENU_OPT_SPELL:
  506. transldlg->t_source->SetValue(_T("<say-as interpret-as=\"characters\">\n"));
  507. transldlg->t_source->SetInsertionPointEnd();
  508. notebook->SetSelection(1);
  509. break;
  510. case MENU_OPT_SPELL2:
  511. transldlg->t_source->SetValue(_T("<say-as interpret-as=\"tts:char\">\n"));
  512. transldlg->t_source->SetInsertionPointEnd();
  513. notebook->SetSelection(1);
  514. break;
  515. case MENU_PATH0:
  516. string = wxFileSelector(_T("Master phonemes file"),wxFileName(path_phfile).GetPath(),
  517. _T("phonemes"),_T(""),_T("*"),wxOPEN);
  518. if(!string.IsEmpty())
  519. {
  520. path_phfile = string;
  521. }
  522. break;
  523. case MENU_PATH1:
  524. string = wxDirSelector(_T("Phoneme source directory"),path_phsource);
  525. if(!string.IsEmpty())
  526. {
  527. path_phsource = string;
  528. }
  529. break;
  530. case MENU_PATH2:
  531. string = wxDirSelector(_T("Dictionary source directory"),path_dictsource);
  532. if(!string.IsEmpty())
  533. {
  534. path_dictsource = string;
  535. }
  536. break;
  537. case MENU_PATH3:
  538. string = wxFileSelector(_T("Sound output file"),wxFileName(path_speech).GetPath(),
  539. _T(""),_T("WAV"),_T("*"),wxSAVE);
  540. if(!string.IsEmpty())
  541. {
  542. path_speech = string;
  543. }
  544. break;
  545. case MENU_PATH4:
  546. string = wxFileSelector(_T("Voice file to modify formant peaks"),wxFileName(path_speech).GetPath(),
  547. _T(""),_T(""),_T("*"),wxOPEN);
  548. if(!string.IsEmpty())
  549. {
  550. path_modifiervoice = string;
  551. }
  552. break;
  553. }
  554. ConfigSetPaths();
  555. }
  556. void MyFrame::OnOptions(wxCommandEvent& event)
  557. {//===========================================
  558. OnOptions2(event.GetId());
  559. }
  560. void DisplayErrorFile(const char *fname)
  561. {//=====================================
  562. int len;
  563. FILE *f;
  564. char *msg;
  565. wxString msg_string;
  566. len = GetFileLength(fname);
  567. if(len > 0)
  568. {
  569. if(len > 1500)
  570. len = 1500; // restrict length to prevent crash in wxLogMessage()
  571. msg = (char *)malloc(len+1);
  572. if(msg != NULL)
  573. {
  574. f = fopen(fname,"r");
  575. len = fread(msg,1, len, f);
  576. fclose(f);
  577. msg[len] = 0;
  578. msg_string = wxString(msg,wxConvUTF8);
  579. wxLogMessage(msg_string);
  580. free(msg);
  581. }
  582. }
  583. } // end of DisplayErrorFile
  584. void MyFrame::OnTools(wxCommandEvent& event)
  585. {//=========================================
  586. int err;
  587. FILE *log;
  588. int debug_flag=0;
  589. char fname_log[sizeof(path_dsource)+12];
  590. char err_fname[sizeof(path_home)+15];
  591. static const char utf8_bom[] = {0xef,0xbb,0xbf,0};
  592. switch(event.GetId())
  593. {
  594. case MENU_TEST:
  595. TestTest(0);
  596. break;
  597. case MENU_TEST2:
  598. TestTest(2);
  599. break;
  600. case MENU_TO_UTF8:
  601. ConvertToUtf8();
  602. break;
  603. case MENU_COUNT_WORDS:
  604. MakeWordFreqList();
  605. break;
  606. case MENU_LEXICON_RU:
  607. case MENU_LEXICON_BG:
  608. case MENU_LEXICON_DE:
  609. case MENU_LEXICON_IT:
  610. case MENU_LEXICON_TEST:
  611. CompareLexicon(event.GetId()); // Compare a lexicon with _rules translation
  612. break;
  613. case MENU_COMPILE_PH:
  614. CompilePhonemeData();
  615. SetVoiceTitle(voice_name2);
  616. break;
  617. case MENU_COMPILE_PH2:
  618. CompileSampleRate();
  619. SetVoiceTitle(voice_name2);
  620. break;
  621. case MENU_COMPILE_MBROLA:
  622. CompileMbrola();
  623. break;
  624. case MENU_COMPILE_INTONATION:
  625. CompileIntonation();
  626. break;
  627. case MENU_COMPILE_DICT_DEBUG:
  628. debug_flag =1; // and drop through to next case
  629. case MENU_COMPILE_DICT:
  630. sprintf(fname_log,"%s%s",path_dsource,"dict_log");
  631. log = fopen(fname_log,"w");
  632. if(log != NULL)
  633. {
  634. fprintf(log, "%s", utf8_bom);
  635. }
  636. LoadDictionary(translator, translator->dictionary_name, 0);
  637. if((err = CompileDictionary(path_dsource,translator->dictionary_name,log,err_fname,debug_flag)) < 0)
  638. {
  639. wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal));
  640. wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource);
  641. if(!dir.IsEmpty())
  642. {
  643. path_dictsource = dir;
  644. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
  645. strcat(path_dsource,"/");
  646. }
  647. break;
  648. }
  649. wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err);
  650. if(log != NULL)
  651. {
  652. fclose(log);
  653. if(err > 0)
  654. {
  655. // display the error messages
  656. DisplayErrorFile(fname_log);
  657. }
  658. }
  659. break;
  660. case MENU_FORMAT_DICTIONARY:
  661. DictionaryFormat(dictionary_name);
  662. break;
  663. case MENU_SORT_DICTIONARY:
  664. DictionarySort(dictionary_name);
  665. break;
  666. case MENU_VOWELCHART1:
  667. MakeVowelLists();
  668. break;
  669. case MENU_VOWELCHART2:
  670. VowelChart(2,NULL);
  671. break;
  672. case MENU_VOWELCHART3:
  673. VowelChart(3,NULL);
  674. break;
  675. case MENU_LOAD_WAV:
  676. // LoadWavFile();
  677. break;
  678. }
  679. }
  680. void MyFrame::OnSpeak(wxCommandEvent& event)
  681. {//=========================================
  682. switch(event.GetId())
  683. {
  684. case MENU_SPEAK_TRANSLATE:
  685. case MENU_SPEAK_RULES:
  686. case MENU_SPEAK_IPA:
  687. case MENU_SPEAK_TEXT:
  688. transldlg->OnCommand(event);
  689. break;
  690. case MENU_SPEAK_FILE:
  691. out_ptr = NULL;
  692. transldlg->SpeakFile();
  693. break;
  694. case MENU_SPEAK_STOP:
  695. SpeakNextClause(NULL,NULL,2);
  696. break;
  697. case MENU_SPEAK_PAUSE:
  698. out_ptr = NULL;
  699. SpeakNextClause(NULL,NULL,3);
  700. if(SynthStatus() & 2)
  701. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Resume"));
  702. else
  703. {
  704. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Pause"));
  705. }
  706. break;
  707. case MENU_SPEAK_VOICE:
  708. transldlg->ReadVoice(0);
  709. SetVoiceTitle(voice_name2);
  710. break;
  711. case MENU_SPEAK_VOICE_VARIANT:
  712. transldlg->ReadVoice(1);
  713. SetVoiceTitle(voice_name2);
  714. break;
  715. }
  716. }