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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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/notebook.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. #ifdef deleted
  42. static const char *about_string = "espeakedit: %s\nAuthor: Jonathan Duddington (c) 2009\n\n"
  43. "Licensed under GNU General Public License version 3\n"
  44. "http://espeak.sourceforge.net/";
  45. #endif
  46. static const char *about_string = "<font size=0><b>espeakedit </b> %s<br>Author: Jonathan Duddington (c) 2009<br>"
  47. "<a href=\"http://espeak.sourceforge.net/\">http://espeak.sourceforge.net</a><br>"
  48. "Licensed under <a href=\"http://espeak.sourceforge.net/license.html\">GNU General Public License version 3</a></font>";
  49. const char *path_data;
  50. extern void TestTest(int control);
  51. extern void CompareLexicon(int);
  52. extern void ConvertToUtf8();
  53. extern void DictionaryFormat(const char *dictname);
  54. extern void DictionarySort(const char *dictname);
  55. extern void init_z();
  56. extern void CompilePhonemeData(void);
  57. extern void CompileMbrola();
  58. extern void CompileIntonation();
  59. extern void InitSpectrumDisplay();
  60. extern void InitProsodyDisplay();
  61. extern void InitWaveDisplay();
  62. extern void VowelChart(int control, char *fname);
  63. extern void MakeVowelLists(void);
  64. extern void MakeWordFreqList();
  65. extern const char *dict_name;
  66. extern wxMenu *speak_menu;
  67. extern wxMenu *data_menu;
  68. MyFrame *myframe = NULL;
  69. SpectDisplay *currentcanvas = NULL;
  70. ChildFrProsody *prosodyframe = NULL;
  71. ProsodyDisplay *prosodycanvas = NULL;
  72. wxNotebook *notebook = NULL;
  73. wxProgressDialog *progress;
  74. int progress_max;
  75. int gui_flag = 0;
  76. int frame_x, frame_y, frame_w, frame_h;
  77. wxList my_children;
  78. wxFont FONT_SMALL(8,wxSWISS,wxNORMAL,wxNORMAL);
  79. wxFont FONT_MEDIUM(9,wxSWISS,wxNORMAL,wxNORMAL);
  80. wxFont FONT_NORMAL(10,wxSWISS,wxNORMAL,wxNORMAL);
  81. IMPLEMENT_APP(MyApp)
  82. wxString AppName = _T("espeakedit");
  83. int MyApp::OnExit()
  84. {//================
  85. ConfigSave(1);
  86. return(0);
  87. }
  88. static const char *help_text =
  89. "\n\nespeakedit\n"
  90. "\tRun with GUI\n"
  91. "espeakedit --compile\n"
  92. "\tCompile phoneme data in espeak-data/phsource\n"
  93. "\tand dictionary data in espeak-data/dictsource\n";
  94. // Initialise this in OnInit, not statically
  95. bool MyApp::OnInit(void)
  96. {//=====================
  97. int j;
  98. wxChar *p;
  99. char param[80];
  100. if(argc > 1)
  101. {
  102. p = argv[1];
  103. j = 0;
  104. while((param[j] = p[j]) != 0) j++;
  105. if((strcmp(param,"--help")==0) || (strcmp(param,"-h")==0))
  106. {
  107. printf(about_string,espeak_Info(NULL));
  108. printf(help_text);
  109. exit(0);
  110. }
  111. ConfigInit();
  112. VoiceReset(0);
  113. WavegenSetVoice(voice);
  114. WavegenInitSound();
  115. if(strcmp(param,"--compile")==0)
  116. {
  117. CompilePhonemeData();
  118. CompileIntonation();
  119. exit(0);
  120. }
  121. }
  122. ConfigInit();
  123. gui_flag = 1;
  124. // It seems that the wctype functions don't work until the locale has been set
  125. // to something other than the default "C". Then, not only Latin1 but also the
  126. // other characters give the correct results with iswalpha() etc.
  127. if(setlocale(LC_CTYPE,"en_US.UTF-8") == NULL)
  128. {
  129. if(setlocale(LC_CTYPE,"UTF-8") == NULL)
  130. setlocale(LC_CTYPE,"");
  131. }
  132. if((frame_w == 0) || (frame_h == 0))
  133. {
  134. frame_w = 1024;
  135. frame_h = 768;
  136. }
  137. // Create the main frame window
  138. myframe = new MyFrame(NULL, -1, AppName, wxPoint(frame_x, frame_y), wxSize(frame_w, frame_h),
  139. wxDEFAULT_FRAME_STYLE |
  140. wxNO_FULL_REPAINT_ON_RESIZE |
  141. wxHSCROLL | wxVSCROLL);
  142. // Make a menubar
  143. myframe->SetMenuBar(MakeMenu(0, voice_name2));
  144. myframe->CreateStatusBar();
  145. myframe->SetVoiceTitle(voice_name2);
  146. // myframe->Maximize();
  147. myframe->Show(TRUE);
  148. SetTopWindow(myframe);
  149. wxInitAllImageHandlers();
  150. // wxImage::AddHandler(wxPNGHandler);
  151. return TRUE;
  152. }
  153. BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
  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_PATH0, MyFrame::OnOptions)
  164. EVT_MENU(MENU_PATH1, MyFrame::OnOptions)
  165. EVT_MENU(MENU_PATH2, MyFrame::OnOptions)
  166. EVT_MENU(MENU_PATH3, MyFrame::OnOptions)
  167. EVT_MENU(MENU_PATH4, MyFrame::OnOptions)
  168. EVT_MENU(MENU_COMPILE_PH, MyFrame::OnTools)
  169. EVT_MENU(MENU_COMPILE_DICT, MyFrame::OnTools)
  170. EVT_MENU(MENU_COMPILE_DICT_DEBUG, MyFrame::OnTools)
  171. EVT_MENU(MENU_FORMAT_DICTIONARY, MyFrame::OnTools)
  172. EVT_MENU(MENU_SORT_DICTIONARY, MyFrame::OnTools)
  173. EVT_MENU(MENU_COMPILE_MBROLA, MyFrame::OnTools)
  174. EVT_MENU(MENU_COMPILE_INTONATION, MyFrame::OnTools)
  175. EVT_MENU(MENU_CLOSE_ALL, MyFrame::OnQuit)
  176. EVT_MENU(MENU_QUIT, MyFrame::OnQuit)
  177. EVT_MENU(MENU_SPEAK_TRANSLATE, MyFrame::OnSpeak)
  178. EVT_MENU(MENU_SPEAK_RULES, MyFrame::OnSpeak)
  179. EVT_MENU(MENU_SPEAK_IPA, MyFrame::OnSpeak)
  180. EVT_MENU(MENU_SPEAK_TEXT, MyFrame::OnSpeak)
  181. EVT_MENU(MENU_SPEAK_FILE, MyFrame::OnSpeak)
  182. EVT_MENU(MENU_SPEAK_STOP, MyFrame::OnSpeak)
  183. EVT_MENU(MENU_SPEAK_PAUSE, MyFrame::OnSpeak)
  184. EVT_MENU(MENU_SPEAK_VOICE, MyFrame::OnSpeak)
  185. EVT_MENU(MENU_SPEAK_VOICE_VARIANT, MyFrame::OnSpeak)
  186. EVT_MENU(MENU_LOAD_WAV, MyFrame::OnTools)
  187. EVT_MENU(MENU_VOWELCHART1, MyFrame::OnTools)
  188. EVT_MENU(MENU_VOWELCHART2, MyFrame::OnTools)
  189. EVT_MENU(MENU_VOWELCHART3, MyFrame::OnTools)
  190. EVT_MENU(MENU_LEXICON_RU, MyFrame::OnTools)
  191. EVT_MENU(MENU_LEXICON_BG, MyFrame::OnTools)
  192. EVT_MENU(MENU_LEXICON_DE, MyFrame::OnTools)
  193. EVT_MENU(MENU_LEXICON_IT, MyFrame::OnTools)
  194. EVT_MENU(MENU_LEXICON_TEST, MyFrame::OnTools)
  195. EVT_MENU(MENU_TO_UTF8, MyFrame::OnTools)
  196. EVT_MENU(MENU_COUNT_WORDS, MyFrame::OnTools)
  197. EVT_MENU(MENU_TEST, MyFrame::OnTools)
  198. EVT_MENU(MENU_TEST2, MyFrame::OnTools)
  199. EVT_TIMER(1, MyFrame::OnTimer)
  200. EVT_SIZE(MyFrame::OnSize)
  201. EVT_SASH_DRAGGED(ID_WINDOW_LEFT, MyFrame::OnSashDrag)
  202. END_EVENT_TABLE()
  203. MyFrame::~MyFrame(void)
  204. {//====================
  205. myframe->Show(false);
  206. myframe->Iconize(false); // os=Windows, get the non-iconsized size
  207. myframe->GetPosition(&frame_x, &frame_y);
  208. myframe->GetSize(&frame_w, &frame_h);
  209. }
  210. MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
  211. const long style):
  212. wxMDIParentFrame(parent, id, title, pos, size, style)
  213. {//===================================================================================================================
  214. // Main Frame constructor
  215. int error_flag = 0;
  216. int result;
  217. int param;
  218. // Another window to the left of the client window
  219. m_leftWindow = new wxSashLayoutWindow(this, ID_WINDOW_LEFT,
  220. wxDefaultPosition, wxSize(298, 30),
  221. wxNO_BORDER | wxSW_3D | wxCLIP_CHILDREN);
  222. m_leftWindow->SetDefaultSize(wxSize(310, 1000));
  223. m_leftWindow->SetOrientation(wxLAYOUT_VERTICAL);
  224. m_leftWindow->SetAlignment(wxLAYOUT_LEFT);
  225. m_leftWindow->SetSashVisible(wxSASH_RIGHT, TRUE);
  226. notebook = new wxNotebook(m_leftWindow,-1);
  227. // notebook->AddPage(voicedlg,_T("Voice"),FALSE);
  228. formantdlg = new FormantDlg(notebook);
  229. notebook->AddPage(formantdlg,_T(" Spect"),FALSE);
  230. voicedlg = new VoiceDlg(notebook);
  231. transldlg = new TranslDlg(notebook);
  232. notebook->AddPage(transldlg,_T("Text"),TRUE);
  233. LoadConfig();
  234. WavegenInitSound();
  235. if((result = LoadPhData()) != 1)
  236. {
  237. if(result == -1)
  238. wxLogError(_T("Failed to read espeak-data/phontab,phondata,phonindex\nPath = ")+wxString(path_home,wxConvLocal)+_T("\n\nThe 'eSpeak' package needs to be installed"));
  239. else
  240. wxLogError(_T("Wrong version of espeak-data at:\n")+ wxString(path_home,wxConvLocal)+_T("\nVersion 0x%x (expects 0x%x)"),result,version_phdata);
  241. error_flag = 1;
  242. }
  243. f_trans = stdout;
  244. option_ssml = 1;
  245. option_phoneme_input = 1;
  246. // if(LoadVoice(voice_name,0) == NULL)
  247. if(SetVoiceByName(voice_name2) != EE_OK)
  248. {
  249. if(error_flag==0)
  250. wxLogError(_T("Failed to load voice data"));
  251. strcpy(dictionary_name,"en");
  252. }
  253. WavegenSetVoice(voice);
  254. for(param=0; param<N_SPEECH_PARAM; param++)
  255. param_stack[0].parameter[param] = param_defaults[param];
  256. SetParameter(espeakRATE,option_speed,0);
  257. SetSpeed(3);
  258. SynthesizeInit();
  259. InitSpectrumDisplay();
  260. InitProsodyDisplay();
  261. // InitWaveDisplay();
  262. espeak_ListVoices(NULL);
  263. m_timer.SetOwner(this,1);
  264. m_timer.Start(500); /* 0.5 timer */
  265. } // end of MyFrame::MyFrame
  266. void MyFrame::SetVoiceTitle(char *voice_name)
  267. {//==========================================
  268. char buf[100];
  269. SetTitle(AppName + _T(" - ") + wxString(voice_name,wxConvLocal) + _T(" voice"));
  270. if((data_menu != NULL) && (translator != NULL))
  271. {
  272. sprintf(buf,"Compile &dictionary '%s'",translator->dictionary_name);
  273. data_menu->SetLabel(MENU_COMPILE_DICT, wxString(buf,wxConvLocal));
  274. sprintf(buf,"&Layout '%s_rules' file",translator->dictionary_name);
  275. data_menu->SetLabel(MENU_FORMAT_DICTIONARY, wxString(buf,wxConvLocal));
  276. sprintf(buf,"&Sort '%s_rules' file",translator->dictionary_name);
  277. data_menu->SetLabel(MENU_SORT_DICTIONARY, wxString(buf,wxConvLocal));
  278. }
  279. }
  280. void MyFrame::OnKey(wxKeyEvent& event)
  281. {
  282. int key;
  283. key = event.GetKeyCode();
  284. if((currentcanvas != NULL) && (currentcanvas != FindFocus()))
  285. {
  286. if((key == WXK_F1) || (key == WXK_F2))
  287. {
  288. currentcanvas->OnKey(event);
  289. currentcanvas->SetFocus();
  290. return;
  291. }
  292. }
  293. event.Skip();
  294. }
  295. void MyFrame::OnTimer(wxTimerEvent &event)
  296. //****************************************
  297. {
  298. SynthOnTimer();
  299. }
  300. void MyFrame::OnQuit(wxCommandEvent& event)
  301. {
  302. switch(event.GetId())
  303. {
  304. case MENU_QUIT:
  305. Close(TRUE);
  306. break;
  307. case MENU_CLOSE_ALL:
  308. break;
  309. }
  310. }
  311. class HtmlWindow: public wxHtmlWindow
  312. {
  313. public:
  314. HtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style);
  315. void OnLinkClicked(const wxHtmlLinkInfo& link);
  316. };
  317. HtmlWindow::HtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
  318. wxHtmlWindow(parent, id, pos, size, style)
  319. {
  320. }
  321. void HtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
  322. {
  323. if(wxLaunchDefaultBrowser(link.GetHref()) == FALSE)
  324. wxLogStatus(_T("Failed to launch default browser: "+link.GetHref()));
  325. }
  326. void MyFrame::OnAbout(wxCommandEvent& event)
  327. {//=========================================
  328. int result;
  329. char buf[300];
  330. wxString url_docs;
  331. wxBoxSizer *topsizer;
  332. HtmlWindow *html;
  333. wxDialog dlg(this, wxID_ANY, wxString(_("About")));
  334. topsizer = new wxBoxSizer(wxVERTICAL);
  335. switch(event.GetId())
  336. {
  337. case MENU_ABOUT:
  338. {
  339. sprintf(buf,about_string,espeak_Info(NULL));
  340. html = new HtmlWindow(&dlg, wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
  341. html -> SetBorders(0);
  342. html -> SetPage(wxString(buf,wxConvLocal));
  343. html -> SetSize(html -> GetInternalRepresentation() -> GetWidth(),
  344. html -> GetInternalRepresentation() -> GetHeight());
  345. topsizer -> Add(html, 1, wxALL, 10);
  346. //#if wxUSE_STATLINE
  347. // topsizer -> Add(new wxStaticLine(&dlg, wxID_ANY), 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
  348. //#endif // wxUSE_STATLINE
  349. wxButton *bu1 = new wxButton(&dlg, wxID_OK, _("OK"));
  350. bu1 -> SetDefault();
  351. topsizer -> Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
  352. dlg.SetSizer(topsizer);
  353. topsizer -> Fit(&dlg);
  354. dlg.ShowModal();
  355. }
  356. break;
  357. case MENU_DOCS:
  358. strcpy(buf,"/docs/docindex.html");
  359. url_docs = wxGetCwd() + wxString(buf,wxConvLocal); // look for "docs" in the current directory
  360. if(!wxFileExists(url_docs))
  361. {
  362. strcpy(buf,"http://espeak.sourceforge.net/docindex.html");
  363. url_docs = wxString(buf,wxConvLocal);
  364. }
  365. else
  366. {
  367. url_docs = _T("file://") + url_docs;
  368. }
  369. result = wxLaunchDefaultBrowser(url_docs);
  370. if(result == 0)
  371. wxLogStatus(_T("Failed to launch default browser: "+url_docs));
  372. break;
  373. }
  374. }
  375. void OnOptions2(int event_id)
  376. {//==========================
  377. wxString string;
  378. int value;
  379. switch(event_id)
  380. {
  381. case MENU_OPT_SPEED:
  382. value = wxGetNumberFromUser(_T(""),_T(""),_T("Speed"),option_speed,80,500);
  383. if(value > 0)
  384. {
  385. option_speed = value;
  386. SetParameter(espeakRATE,option_speed,0);
  387. SetSpeed(3);
  388. }
  389. break;
  390. case MENU_OPT_PUNCT:
  391. transldlg->t_source->SetValue(_T("<tts:style field=\"punctuation\" mode=\"all\">\n"));
  392. transldlg->t_source->SetInsertionPointEnd();
  393. notebook->SetSelection(1);
  394. break;
  395. case MENU_OPT_SPELL:
  396. transldlg->t_source->SetValue(_T("<say-as interpret-as=\"tts:char\">\n"));
  397. transldlg->t_source->SetInsertionPointEnd();
  398. notebook->SetSelection(1);
  399. break;
  400. case MENU_PATH0:
  401. string = wxFileSelector(_T("Master phonemes file"),wxFileName(path_phfile).GetPath(),
  402. _T(""),_T(""),_T("*"),wxOPEN);
  403. if(!string.IsEmpty())
  404. {
  405. path_phfile = string;
  406. }
  407. break;
  408. case MENU_PATH1:
  409. string = wxDirSelector(_T("Phoneme source directory"),path_phsource);
  410. if(!string.IsEmpty())
  411. {
  412. path_phsource = string;
  413. }
  414. break;
  415. case MENU_PATH2:
  416. string = wxDirSelector(_T("Dictionary source directory"),path_dictsource);
  417. if(!string.IsEmpty())
  418. {
  419. path_dictsource = string;
  420. }
  421. break;
  422. case MENU_PATH3:
  423. string = wxFileSelector(_T("Sound output file"),wxFileName(path_speech).GetPath(),
  424. _T(""),_T("WAV"),_T("*"),wxSAVE);
  425. if(!string.IsEmpty())
  426. {
  427. path_speech = string;
  428. }
  429. break;
  430. case MENU_PATH4:
  431. string = wxFileSelector(_T("Voice file to modify formant peaks"),wxFileName(path_speech).GetPath(),
  432. _T(""),_T(""),_T("*"),wxOPEN);
  433. if(!string.IsEmpty())
  434. {
  435. path_modifiervoice = string;
  436. }
  437. break;
  438. }
  439. ConfigSetPaths();
  440. }
  441. void MyFrame::OnOptions(wxCommandEvent& event)
  442. {//===========================================
  443. OnOptions2(event.GetId());
  444. }
  445. void DisplayErrorFile(const char *fname)
  446. {//=====================================
  447. int len;
  448. FILE *f;
  449. char *msg;
  450. wxString msg_string;
  451. len = GetFileLength(fname);
  452. if(len > 0)
  453. {
  454. if(len > 1500)
  455. len = 1500; // restrict length to pppppevent crash in wxLogMessage()
  456. msg = (char *)malloc(len+1);
  457. if(msg != NULL)
  458. {
  459. f = fopen(fname,"r");
  460. len = fread(msg,1, len, f);
  461. fclose(f);
  462. msg[len] = 0;
  463. msg_string = wxString(msg,wxConvUTF8);
  464. wxLogMessage(msg_string);
  465. free(msg);
  466. }
  467. }
  468. } // end of DisplayErrorFile
  469. void MyFrame::OnTools(wxCommandEvent& event)
  470. {//=========================================
  471. int err;
  472. FILE *log;
  473. int debug_flag=0;
  474. char fname_log[sizeof(path_dsource)+12];
  475. char err_fname[sizeof(path_home)+15];
  476. switch(event.GetId())
  477. {
  478. case MENU_TEST:
  479. TestTest(0);
  480. break;
  481. case MENU_TEST2:
  482. TestTest(2);
  483. break;
  484. case MENU_TO_UTF8:
  485. ConvertToUtf8();
  486. break;
  487. case MENU_COUNT_WORDS:
  488. MakeWordFreqList();
  489. break;
  490. case MENU_LEXICON_RU:
  491. case MENU_LEXICON_BG:
  492. case MENU_LEXICON_DE:
  493. case MENU_LEXICON_IT:
  494. case MENU_LEXICON_TEST:
  495. CompareLexicon(event.GetId()); // Compare a lexicon with _rules translation
  496. break;
  497. case MENU_COMPILE_PH:
  498. CompilePhonemeData();
  499. break;
  500. case MENU_COMPILE_MBROLA:
  501. CompileMbrola();
  502. break;
  503. case MENU_COMPILE_INTONATION:
  504. CompileIntonation();
  505. break;
  506. case MENU_COMPILE_DICT_DEBUG:
  507. debug_flag =1; // and drop through to next case
  508. case MENU_COMPILE_DICT:
  509. sprintf(fname_log,"%s%s",path_dsource,"dict_log");
  510. log = fopen(fname_log,"w");
  511. LoadDictionary(translator, translator->dictionary_name, 0);
  512. if((err = CompileDictionary(path_dsource,translator->dictionary_name,log,err_fname,debug_flag)) < 0)
  513. {
  514. wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal));
  515. wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource);
  516. if(!dir.IsEmpty())
  517. {
  518. path_dictsource = dir;
  519. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
  520. strcat(path_dsource,"/");
  521. }
  522. break;
  523. }
  524. wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err);
  525. if(log != NULL)
  526. {
  527. fclose(log);
  528. if(err > 0)
  529. {
  530. // display the error messages
  531. DisplayErrorFile(fname_log);
  532. }
  533. }
  534. break;
  535. case MENU_FORMAT_DICTIONARY:
  536. DictionaryFormat(dictionary_name);
  537. break;
  538. case MENU_SORT_DICTIONARY:
  539. DictionarySort(dictionary_name);
  540. break;
  541. case MENU_VOWELCHART1:
  542. MakeVowelLists();
  543. break;
  544. case MENU_VOWELCHART2:
  545. VowelChart(2,NULL);
  546. break;
  547. case MENU_VOWELCHART3:
  548. VowelChart(3,NULL);
  549. break;
  550. case MENU_LOAD_WAV:
  551. // LoadWavFile();
  552. break;
  553. }
  554. }
  555. void MyFrame::OnSpeak(wxCommandEvent& event)
  556. {//=========================================
  557. switch(event.GetId())
  558. {
  559. case MENU_SPEAK_TRANSLATE:
  560. case MENU_SPEAK_RULES:
  561. case MENU_SPEAK_IPA:
  562. case MENU_SPEAK_TEXT:
  563. transldlg->OnCommand(event);
  564. break;
  565. case MENU_SPEAK_FILE:
  566. out_ptr = NULL;
  567. transldlg->SpeakFile();
  568. break;
  569. case MENU_SPEAK_STOP:
  570. SpeakNextClause(NULL,NULL,2);
  571. break;
  572. case MENU_SPEAK_PAUSE:
  573. out_ptr = NULL;
  574. SpeakNextClause(NULL,NULL,3);
  575. if(SynthStatus() & 2)
  576. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Resume"));
  577. else
  578. {
  579. speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Pause"));
  580. }
  581. break;
  582. case MENU_SPEAK_VOICE:
  583. transldlg->ReadVoice(0);
  584. SetVoiceTitle(voice_name2);
  585. break;
  586. case MENU_SPEAK_VOICE_VARIANT:
  587. transldlg->ReadVoice(1);
  588. SetVoiceTitle(voice_name2);
  589. break;
  590. }
  591. }
  592. void MyFrame::OnSashDrag(wxSashEvent& event)
  593. {
  594. int w, h;
  595. if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
  596. return;
  597. GetClientSize(&w, &h);
  598. switch (event.GetId())
  599. {
  600. case ID_WINDOW_LEFT:
  601. {
  602. m_leftWindow->SetDefaultSize(wxSize(event.GetDragRect().width, h));
  603. break;
  604. }
  605. }
  606. wxLayoutAlgorithm layout;
  607. layout.LayoutMDIFrame(this);
  608. // Leaves bits of itself behind sometimes
  609. GetClientWindow()->Refresh();
  610. }
  611. void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event))
  612. {
  613. wxLayoutAlgorithm layout;
  614. layout.LayoutMDIFrame(this);
  615. }
  616. // Note that SASHTEST_NEW_WINDOW and SASHTEST_ABOUT commands get passed
  617. // to the parent window for processing, so no need to
  618. // duplicate event handlers here.
  619. BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
  620. EVT_MENU(SPECTSEQ_CLOSE, MyChild::OnQuit)
  621. EVT_MENU(SPECTSEQ_SAVE, MyChild::OnSave)
  622. EVT_MENU(SPECTSEQ_SAVEAS, MyChild::OnSaveAs)
  623. EVT_MENU(SPECTSEQ_SAVESELECT, MyChild::OnSaveSelect)
  624. EVT_MENU(SPECTSEQ_SAVEPITCH, MyChild::OnSavePitchenv)
  625. EVT_ACTIVATE(MyChild::OnActivate)
  626. END_EVENT_TABLE()
  627. MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size,
  628. const long style):
  629. wxMDIChildFrame(parent, -1, title, pos, size, style)
  630. {
  631. canvas = NULL;
  632. my_children.Append(this);
  633. }
  634. MyChild::~MyChild(void)
  635. {
  636. canvas = NULL;
  637. #ifndef PLATFORM_WINDOWS
  638. wxWindow *w;
  639. // bug in wxMDIChildFrame, we need to explicitly remove the ChildFrame from the ClientWindow
  640. w = myframe->GetClientWindow();
  641. w->RemoveChild(this);
  642. #endif
  643. my_children.DeleteObject(this);
  644. }
  645. //extern void CloseCanvas();
  646. void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
  647. {
  648. Destroy();
  649. }
  650. void MyChild::OnSave(wxCommandEvent& WXUNUSED(event))
  651. {
  652. canvas->Save(canvas->savepath);
  653. }
  654. void MyChild::OnSaveAs(wxCommandEvent& WXUNUSED(event))
  655. {
  656. canvas->Save();
  657. }
  658. void MyChild::OnSaveSelect(wxCommandEvent& WXUNUSED(event))
  659. {
  660. canvas->Save(_T(""),1);
  661. }
  662. void MyChild::OnSavePitchenv(wxCommandEvent& WXUNUSED(event))
  663. {
  664. canvas->SavePitchenv(canvas->spectseq->pitchenv);
  665. }
  666. void MyChild::OnActivate(wxActivateEvent& event)
  667. {
  668. if(canvas)
  669. canvas->OnActivate(event.GetActive());
  670. }