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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2010 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. #ifdef deleted
  41. static const char *about_string = "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. #endif
  45. static const char *about_string = "<font size=0><b>espeakedit </b> %s<br>Author: Jonathan Duddington (c) 2009<br>"
  46. "<a href=\"http://espeak.sourceforge.net/\">http://espeak.sourceforge.net</a><br>"
  47. "Licensed under <a href=\"http://espeak.sourceforge.net/license.html\">GNU General Public License version 3</a></font>";
  48. const char *path_data;
  49. extern void TestTest(int control);
  50. extern void CompareLexicon(int);
  51. extern void ConvertToUtf8();
  52. extern void DictionaryFormat(const char *dictname);
  53. extern void DictionarySort(const char *dictname);
  54. extern void init_z();
  55. extern void CompilePhonemeData(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_string,espeak_Info(NULL));
  106. printf(help_text);
  107. exit(0);
  108. }
  109. ConfigInit();
  110. VoiceReset(0);
  111. WavegenSetVoice(voice);
  112. WavegenInitSound();
  113. if(strcmp(param,"--compile")==0)
  114. {
  115. CompilePhonemeData();
  116. CompileIntonation();
  117. exit(0);
  118. }
  119. }
  120. ConfigInit();
  121. gui_flag = 1;
  122. // It seems that the wctype functions don't work until the locale has been set
  123. // to something other than the default "C". Then, not only Latin1 but also the
  124. // other characters give the correct results with iswalpha() etc.
  125. if(setlocale(LC_CTYPE,"en_US.UTF-8") == NULL)
  126. {
  127. if(setlocale(LC_CTYPE,"UTF-8") == NULL)
  128. setlocale(LC_CTYPE,"");
  129. }
  130. if((frame_w == 0) || (frame_h == 0))
  131. {
  132. frame_w = 800;
  133. frame_h = 768;
  134. }
  135. // Create the main frame window
  136. myframe = new MyFrame(NULL, -1, AppName, wxPoint(frame_x, frame_y), wxSize(frame_w, frame_h),
  137. wxDEFAULT_FRAME_STYLE |
  138. wxNO_FULL_REPAINT_ON_RESIZE |
  139. wxHSCROLL | wxVSCROLL);
  140. // Make a menubar
  141. myframe->SetMenuBar(MakeMenu(0, voice_name2));
  142. myframe->CreateStatusBar();
  143. myframe->SetVoiceTitle(voice_name2);
  144. // myframe->Maximize();
  145. myframe->Show(TRUE);
  146. SetTopWindow(myframe);
  147. wxInitAllImageHandlers();
  148. // wxImage::AddHandler(wxPNGHandler);
  149. return TRUE;
  150. }
  151. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  152. EVT_CHAR(MyFrame::OnKey)
  153. EVT_MENU(MENU_ABOUT, MyFrame::OnAbout)
  154. EVT_MENU(MENU_DOCS, MyFrame::OnAbout)
  155. EVT_MENU(MENU_SPECTRUM, MyFrame::OnNewWindow)
  156. EVT_MENU(MENU_SPECTRUM2, MyFrame::OnNewWindow)
  157. EVT_MENU(MENU_PROSODY, MyFrame::OnProsody)
  158. EVT_MENU(MENU_OPT_SPEED, MyFrame::OnOptions)
  159. EVT_MENU(MENU_OPT_PUNCT, MyFrame::OnOptions)
  160. EVT_MENU(MENU_OPT_SPELL, 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_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. 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. WavegenInitSound();
  247. if((result = LoadPhData()) != 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. }
  255. f_trans = stdout;
  256. option_ssml = 1;
  257. option_phoneme_input = 1;
  258. // if(LoadVoice(voice_name,0) == NULL)
  259. if(SetVoiceByName(voice_name2) != EE_OK)
  260. {
  261. if(error_flag==0)
  262. wxLogError(_T("Failed to load voice data"));
  263. strcpy(dictionary_name,"en");
  264. }
  265. WavegenSetVoice(voice);
  266. for(param=0; param<N_SPEECH_PARAM; param++)
  267. param_stack[0].parameter[param] = param_defaults[param];
  268. SetParameter(espeakRATE,option_speed,0);
  269. SetSpeed(3);
  270. SynthesizeInit();
  271. InitSpectrumDisplay();
  272. InitProsodyDisplay();
  273. // InitWaveDisplay();
  274. espeak_ListVoices(NULL);
  275. m_timer.SetOwner(this,1);
  276. m_timer.Start(500); /* 0.5 timer */
  277. } // end of MyFrame::MyFrame
  278. void MyFrame::SetVoiceTitle(char *voice_name)
  279. {//==========================================
  280. char buf[100];
  281. SetTitle(AppName + _T(" - ") + wxString(voice_name,wxConvLocal) + _T(" voice"));
  282. if((data_menu != NULL) && (translator != NULL))
  283. {
  284. sprintf(buf,"Compile &dictionary '%s'",translator->dictionary_name);
  285. data_menu->SetLabel(MENU_COMPILE_DICT, wxString(buf,wxConvLocal));
  286. sprintf(buf,"&Layout '%s_rules' file",translator->dictionary_name);
  287. data_menu->SetLabel(MENU_FORMAT_DICTIONARY, wxString(buf,wxConvLocal));
  288. sprintf(buf,"&Sort '%s_rules' file",translator->dictionary_name);
  289. data_menu->SetLabel(MENU_SORT_DICTIONARY, wxString(buf,wxConvLocal));
  290. }
  291. }
  292. void MyFrame::PageCmd(wxCommandEvent& event)
  293. {//=========================================
  294. int pagenum;
  295. int ix;
  296. int n_pages;
  297. SpectDisplay *page;
  298. // if(currentcanvas != NULL)
  299. {
  300. pagenum = screenpages->GetSelection();
  301. switch(event.GetId())
  302. {
  303. case SPECTSEQ_SAVE:
  304. currentcanvas->Save(currentcanvas->savepath);
  305. break;
  306. case SPECTSEQ_SAVEAS:
  307. currentcanvas->Save();
  308. break;
  309. case SPECTSEQ_SAVESELECT:
  310. currentcanvas->Save(_T(""), 1);
  311. break;
  312. case SPECTSEQ_CLOSE:
  313. if(screenpages->GetPageText(pagenum) != _T("Prosody"))
  314. {
  315. currentcanvas->OnActivate(0);
  316. }
  317. screenpages->DeletePage(pagenum);
  318. if((n_pages = screenpages->GetPageCount()) > 0)
  319. {
  320. if(pagenum >= n_pages)
  321. pagenum--;
  322. page = (SpectDisplay *)screenpages->GetPage(pagenum);
  323. if(screenpages->GetPageText(pagenum) == _T("Prosody"))
  324. {
  325. MakeMenu(3, NULL);
  326. }
  327. else
  328. {
  329. page->OnActivate(1);
  330. MakeMenu(2, NULL);
  331. }
  332. }
  333. else
  334. {
  335. MakeMenu(1, NULL);
  336. }
  337. break;
  338. case MENU_CLOSE_ALL:
  339. n_pages = screenpages->GetPageCount();
  340. for(ix=n_pages-1; ix>=0; ix--)
  341. {
  342. screenpages->DeletePage(ix);
  343. }
  344. currentcanvas = NULL;
  345. MakeMenu(1, NULL);
  346. break;
  347. case SPECTSEQ_SAVEPITCH:
  348. currentcanvas->SavePitchenv(currentcanvas->spectseq->pitchenv);
  349. break;
  350. }
  351. }
  352. }
  353. void MyFrame::OnPageChanged(wxNotebookEvent& event)
  354. {//=================================================
  355. int pagenum;
  356. wxString title;
  357. SpectDisplay *page;
  358. pagenum = event.GetSelection();
  359. if(event.GetId() == ID_SCREENPAGES)
  360. {
  361. title = screenpages->GetPageText(pagenum);
  362. if((title != _T("Prosody")) && (adding_page != 2))
  363. {
  364. page = (SpectDisplay *)screenpages->GetPage(pagenum);
  365. if(page != currentcanvas)
  366. {
  367. if(currentcanvas != NULL)
  368. {
  369. currentcanvas->OnActivate(0);
  370. }
  371. page->OnActivate(1);
  372. }
  373. MakeMenu(2, NULL);
  374. }
  375. else
  376. {
  377. MakeMenu(3, NULL);
  378. }
  379. }
  380. adding_page = 0; // work around for wxNotebook bug (version 2.8.7)
  381. }
  382. void MyFrame::OnKey(wxKeyEvent& event)
  383. {
  384. int key;
  385. key = event.GetKeyCode();
  386. if((currentcanvas != NULL) && (currentcanvas != FindFocus()))
  387. {
  388. if((key == WXK_F1) || (key == WXK_F2))
  389. {
  390. currentcanvas->OnKey(event);
  391. currentcanvas->SetFocus();
  392. return;
  393. }
  394. }
  395. event.Skip();
  396. }
  397. void MyFrame::OnTimer(wxTimerEvent &event)
  398. //****************************************
  399. {
  400. SynthOnTimer();
  401. }
  402. void MyFrame::OnQuit(wxCommandEvent& event)
  403. {
  404. switch(event.GetId())
  405. {
  406. case MENU_QUIT:
  407. Close(TRUE);
  408. break;
  409. case MENU_CLOSE_ALL:
  410. break;
  411. }
  412. }
  413. class HtmlWindow: public wxHtmlWindow
  414. {
  415. public:
  416. HtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style);
  417. void OnLinkClicked(const wxHtmlLinkInfo& link);
  418. };
  419. HtmlWindow::HtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
  420. wxHtmlWindow(parent, id, pos, size, style)
  421. {
  422. }
  423. void HtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
  424. {
  425. if(wxLaunchDefaultBrowser(link.GetHref()) == FALSE)
  426. wxLogStatus(_T("Failed to launch default browser: "+link.GetHref()));
  427. }
  428. void MyFrame::OnAbout(wxCommandEvent& event)
  429. {//=========================================
  430. int result;
  431. char buf[300];
  432. wxString url_docs;
  433. wxBoxSizer *topsizer;
  434. HtmlWindow *html;
  435. wxDialog dlg(this, wxID_ANY, wxString(_("About")));
  436. topsizer = new wxBoxSizer(wxVERTICAL);
  437. switch(event.GetId())
  438. {
  439. case MENU_ABOUT:
  440. {
  441. sprintf(buf,about_string,espeak_Info(NULL));
  442. html = new HtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
  443. html -> SetBorders(0);
  444. html -> SetPage(wxString(buf,wxConvLocal));
  445. html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
  446. html -> GetInternalRepresentation() -> GetHeight());
  447. topsizer -> Add(html, 1, wxALL, 10);
  448. //#if wxUSE_STATLINE
  449. // topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  450. //#endif // wxUSE_STATLINE
  451. wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
  452. bu1 -> SetDefault();
  453. topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
  454. dlg.SetSizer(topsizer);
  455. topsizer -> Fit(&dlg);
  456. dlg.ShowModal();
  457. }
  458. break;
  459. case MENU_DOCS:
  460. strcpy(buf,"/docs/docindex.html");
  461. url_docs = wxGetCwd() + wxString(buf,wxConvLocal); // look for "docs" in the current directory
  462. if(!wxFileExists(url_docs))
  463. {
  464. strcpy(buf,"http://espeak.sourceforge.net/docindex.html");
  465. url_docs = wxString(buf,wxConvLocal);
  466. }
  467. else
  468. {
  469. url_docs = _T("file://") + url_docs;
  470. }
  471. result = wxLaunchDefaultBrowser(url_docs);
  472. if(result == 0)
  473. wxLogStatus(_T("Failed to launch default browser: "+url_docs));
  474. break;
  475. }
  476. }
  477. void OnOptions2(int event_id)
  478. {//==========================
  479. wxString string;
  480. int value;
  481. switch(event_id)
  482. {
  483. case MENU_OPT_SPEED:
  484. value = wxGetNumberFromUser(_T(""),_T(""),_T("Speed"),option_speed,80,500);
  485. if(value > 0)
  486. {
  487. option_speed = value;
  488. SetParameter(espeakRATE,option_speed,0);
  489. SetSpeed(3);
  490. }
  491. break;
  492. case MENU_OPT_PUNCT:
  493. transldlg->t_source->SetValue(_T("<tts:style field=\"punctuation\" mode=\"all\">\n"));
  494. transldlg->t_source->SetInsertionPointEnd();
  495. notebook->SetSelection(1);
  496. break;
  497. case MENU_OPT_SPELL:
  498. transldlg->t_source->SetValue(_T("<say-as interpret-as=\"tts:char\">\n"));
  499. transldlg->t_source->SetInsertionPointEnd();
  500. notebook->SetSelection(1);
  501. break;
  502. case MENU_PATH0:
  503. string = wxFileSelector(_T("Master phonemes file"),wxFileName(path_phfile).GetPath(),
  504. _T(""),_T(""),_T("*"),wxOPEN);
  505. if(!string.IsEmpty())
  506. {
  507. path_phfile = string;
  508. }
  509. break;
  510. case MENU_PATH1:
  511. string = wxDirSelector(_T("Phoneme source directory"),path_phsource);
  512. if(!string.IsEmpty())
  513. {
  514. path_phsource = string;
  515. }
  516. break;
  517. case MENU_PATH2:
  518. string = wxDirSelector(_T("Dictionary source directory"),path_dictsource);
  519. if(!string.IsEmpty())
  520. {
  521. path_dictsource = string;
  522. }
  523. break;
  524. case MENU_PATH3:
  525. string = wxFileSelector(_T("Sound output file"),wxFileName(path_speech).GetPath(),
  526. _T(""),_T("WAV"),_T("*"),wxSAVE);
  527. if(!string.IsEmpty())
  528. {
  529. path_speech = string;
  530. }
  531. break;
  532. case MENU_PATH4:
  533. string = wxFileSelector(_T("Voice file to modify formant peaks"),wxFileName(path_speech).GetPath(),
  534. _T(""),_T(""),_T("*"),wxOPEN);
  535. if(!string.IsEmpty())
  536. {
  537. path_modifiervoice = string;
  538. }
  539. break;
  540. }
  541. ConfigSetPaths();
  542. }
  543. void MyFrame::OnOptions(wxCommandEvent& event)
  544. {//===========================================
  545. OnOptions2(event.GetId());
  546. }
  547. void DisplayErrorFile(const char *fname)
  548. {//=====================================
  549. int len;
  550. FILE *f;
  551. char *msg;
  552. wxString msg_string;
  553. len = GetFileLength(fname);
  554. if(len > 0)
  555. {
  556. if(len > 1500)
  557. len = 1500; // restrict length to pppppevent crash in wxLogMessage()
  558. msg = (char *)malloc(len+1);
  559. if(msg != NULL)
  560. {
  561. f = fopen(fname,"r");
  562. len = fread(msg,1, len, f);
  563. fclose(f);
  564. msg[len] = 0;
  565. msg_string = wxString(msg,wxConvUTF8);
  566. wxLogMessage(msg_string);
  567. free(msg);
  568. }
  569. }
  570. } // end of DisplayErrorFile
  571. void MyFrame::OnTools(wxCommandEvent& event)
  572. {//=========================================
  573. int err;
  574. FILE *log;
  575. int debug_flag=0;
  576. char fname_log[sizeof(path_dsource)+12];
  577. char err_fname[sizeof(path_home)+15];
  578. switch(event.GetId())
  579. {
  580. case MENU_TEST:
  581. TestTest(0);
  582. break;
  583. case MENU_TEST2:
  584. TestTest(2);
  585. break;
  586. case MENU_TO_UTF8:
  587. ConvertToUtf8();
  588. break;
  589. case MENU_COUNT_WORDS:
  590. MakeWordFreqList();
  591. break;
  592. case MENU_LEXICON_RU:
  593. case MENU_LEXICON_BG:
  594. case MENU_LEXICON_DE:
  595. case MENU_LEXICON_IT:
  596. case MENU_LEXICON_TEST:
  597. CompareLexicon(event.GetId()); // Compare a lexicon with _rules translation
  598. break;
  599. case MENU_COMPILE_PH:
  600. CompilePhonemeData();
  601. break;
  602. case MENU_COMPILE_MBROLA:
  603. CompileMbrola();
  604. break;
  605. case MENU_COMPILE_INTONATION:
  606. CompileIntonation();
  607. break;
  608. case MENU_COMPILE_DICT_DEBUG:
  609. debug_flag =1; // and drop through to next case
  610. case MENU_COMPILE_DICT:
  611. sprintf(fname_log,"%s%s",path_dsource,"dict_log");
  612. log = fopen(fname_log,"w");
  613. LoadDictionary(translator, translator->dictionary_name, 0);
  614. if((err = CompileDictionary(path_dsource,translator->dictionary_name,log,err_fname,debug_flag)) < 0)
  615. {
  616. wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal));
  617. wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource);
  618. if(!dir.IsEmpty())
  619. {
  620. path_dictsource = dir;
  621. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
  622. strcat(path_dsource,"/");
  623. }
  624. break;
  625. }
  626. wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err);
  627. if(log != NULL)
  628. {
  629. fclose(log);
  630. if(err > 0)
  631. {
  632. // display the error messages
  633. DisplayErrorFile(fname_log);
  634. }
  635. }
  636. break;
  637. case MENU_FORMAT_DICTIONARY:
  638. DictionaryFormat(dictionary_name);
  639. break;
  640. case MENU_SORT_DICTIONARY:
  641. DictionarySort(dictionary_name);
  642. break;
  643. case MENU_VOWELCHART1:
  644. MakeVowelLists();
  645. break;
  646. case MENU_VOWELCHART2:
  647. VowelChart(2,NULL);
  648. break;
  649. case MENU_VOWELCHART3:
  650. VowelChart(3,NULL);
  651. break;
  652. case MENU_LOAD_WAV:
  653. // LoadWavFile();
  654. break;
  655. }
  656. }
  657. void MyFrame::OnSpeak(wxCommandEvent& event)
  658. {//=========================================
  659. switch(event.GetId())
  660. {
  661. case MENU_SPEAK_TRANSLATE:
  662. case MENU_SPEAK_RULES:
  663. case MENU_SPEAK_IPA:
  664. case MENU_SPEAK_TEXT:
  665. transldlg->OnCommand(event);
  666. break;
  667. case MENU_SPEAK_FILE:
  668. out_ptr = NULL;
  669. transldlg->SpeakFile();
  670. break;
  671. case MENU_SPEAK_STOP:
  672. SpeakNextClause(NULL,NULL,2);
  673. break;
  674. case MENU_SPEAK_PAUSE:
  675. out_ptr = NULL;
  676. SpeakNextClause(NULL,NULL,3);
  677. if(SynthStatus() & 2)
  678. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Resume"));
  679. else
  680. {
  681. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Pause"));
  682. }
  683. break;
  684. case MENU_SPEAK_VOICE:
  685. transldlg->ReadVoice(0);
  686. SetVoiceTitle(voice_name2);
  687. break;
  688. case MENU_SPEAK_VOICE_VARIANT:
  689. transldlg->ReadVoice(1);
  690. SetVoiceTitle(voice_name2);
  691. break;
  692. }
  693. }