Menu

[r222]: / trunk / src / espeakedit.cpp  Maximize  Restore  History

Download this file

672 lines (531 with data), 16.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
/***************************************************************************
* Copyright (C) 2005 to 2007 by Jonathan Duddington *
* email: jonsd@users.sourceforge.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see: *
* <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "wx/wx.h"
#include "wx/wfstream.h"
#include "wx/notebook.h"
#include "wx/image.h"
#include "wx/filename.h"
#include "wx/numdlg.h"
#include "wx/mdi.h"
#include "wx/laywin.h"
#include "wx/sashwin.h"
#include <locale.h>
#include "speak_lib.h"
#include "main.h"
#include "speech.h"
#include "options.h"
#include "phoneme.h"
#include "synthesize.h"
#include "voice.h"
#include "spect.h"
#include "translate.h"
#include "prosodydisplay.h"
static const char *about_string = "espeakedit: %s\nAuthor: Jonathan Duddington (c) 2007\n\n"
"Licensed under GNU General Public License version 3\n"
"http://espeak.sourceforge.net/";
const char *path_data = "/home/jsd1/speechdata/phsource";
extern void TestTest(int control);
extern void CompareLexicon(int);
extern void ConvertToUtf8();
extern void init_z();
extern void CompileInit(void);
extern void CompileMbrola();
extern void InitSpectrumDisplay();
extern void InitProsodyDisplay();
extern void InitWaveDisplay();
extern void VowelChart(int control, char *fname);
extern void MakeVowelLists(void);
extern void MakeWordFreqList();
extern const char *dict_name;
MyFrame *myframe = NULL;
SpectDisplay *currentcanvas = NULL;
ChildFrProsody *prosodyframe = NULL;
ProsodyDisplay *prosodycanvas = NULL;
wxNotebook *notebook = NULL;
wxProgressDialog *progress;
int progress_max;
int gui_flag = 0;
wxList my_children;
wxFont FONT_SMALL(8,wxSWISS,wxNORMAL,wxNORMAL);
wxFont FONT_MEDIUM(9,wxSWISS,wxNORMAL,wxNORMAL);
wxFont FONT_NORMAL(10,wxSWISS,wxNORMAL,wxNORMAL);
IMPLEMENT_APP(MyApp)
wxString AppName = _T("espeakedit");
int MyApp::OnExit()
{//================
ConfigSave(1);
return(0);
}
static const char *help_text =
"\n\nespeakedit\n"
"\tRun with GUI\n"
"espeakedit --compile\n"
"\tCompile phoneme data in espeak-data/phsource\n"
"\tand dictionary data in espeak-data/dictsource\n";
// Initialise this in OnInit, not statically
bool MyApp::OnInit(void)
{//=====================
int j;
wxChar *p;
char param[80];
if(argc > 1)
{
extern void VoiceReset(int control);
p = argv[1];
j = 0;
while((param[j] = p[j]) != 0) j++;
if((strcmp(param,"--help")==0) || (strcmp(param,"-h")==0))
{
printf(about_string,espeak_Info(NULL));
printf(help_text);
exit(0);
}
ConfigInit();
VoiceReset(0);
WavegenSetVoice(voice);
WavegenInitSound();
if(strcmp(param,"--compile")==0)
{
CompileInit();
exit(0);
}
}
gui_flag = 1;
// It seems that the wctype functions don't work until the locale has been set
// to something other than the default "C". Then, not only Latin1 but also the
// other characters give the correct results with iswalpha() etc.
if(setlocale(LC_CTYPE,"en_US.UTF-8") == NULL)
{
if(setlocale(LC_CTYPE,"UTF-8") == NULL)
setlocale(LC_CTYPE,"");
}
// Create the main frame window
myframe = new MyFrame(NULL, -1, AppName, wxPoint(0, 0), wxSize(1024, 768),
wxDEFAULT_FRAME_STYLE |
wxNO_FULL_REPAINT_ON_RESIZE |
wxHSCROLL | wxVSCROLL);
// Make a menubar
myframe->SetMenuBar(MakeMenu(0));
myframe->CreateStatusBar();
myframe->Show(TRUE);
SetTopWindow(myframe);
wxInitAllImageHandlers();
// wxImage::AddHandler(wxPNGHandler);
return TRUE;
}
BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
EVT_CHAR(MyFrame::OnKey)
EVT_MENU(MENU_ABOUT, MyFrame::OnAbout)
EVT_MENU(MENU_SPECTRUM, MyFrame::OnNewWindow)
EVT_MENU(MENU_SPECTRUM2, MyFrame::OnNewWindow)
EVT_MENU(MENU_PROSODY, MyFrame::OnProsody)
EVT_MENU(MENU_PARAMS, MyFrame::OnOptions)
EVT_MENU(MENU_PATH0, MyFrame::OnOptions)
EVT_MENU(MENU_PATH1, MyFrame::OnOptions)
EVT_MENU(MENU_PATH2, MyFrame::OnOptions)
EVT_MENU(MENU_PATH3, MyFrame::OnOptions)
EVT_MENU(MENU_PATH4, MyFrame::OnOptions)
EVT_MENU(MENU_COMPILE_PH, MyFrame::OnTools)
EVT_MENU(MENU_COMPILE_DICT, MyFrame::OnTools)
EVT_MENU(MENU_COMPILE_DICT_DEBUG, MyFrame::OnTools)
EVT_MENU(MENU_COMPILE_MBROLA, MyFrame::OnTools)
EVT_MENU(MENU_CLOSE_ALL, MyFrame::OnQuit)
EVT_MENU(MENU_QUIT, MyFrame::OnQuit)
EVT_MENU(MENU_SPEAK_TRANSLATE, MyFrame::OnSpeak)
EVT_MENU(MENU_SPEAK_RULES, MyFrame::OnSpeak)
EVT_MENU(MENU_SPEAK_TEXT, MyFrame::OnSpeak)
EVT_MENU(MENU_SPEAK_FILE, MyFrame::OnSpeak)
EVT_MENU(MENU_SPEAK_STOP, MyFrame::OnSpeak)
EVT_MENU(MENU_SPEAK_PAUSE, MyFrame::OnSpeak)
EVT_MENU(MENU_SPEAK_VOICE, MyFrame::OnSpeak)
EVT_MENU(MENU_SPEAK_VOICE_VARIANT, MyFrame::OnSpeak)
EVT_MENU(MENU_LOAD_WAV, MyFrame::OnTools)
EVT_MENU(MENU_VOWELCHART1, MyFrame::OnTools)
EVT_MENU(MENU_VOWELCHART2, MyFrame::OnTools)
EVT_MENU(MENU_VOWELCHART3, MyFrame::OnTools)
EVT_MENU(MENU_LEXICON_RU, MyFrame::OnTools)
EVT_MENU(MENU_LEXICON_DE, MyFrame::OnTools)
EVT_MENU(MENU_LEXICON_IT, MyFrame::OnTools)
EVT_MENU(MENU_LEXICON_IT2, MyFrame::OnTools)
EVT_MENU(MENU_TO_UTF8, MyFrame::OnTools)
EVT_MENU(MENU_COUNT_WORDS, MyFrame::OnTools)
EVT_MENU(MENU_TEST, MyFrame::OnTools)
EVT_MENU(MENU_TEST2, MyFrame::OnTools)
EVT_TIMER(1, MyFrame::OnTimer)
EVT_SIZE(MyFrame::OnSize)
EVT_SASH_DRAGGED_RANGE(ID_WINDOW_TOP, ID_WINDOW_BOTTOM, MyFrame::OnSashDrag)
END_EVENT_TABLE()
MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size,
const long style):
wxMDIParentFrame(parent, id, title, pos, size, style)
{//===================================================================================================================
// Main Frame constructor
int error_flag = 0;
int result;
int param;
// Create some dummy layout windows
wxSashLayoutWindow *win;
// Another window to the left of the client window
win = new wxSashLayoutWindow(this, ID_WINDOW_LEFT2,
wxDefaultPosition, wxSize(298, 30),
wxNO_BORDER | wxSW_3D | wxCLIP_CHILDREN);
win->SetDefaultSize(wxSize(310, 1000));
win->SetOrientation(wxLAYOUT_VERTICAL);
win->SetAlignment(wxLAYOUT_LEFT);
// win->SetBackgroundColour(wxColour(0, 255, 255));
win->SetSashVisible(wxSASH_RIGHT, TRUE);
m_leftWindow2 = win;
notebook = new wxNotebook(m_leftWindow2,-1);
// notebook->AddPage(voicedlg,_T("Voice"),FALSE);
formantdlg = new FormantDlg(notebook);
notebook->AddPage(formantdlg,_T(" Spect"),FALSE);
voicedlg = new VoiceDlg(notebook);
transldlg = new TranslDlg(notebook);
notebook->AddPage(transldlg,_T("Text"),TRUE);
ConfigInit();
WavegenInitSound();
if((result = LoadPhData()) != 1)
{
if(result == -1)
wxLogError(_T("Failed to load phoneme data,\nneeds espeak-data/phontab,phondata,phonindex\nPath = ")+wxString(path_home,wxConvLocal));
else
wxLogError(_T("Wrong version of espeak-data: 0x%x (expects 0x%x)"),result,version_phdata);
error_flag = 1;
}
f_trans = stdout;
option_ssml = 1;
option_phoneme_input = 1;
// if(LoadVoice(voice_name,0) == NULL)
if(SetVoiceByName(voice_name2) != EE_OK)
{
if(error_flag==0)
wxLogError(_T("Failed to load voice data"));
strcpy(dictionary_name,"en");
}
else
{
SetVoiceTitle(voice_name2);
}
WavegenSetVoice(voice);
for(param=0; param<N_SPEECH_PARAM; param++)
param_stack[0].parameter[param] = param_defaults[param];
SetParameter(espeakRATE,option_speed,0);
SetSpeed(3);
SynthesizeInit();
InitSpectrumDisplay();
InitProsodyDisplay();
// InitWaveDisplay();
espeak_ListVoices(NULL);
m_timer.SetOwner(this,1);
m_timer.Start(500); /* 0.5 timer */
} // end of MyFrame::MyFrame
void MyFrame::SetVoiceTitle(char *voice_name)
{//==========================================
SetTitle(AppName + _T(" - ") + wxString(voice_name,wxConvLocal) + _T(" voice"));
}
void MyFrame::OnKey(wxKeyEvent& event)
{
int key;
key = event.GetKeyCode();
if((currentcanvas != NULL) && (currentcanvas != FindFocus()))
{
if((key == WXK_F1) || (key == WXK_F2))
{
currentcanvas->OnKey(event);
currentcanvas->SetFocus();
return;
}
}
event.Skip();
}
void MyFrame::OnTimer(wxTimerEvent &event)
//****************************************
{
SynthOnTimer();
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
switch(event.GetId())
{
case MENU_QUIT:
Close(TRUE);
break;
case MENU_CLOSE_ALL:
break;
}
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{//===================================================
char buf[300];
sprintf(buf,about_string,espeak_Info(NULL));
(void)wxMessageBox(wxString(buf,wxConvLocal), _T("About eSpeak Editor"));
}
void OnOptions2(int event_id)
{//==========================
wxString string;
int value;
switch(event_id)
{
case MENU_PARAMS:
value = wxGetNumberFromUser(_T(""),_T(""),_T("Speed"),option_speed,80,390);
if(value > 0)
{
option_speed = value;
SetParameter(espeakRATE,option_speed,0);
SetSpeed(3);
}
break;
case MENU_PATH0:
string = wxFileSelector(_T("Master phonemes file"),wxFileName(path_phfile).GetPath(),
_T(""),_T(""),_T("*"),wxOPEN);
if(!string.IsEmpty())
{
path_phfile = string;
}
break;
case MENU_PATH1:
string = wxDirSelector(_T("Phoneme source directory"),path_phsource);
if(!string.IsEmpty())
{
path_phsource = string;
}
break;
case MENU_PATH2:
string = wxDirSelector(_T("Dictionary source directory"),path_dictsource);
if(!string.IsEmpty())
{
path_dictsource = string;
}
break;
case MENU_PATH3:
string = wxFileSelector(_T("Sound output file"),wxFileName(path_speech).GetPath(),
_T(""),_T("WAV"),_T("*"),wxSAVE);
if(!string.IsEmpty())
{
path_speech = string;
}
break;
case MENU_PATH4:
string = wxFileSelector(_T("Voice file to modify formant peaks"),wxFileName(path_speech).GetPath(),
_T(""),_T(""),_T("*"),wxOPEN);
if(!string.IsEmpty())
{
path_modifiervoice = string;
}
break;
}
ConfigSetPaths();
}
void MyFrame::OnOptions(wxCommandEvent& event)
{//===========================================
OnOptions2(event.GetId());
}
void MyFrame::OnTools(wxCommandEvent& event)
{//=========================================
int err;
FILE *log;
int debug_flag=0;
char fname_log[sizeof(path_dsource)+12];
char err_fname[sizeof(path_home)+15];
switch(event.GetId())
{
case MENU_TEST:
TestTest(0);
break;
case MENU_TEST2:
TestTest(2);
break;
case MENU_TO_UTF8:
ConvertToUtf8();
break;
case MENU_COUNT_WORDS:
MakeWordFreqList();
break;
case MENU_LEXICON_RU:
case MENU_LEXICON_DE:
case MENU_LEXICON_IT:
case MENU_LEXICON_IT2:
CompareLexicon(event.GetId()); // Compare a lexicon with _rules translation
break;
case MENU_COMPILE_PH:
CompileInit();
break;
case MENU_COMPILE_MBROLA:
CompileMbrola();
break;
case MENU_COMPILE_DICT_DEBUG:
debug_flag =1; // and drop through to next case
case MENU_COMPILE_DICT:
sprintf(fname_log,"%s%s",path_dsource,"dict_log");
log = fopen(fname_log,"w");
if((err = CompileDictionary(path_dsource,dictionary_name,log,err_fname,debug_flag)) < 0)
{
wxLogError(_T("Can't access file:\n")+wxString(err_fname,wxConvLocal));
wxString dir = wxDirSelector(_T("Directory containing dictionary files"),path_dictsource);
if(!dir.IsEmpty())
{
path_dictsource = dir;
strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
strcat(path_dsource,"/");
}
break;
}
wxLogStatus(_T("Compiled '")+wxString(dictionary_name,wxConvLocal)+_T("', %d errors"),err);
if(log != NULL)
fclose(log);
break;
case MENU_VOWELCHART1:
MakeVowelLists();
break;
case MENU_VOWELCHART2:
VowelChart(2,NULL);
break;
case MENU_VOWELCHART3:
VowelChart(3,NULL);
break;
case MENU_LOAD_WAV:
// LoadWavFile();
break;
}
}
extern wxMenu *speak_menu;
void MyFrame::OnSpeak(wxCommandEvent& event)
{//=========================================
switch(event.GetId())
{
case MENU_SPEAK_TRANSLATE:
case MENU_SPEAK_RULES:
case MENU_SPEAK_TEXT:
transldlg->OnCommand(event);
break;
case MENU_SPEAK_FILE:
transldlg->SpeakFile();
break;
case MENU_SPEAK_STOP:
SpeakNextClause(NULL,NULL,2);
break;
case MENU_SPEAK_PAUSE:
SpeakNextClause(NULL,NULL,3);
if(SynthStatus() & 2)
speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Resume"));
else
speak_menu->SetLabel(MENU_SPEAK_PAUSE,_T("&Pause"));
break;
case MENU_SPEAK_VOICE:
transldlg->ReadVoice(0);
SetVoiceTitle(voice_name2);
break;
case MENU_SPEAK_VOICE_VARIANT:
transldlg->ReadVoice(1);
SetVoiceTitle(voice_name2);
break;
}
}
void MyFrame::OnSashDrag(wxSashEvent& event)
{
if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE)
return;
switch (event.GetId())
{
case ID_WINDOW_TOP:
{
m_topWindow->SetDefaultSize(wxSize(1000, event.GetDragRect().height));
break;
}
case ID_WINDOW_LEFT1:
{
m_leftWindow1->SetDefaultSize(wxSize(event.GetDragRect().width, 1000));
break;
}
case ID_WINDOW_LEFT2:
{
m_leftWindow2->SetDefaultSize(wxSize(event.GetDragRect().width, 1000));
break;
}
case ID_WINDOW_BOTTOM:
{
m_bottomWindow->SetDefaultSize(wxSize(1000, event.GetDragRect().height));
break;
}
}
wxLayoutAlgorithm layout;
layout.LayoutMDIFrame(this);
// Leaves bits of itself behind sometimes
GetClientWindow()->Refresh();
}
void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event))
{
wxLayoutAlgorithm layout;
layout.LayoutMDIFrame(this);
}
// Note that SASHTEST_NEW_WINDOW and SASHTEST_ABOUT commands get passed
// to the parent window for processing, so no need to
// duplicate event handlers here.
BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
EVT_MENU(SPECTSEQ_CLOSE, MyChild::OnQuit)
EVT_MENU(SPECTSEQ_SAVE, MyChild::OnSave)
EVT_MENU(SPECTSEQ_SAVEAS, MyChild::OnSaveAs)
EVT_MENU(SPECTSEQ_SAVESELECT, MyChild::OnSaveSelect)
EVT_MENU(SPECTSEQ_SAVEPITCH, MyChild::OnSavePitchenv)
EVT_ACTIVATE(MyChild::OnActivate)
END_EVENT_TABLE()
MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, const wxPoint& pos, const wxSize& size,
const long style):
wxMDIChildFrame(parent, -1, title, pos, size, style)
{
canvas = NULL;
my_children.Append(this);
}
MyChild::~MyChild(void)
{
canvas = NULL;
#ifndef PLATFORM_WINDOWS
wxWindow *w;
// bug in wxMDIChildFrame, we need to explicitly remove the ChildFrame from the ClientWindow
w = myframe->GetClientWindow();
w->RemoveChild(this);
#endif
my_children.DeleteObject(this);
}
//extern void CloseCanvas();
void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Destroy();
}
void MyChild::OnSave(wxCommandEvent& WXUNUSED(event))
{
canvas->Save(canvas->savepath);
}
void MyChild::OnSaveAs(wxCommandEvent& WXUNUSED(event))
{
canvas->Save();
}
void MyChild::OnSaveSelect(wxCommandEvent& WXUNUSED(event))
{
canvas->Save(_T(""),1);
}
void MyChild::OnSavePitchenv(wxCommandEvent& WXUNUSED(event))
{
canvas->SavePitchenv(canvas->spectseq->pitchenv);
}
void MyChild::OnActivate(wxActivateEvent& event)
{
if(canvas)
canvas->OnActivate(event.GetActive());
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.