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.

options.cpp 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2013 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "wx/wx.h"
  20. #include "wx/fileconf.h"
  21. #include "wx/filename.h"
  22. #include <sys/stat.h>
  23. #include "speech.h"
  24. #ifdef PLATFORM_WINDOWS
  25. #include "wx/msw/registry.h"
  26. #endif
  27. #include "main.h"
  28. #include "options.h"
  29. extern void WavegenInit(int samplerate, int wavemult_fact);
  30. extern void strncpy0(char *to,const char *from, int size);
  31. extern int GetNumeric(wxTextCtrl *t);
  32. extern void SetNumeric(wxTextCtrl *t, int value);
  33. extern int samplerate;
  34. wxString path_espeakdata;
  35. wxString path_spectload;
  36. wxString path_spectload2;
  37. wxString path_pitches;
  38. wxString path_wave;
  39. wxString path_speech;
  40. wxString path_phfile;
  41. wxString path_phsource;
  42. wxString path_dictsource;
  43. wxString path_speaktext;
  44. wxString path_modifiervoice;
  45. wxString path_dir1;
  46. int option_speed=160;
  47. char path_dsource[sizeof(path_home)+20];
  48. char voice_name2[40];
  49. BEGIN_EVENT_TABLE(Options, wxDialog)
  50. EVT_BUTTON(wxID_SAVE,Options::OnCommand)
  51. EVT_BUTTON(wxID_CLOSE,Options::OnCommand)
  52. END_EVENT_TABLE()
  53. Options::Options(wxWindow *parent) : wxDialog(parent,-1,_T("Options"),wxDefaultPosition,wxDefaultSize)
  54. {//===================================================================================================
  55. m_lab[0] = new wxStaticText(this,-1,_T("Sample rate"),wxPoint(72,84));
  56. m_samplerate = new wxTextCtrl(this,-1,_T(""),wxPoint(8,80),wxSize(60,24));
  57. SetNumeric(m_samplerate,samplerate);
  58. m_save = new wxButton(this,wxID_SAVE,_T("Save"),wxPoint(8,120));
  59. m_close = new wxButton(this,wxID_CLOSE,_T("Cancel"),wxPoint(98,120));
  60. Show();
  61. }
  62. Options::~Options()
  63. {//================
  64. int ix;
  65. for(ix=0; ix < 1; ix++)
  66. delete m_lab[ix];
  67. delete m_samplerate;
  68. delete m_save;
  69. delete m_close;
  70. }
  71. void Options::OnCommand(wxCommandEvent& event)
  72. {//===========================================
  73. int id;
  74. int value;
  75. switch(id = event.GetId())
  76. {
  77. case wxID_SAVE:
  78. value = GetNumeric(m_samplerate);
  79. if(value > 0) WavegenInit(value,0);
  80. Destroy();
  81. break;
  82. case wxID_CLOSE:
  83. Destroy();
  84. break;
  85. }
  86. }
  87. void ConfigSetPaths()
  88. {//==================
  89. // set c_string paths from wxStrings
  90. strncpy0(path_source,path_phsource.mb_str(wxConvLocal),sizeof(path_source)-1);
  91. strcat(path_source,"/");
  92. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_source)-1);
  93. strcat(path_dsource,"/");
  94. }
  95. void ConfigInit()
  96. {//==============
  97. wxString string;
  98. wxString basedir;
  99. const char *path_base;
  100. #ifdef PLATFORM_WINDOWS
  101. int found = 0;
  102. char buf[200];
  103. wxRegKey *pRegKey = new wxRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak"));
  104. if((path_base = getenv("ESPEAK_DATA_PATH")) != NULL)
  105. {
  106. sprintf(path_home,"%s\\espeak-data",path_base);
  107. if(GetFileLength(path_home) == -2)
  108. found = 1; // an espeak-data directory exists
  109. }
  110. if(found == 0)
  111. {
  112. if(pRegKey->Exists() )
  113. {
  114. wxString RegVal;
  115. pRegKey->QueryValue(_T("Path"),RegVal);
  116. strncpy0(buf,RegVal.mb_str(wxConvLocal),sizeof(buf));
  117. path_base = buf;
  118. }
  119. else
  120. {
  121. path_base = "C:\\Program Files\\eSpeak";
  122. }
  123. sprintf(path_home,"%s\\espeak-data",path_base);
  124. }
  125. #else
  126. snprintf(path_home,sizeof(path_home),"%s/espeak-data",getenv("HOME"));
  127. path_base = path_home;
  128. #endif
  129. mkdir(path_home,S_IRWXU); // create if it doesn't already exist
  130. wxFileConfig *pConfig = new wxFileConfig(_T("espeakedit"));
  131. wxFileConfig::Set(pConfig);
  132. basedir = wxString(path_base,wxConvLocal); // this is only used to set defaults for other paths if they are not in the config file
  133. pConfig->Read(_T("/espeakdata"),&path_espeakdata,wxEmptyString);
  134. if(path_espeakdata != wxEmptyString)
  135. {
  136. strcpy(path_home, path_espeakdata.mb_str(wxConvLocal));
  137. }
  138. pConfig->Read(_T("/spectload"),&path_spectload,basedir+_T("/phsource"));
  139. pConfig->Read(_T("/spectload2"),&path_spectload2,basedir+_T("/phsource"));
  140. pConfig->Read(_T("/pitchpath"),&path_pitches,basedir+_T("/pitch"));
  141. pConfig->Read(_T("/wavepath"),&path_wave,wxEmptyString);
  142. pConfig->Read(_T("/speechpath"),&path_speech,wxEmptyString);
  143. pConfig->Read(_T("/voicename"),&string,wxEmptyString);
  144. strcpy(voice_name2,string.mb_str(wxConvLocal));
  145. pConfig->Read(_T("/phsource"),&path_phsource,basedir+_T("/phsource"));
  146. pConfig->Read(_T("/phfile"),&path_phfile,path_phsource+_T("/phonemes"));
  147. pConfig->Read(_T("/dictsource"),&path_dictsource,basedir+_T("/dictsource"));
  148. pConfig->Read(_T("/speaktext"),&path_speaktext,wxEmptyString);
  149. pConfig->Read(_T("/modifiervoice"),&path_modifiervoice,basedir);
  150. pConfig->Read(_T("/dir1"),&path_dir1,basedir);
  151. option_speed = pConfig->Read(_T("/speed"),160);
  152. frame_x = pConfig->Read(_T("/windowx"), 0l);
  153. frame_y = pConfig->Read(_T("/windowy"), 0l);
  154. frame_h = pConfig->Read(_T("/windowh"), 0l);
  155. frame_w = pConfig->Read(_T("/windoww"), 0l);
  156. ConfigSetPaths();
  157. } // end of ConfigInit
  158. void ConfigSave(int exit)
  159. {//======================
  160. wxFileConfig *pConfig = (wxFileConfig *)(wxConfigBase::Get());
  161. #ifndef PLATFORM_WINDOWS
  162. // pConfig->Write(_T("/samplerate"),samplerate);
  163. #endif
  164. pConfig->Write(_T("/espeakdata"),path_espeakdata);
  165. pConfig->Write(_T("/spectload"),path_spectload);
  166. pConfig->Write(_T("/spectload2"),path_spectload2);
  167. pConfig->Write(_T("/pitchpath"),path_pitches);
  168. pConfig->Write(_T("/wavepath"),path_wave);
  169. pConfig->Write(_T("/speechpath"),path_speech);
  170. pConfig->Write(_T("/voicename"),wxString(voice_name2,wxConvLocal));
  171. pConfig->Write(_T("/phsource"),path_phsource);
  172. pConfig->Write(_T("/phfile"),path_phfile);
  173. pConfig->Write(_T("/dictsource"),path_dictsource);
  174. pConfig->Write(_T("/speaktext"),path_speaktext);
  175. pConfig->Write(_T("/speed"),option_speed);
  176. pConfig->Write(_T("/modifiervoice"),path_modifiervoice);
  177. pConfig->Write(_T("/dir1"),path_dir1);
  178. pConfig->Write(_T("/windowx"),frame_x);
  179. pConfig->Write(_T("/windowy"),frame_y);
  180. pConfig->Write(_T("/windoww"),frame_w);
  181. pConfig->Write(_T("/windowh"),frame_h);
  182. if(exit)
  183. delete wxFileConfig::Set((wxFileConfig *)NULL);
  184. }