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

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