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

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