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 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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. IMPLEMENT_APP(MyApp)
  76. wxString AppName = _T("espeakedit");
  77. int MyApp::OnExit()
  78. {//================
  79. ConfigSave(1);
  80. return(0);
  81. }
  82. static const char *help_text =
  83. "\n\nespeakedit\n"
  84. "\tRun with GUI\n"
  85. "espeakedit --compile\n"
  86. "\tCompile phoneme data in espeak-data/phsource\n"
  87. "\tand dictionary data in espeak-data/dictsource\n";
  88. // Initialise this in OnInit, not statically
  89. bool MyApp::OnInit(void)
  90. {//=====================
  91. int j;
  92. wxChar *p;
  93. char param[120];
  94. if(argc > 1)
  95. {
  96. p = argv[1];
  97. j = 0;
  98. while((param[j] = p[j]) != 0) j++;
  99. if((strcmp(param,"--help")==0) || (strcmp(param,"-h")==0))
  100. {
  101. printf(about_string2,espeak_Info(NULL));
  102. printf("%s", help_text);
  103. exit(0);
  104. }
  105. ConfigInit();
  106. if(strcmp(param,"--compile")==0)
  107. {
  108. LoadPhData(NULL);
  109. samplerate_native = samplerate = 22050;
  110. CompilePhonemeData();
  111. CompileIntonation();
  112. }
  113. exit(0);
  114. }
  115. ConfigInit();
  116. gui_flag = 1;
  117. // It seems that the wctype functions don't work until the locale has been set
  118. // to something other than the default "C". Then, not only Latin1 but also the
  119. // other characters give the correct results with iswalpha() etc.
  120. if(setlocale(LC_CTYPE,"en_US.UTF-8") == NULL)
  121. {
  122. if(setlocale(LC_CTYPE,"UTF-8") == NULL)
  123. setlocale(LC_CTYPE,"");
  124. }
  125. if((frame_w == 0) || (frame_h == 0))
  126. {
  127. frame_w = 800;
  128. frame_h = 768;
  129. }
  130. // Create the main frame window
  131. myframe = new MyFrame(NULL, -1, AppName, wxPoint(frame_x, frame_y), wxSize(frame_w, frame_h),
  132. wxDEFAULT_FRAME_STYLE |
  133. wxNO_FULL_REPAINT_ON_RESIZE |
  134. wxHSCROLL | wxVSCROLL);
  135. // Make a menubar
  136. myframe->SetMenuBar(MakeMenu(0, voice_name2));
  137. myframe->CreateStatusBar();
  138. myframe->SetVoiceTitle(voice_name2);
  139. // myframe->Maximize();
  140. myframe->Show(TRUE);
  141. SetTopWindow(myframe);
  142. wxInitAllImageHandlers();
  143. // wxImage::AddHandler(wxPNGHandler);
  144. wxLogStatus(_T("Using espeak_data at: ")+wxString(path_home, wxConvLocal));
  145. return TRUE;
  146. }
  147. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  148. EVT_CHAR(MyFrame::OnKey)
  149. EVT_MENU(MENU_ABOUT, MyFrame::OnAbout)
  150. EVT_MENU(MENU_DOCS, MyFrame::OnAbout)
  151. EVT_MENU(MENU_SPECTRUM, MyFrame::OnNewWindow)
  152. EVT_MENU(MENU_SPECTRUM2, MyFrame::OnNewWindow)
  153. EVT_MENU(MENU_PROSODY, MyFrame::OnProsody)
  154. EVT_MENU(MENU_OPT_SPEED, MyFrame::OnOptions)
  155. EVT_MENU(MENU_OPT_PUNCT, MyFrame::OnOptions)
  156. EVT_MENU(MENU_OPT_SPELL, MyFrame::OnOptions)
  157. EVT_MENU(MENU_OPT_SPELL2, MyFrame::OnOptions)
  158. EVT_MENU(MENU_PATH_DATA, 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. screenpages->SetPageText(screenpages->GetSelection(), currentcanvas->spectseq->name+_T(" ²"));
  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_PATH_DATA:
  515. string = wxDirSelector(_T("espeak_data directory"), wxEmptyString);
  516. if(!string.IsEmpty())
  517. {
  518. if(!wxDirExists(string+_T("/voices")))
  519. {
  520. wxLogError(_T("No 'voices' directory in ") + string);
  521. break;
  522. }
  523. path_espeakdata = string;
  524. wxLogMessage(_T("Quit and restart espeakedit to use the new espeak_data location"));
  525. }
  526. break;
  527. case MENU_PATH0:
  528. string = wxFileSelector(_T("Master phonemes file"),wxFileName(path_phfile).GetPath(),
  529. _T("phonemes"),_T(""),_T("*"),wxOPEN);
  530. if(!string.IsEmpty())
  531. {
  532. path_phfile = string;
  533. }
  534. break;
  535. case MENU_PATH1:
  536. string = wxDirSelector(_T("Phoneme source directory"),path_phsource);
  537. if(!string.IsEmpty())
  538. {
  539. path_phsource = string;
  540. }
  541. break;
  542. case MENU_PATH2:
  543. string = wxDirSelector(_T("Dictionary source directory"),path_dictsource);
  544. if(!string.IsEmpty())
  545. {
  546. path_dictsource = string;
  547. }
  548. break;
  549. case MENU_PATH3:
  550. string = wxFileSelector(_T("Sound output file"),wxFileName(path_speech).GetPath(),
  551. _T(""),_T("WAV"),_T("*"),wxSAVE);
  552. if(!string.IsEmpty())
  553. {
  554. path_speech = string;
  555. }
  556. break;
  557. case MENU_PATH4:
  558. string = wxFileSelector(_T("Voice file to modify formant peaks"),wxFileName(path_speech).GetPath(),
  559. _T(""),_T(""),_T("*"),wxOPEN);
  560. if(!string.IsEmpty())
  561. {
  562. path_modifiervoice = string;
  563. }
  564. break;
  565. }
  566. ConfigSetPaths();
  567. }
  568. void MyFrame::OnOptions(wxCommandEvent& event)
  569. {//===========================================
  570. OnOptions2(event.GetId());
  571. }
  572. void DisplayErrorFile(const char *fname)
  573. {//=====================================
  574. int len;
  575. FILE *f;
  576. char *msg;
  577. wxString msg_string;
  578. len = GetFileLength(fname);
  579. if(len > 0)
  580. {
  581. if(len > 1500)
  582. len = 1500; // restrict length to prevent crash in wxLogMessage()
  583. msg = (char *)malloc(len+1);
  584. if(msg != NULL)
  585. {
  586. f = fopen(fname,"r");
  587. len = fread(msg,1, len, f);
  588. fclose(f);
  589. msg[len] = 0;
  590. msg_string = wxString(msg,wxConvUTF8);
  591. wxLogMessage(msg_string);
  592. free(msg);
  593. }
  594. }
  595. } // end of DisplayErrorFile
  596. void MyFrame::OnTools(wxCommandEvent& event)
  597. {//=========================================
  598. int err;
  599. FILE *log;
  600. int debug_flag=0;
  601. char fname_log[sizeof(path_dsource)+12];
  602. char err_fname[sizeof(path_home)+15];
  603. static const char utf8_bom[] = {0xef,0xbb,0xbf,0};
  604. switch(event.GetId())
  605. {
  606. case MENU_TEST:
  607. TestTest(0);
  608. break;
  609. case MENU_TEST2:
  610. TestTest(2);
  611. break;
  612. case MENU_TO_UTF8:
  613. ConvertToUtf8();
  614. break;
  615. case MENU_COUNT_WORDS:
  616. MakeWordFreqList();
  617. break;
  618. case MENU_LEXICON_RU:
  619. case MENU_LEXICON_BG:
  620. case MENU_LEXICON_DE:
  621. case MENU_LEXICON_IT:
  622. case MENU_LEXICON_TEST:
  623. CompareLexicon(event.GetId()); // Compare a lexicon with _rules translation
  624. break;
  625. case MENU_COMPILE_PH:
  626. CompilePhonemeData();
  627. SetVoiceTitle(voice_name2);
  628. break;
  629. case MENU_COMPILE_PH2:
  630. CompileSampleRate();
  631. SetVoiceTitle(voice_name2);
  632. break;
  633. case MENU_COMPILE_MBROLA:
  634. CompileMbrola();
  635. break;
  636. case MENU_COMPILE_INTONATION:
  637. CompileIntonation();
  638. break;
  639. case MENU_COMPILE_DICT_DEBUG:
  640. debug_flag =1; // and drop through to next case
  641. case MENU_COMPILE_DICT:
  642. sprintf(fname_log,"%s%s",path_dsource,"dict_log");
  643. log = fopen(fname_log,"w");
  644. if(log != NULL)
  645. {
  646. fprintf(log, "%s", utf8_bom);
  647. }
  648. LoadDictionary(translator, translator->dictionary_name, 0);
  649. if((err = CompileDictionary(path_dsource,translator->dictionary_name,log,err_fname,debug_flag)) < 0)
  650. {
  651. wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal));
  652. wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource);
  653. if(!dir.IsEmpty())
  654. {
  655. path_dictsource = dir;
  656. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
  657. strcat(path_dsource,"/");
  658. }
  659. break;
  660. }
  661. wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err);
  662. if(log != NULL)
  663. {
  664. fclose(log);
  665. if(err > 0)
  666. {
  667. // display the error messages
  668. DisplayErrorFile(fname_log);
  669. }
  670. }
  671. break;
  672. case MENU_FORMAT_DICTIONARY:
  673. DictionaryFormat(dictionary_name);
  674. break;
  675. case MENU_SORT_DICTIONARY:
  676. DictionarySort(dictionary_name);
  677. break;
  678. case MENU_VOWELCHART1:
  679. MakeVowelLists();
  680. break;
  681. case MENU_VOWELCHART2:
  682. VowelChart(2,NULL);
  683. break;
  684. case MENU_VOWELCHART3:
  685. VowelChart(3,NULL);
  686. break;
  687. case MENU_LOAD_WAV:
  688. // LoadWavFile();
  689. break;
  690. }
  691. }
  692. void MyFrame::OnSpeak(wxCommandEvent& event)
  693. {//=========================================
  694. switch(event.GetId())
  695. {
  696. case MENU_SPEAK_TRANSLATE:
  697. case MENU_SPEAK_RULES:
  698. case MENU_SPEAK_IPA:
  699. case MENU_SPEAK_TEXT:
  700. transldlg->OnCommand(event);
  701. break;
  702. case MENU_SPEAK_FILE:
  703. out_ptr = NULL;
  704. transldlg->SpeakFile();
  705. break;
  706. case MENU_SPEAK_STOP:
  707. SpeakNextClause(NULL,NULL,2);
  708. break;
  709. case MENU_SPEAK_PAUSE:
  710. out_ptr = NULL;
  711. SpeakNextClause(NULL,NULL,3);
  712. if(SynthStatus() & 2)
  713. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Resume"));
  714. else
  715. {
  716. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Pause"));
  717. }
  718. break;
  719. case MENU_SPEAK_VOICE:
  720. transldlg->ReadVoice(0);
  721. SetVoiceTitle(voice_name2);
  722. break;
  723. case MENU_SPEAK_VOICE_VARIANT:
  724. transldlg->ReadVoice(1);
  725. SetVoiceTitle(voice_name2);
  726. break;
  727. }
  728. }