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

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