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

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