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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2013 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/fileconf.h"
  22. #include "wx/filename.h"
  23. #include <sys/stat.h>
  24. #include "speech.h"
  25. #ifdef PLATFORM_WINDOWS
  26. #include "wx/msw/registry.h"
  27. #endif
  28. #include "main.h"
  29. #include "options.h"
  30. extern void WavegenInit(int samplerate, int wavemult_fact);
  31. extern void strncpy0(char *to,const char *from, int size);
  32. extern int GetNumeric(wxTextCtrl *t);
  33. extern void SetNumeric(wxTextCtrl *t, int value);
  34. extern int samplerate;
  35. wxString path_espeakdata;
  36. wxString path_spectload;
  37. wxString path_spectload2;
  38. wxString path_pitches;
  39. wxString path_wave;
  40. wxString path_speech;
  41. wxString path_phfile;
  42. wxString path_phsource;
  43. wxString path_dictsource;
  44. wxString path_speaktext;
  45. wxString path_modifiervoice;
  46. wxString path_dir1;
  47. int option_speed=160;
  48. char path_dsource[sizeof(path_home)+20];
  49. char voice_name2[40];
  50. BEGIN_EVENT_TABLE(Options, wxDialog)
  51. EVT_BUTTON(wxID_SAVE,Options::OnCommand)
  52. EVT_BUTTON(wxID_CLOSE,Options::OnCommand)
  53. END_EVENT_TABLE()
  54. Options::Options(wxWindow *parent) : wxDialog(parent,-1,_T("Options"),wxDefaultPosition,wxDefaultSize)
  55. {//===================================================================================================
  56. m_lab[0] = new wxStaticText(this,-1,_T("Sample rate"),wxPoint(72,84));
  57. m_samplerate = new wxTextCtrl(this,-1,_T(""),wxPoint(8,80),wxSize(60,24));
  58. SetNumeric(m_samplerate,samplerate);
  59. m_save = new wxButton(this,wxID_SAVE,_T("Save"),wxPoint(8,120));
  60. m_close = new wxButton(this,wxID_CLOSE,_T("Cancel"),wxPoint(98,120));
  61. Show();
  62. }
  63. Options::~Options()
  64. {//================
  65. int ix;
  66. for(ix=0; ix < 1; ix++)
  67. delete m_lab[ix];
  68. delete m_samplerate;
  69. delete m_save;
  70. delete m_close;
  71. }
  72. void Options::OnCommand(wxCommandEvent& event)
  73. {//===========================================
  74. int id;
  75. int value;
  76. switch(id = event.GetId())
  77. {
  78. case wxID_SAVE:
  79. value = GetNumeric(m_samplerate);
  80. if(value > 0) WavegenInit(value,0);
  81. Destroy();
  82. break;
  83. case wxID_CLOSE:
  84. Destroy();
  85. break;
  86. }
  87. }
  88. void ConfigSetPaths()
  89. {//==================
  90. // set c_string paths from wxStrings
  91. strncpy0(path_source,path_phsource.mb_str(wxConvLocal),sizeof(path_source)-1);
  92. strcat(path_source,"/");
  93. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_source)-1);
  94. strcat(path_dsource,"/");
  95. }
  96. void ConfigInit(bool use_defaults)
  97. {//==============
  98. wxString string;
  99. wxString basedir;
  100. const char *path_base;
  101. #ifdef PLATFORM_WINDOWS
  102. int found = 0;
  103. char buf[200];
  104. wxRegKey *pRegKey = new wxRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak"));
  105. if((path_base = getenv("ESPEAK_DATA_PATH")) != NULL)
  106. {
  107. sprintf(path_home,"%s\\espeak-data",path_base);
  108. if(GetFileLength(path_home) == -2)
  109. found = 1; // an espeak-data directory exists
  110. }
  111. if(found == 0)
  112. {
  113. if(pRegKey->Exists() )
  114. {
  115. wxString RegVal;
  116. pRegKey->QueryValue(_T("Path"),RegVal);
  117. strncpy0(buf,RegVal.mb_str(wxConvLocal),sizeof(buf));
  118. path_base = buf;
  119. }
  120. else
  121. {
  122. path_base = "C:\\Program Files\\eSpeak";
  123. }
  124. sprintf(path_home,"%s\\espeak-data",path_base);
  125. }
  126. #else
  127. char *env;
  128. if((env = getenv("ESPEAK_DATA_PATH")) == NULL)
  129. env = getenv("HOME");
  130. snprintf(path_home,sizeof(path_home),"%s/espeak-data",env);
  131. path_base = path_home;
  132. #endif
  133. mkdir(path_home,S_IRWXU); // create if it doesn't already exist
  134. wxFileConfig *pConfig = new wxFileConfig(_T("espeakedit"));
  135. wxFileConfig::Set(pConfig);
  136. basedir = wxString(path_base,wxConvLocal); // this is only used to set defaults for other paths if they are not in the config file
  137. if (use_defaults)
  138. {
  139. path_spectload = basedir + _T("/../phsource");
  140. path_spectload2 = basedir + _T("/../phsource");
  141. path_pitches = basedir + _T("/pitch");
  142. path_phsource = basedir + _T("/../phsource");
  143. path_phfile = path_phsource + _T("/phonemes");
  144. path_dictsource = basedir + _T("/../dictsource");
  145. path_modifiervoice = basedir;
  146. path_dir1 = basedir;
  147. }
  148. else
  149. {
  150. pConfig->Read(_T("/espeakdata"),&path_espeakdata,wxEmptyString);
  151. if(path_espeakdata != wxEmptyString)
  152. {
  153. strcpy(path_home, path_espeakdata.mb_str(wxConvLocal));
  154. }
  155. pConfig->Read(_T("/spectload"),&path_spectload,basedir+_T("/phsource"));
  156. pConfig->Read(_T("/spectload2"),&path_spectload2,basedir+_T("/phsource"));
  157. pConfig->Read(_T("/pitchpath"),&path_pitches,basedir+_T("/pitch"));
  158. pConfig->Read(_T("/wavepath"),&path_wave,wxEmptyString);
  159. pConfig->Read(_T("/speechpath"),&path_speech,wxEmptyString);
  160. pConfig->Read(_T("/voicename"),&string,wxEmptyString);
  161. strcpy(voice_name2,string.mb_str(wxConvLocal));
  162. pConfig->Read(_T("/phsource"),&path_phsource,basedir+_T("/phsource"));
  163. pConfig->Read(_T("/phfile"),&path_phfile,path_phsource+_T("/phonemes"));
  164. pConfig->Read(_T("/dictsource"),&path_dictsource,basedir+_T("/dictsource"));
  165. pConfig->Read(_T("/speaktext"),&path_speaktext,wxEmptyString);
  166. pConfig->Read(_T("/modifiervoice"),&path_modifiervoice,basedir);
  167. pConfig->Read(_T("/dir1"),&path_dir1,basedir);
  168. option_speed = pConfig->Read(_T("/speed"),160);
  169. frame_x = pConfig->Read(_T("/windowx"), 0l);
  170. frame_y = pConfig->Read(_T("/windowy"), 0l);
  171. frame_h = pConfig->Read(_T("/windowh"), 0l);
  172. frame_w = pConfig->Read(_T("/windoww"), 0l);
  173. }
  174. ConfigSetPaths();
  175. } // end of ConfigInit
  176. void ConfigSave(int exit)
  177. {//======================
  178. wxFileConfig *pConfig = (wxFileConfig *)(wxConfigBase::Get());
  179. #ifndef PLATFORM_WINDOWS
  180. // pConfig->Write(_T("/samplerate"),samplerate);
  181. #endif
  182. pConfig->Write(_T("/espeakdata"),path_espeakdata);
  183. pConfig->Write(_T("/spectload"),path_spectload);
  184. pConfig->Write(_T("/spectload2"),path_spectload2);
  185. pConfig->Write(_T("/pitchpath"),path_pitches);
  186. pConfig->Write(_T("/wavepath"),path_wave);
  187. pConfig->Write(_T("/speechpath"),path_speech);
  188. pConfig->Write(_T("/voicename"),wxString(voice_name2,wxConvLocal));
  189. pConfig->Write(_T("/phsource"),path_phsource);
  190. pConfig->Write(_T("/phfile"),path_phfile);
  191. pConfig->Write(_T("/dictsource"),path_dictsource);
  192. pConfig->Write(_T("/speaktext"),path_speaktext);
  193. pConfig->Write(_T("/speed"),option_speed);
  194. pConfig->Write(_T("/modifiervoice"),path_modifiervoice);
  195. pConfig->Write(_T("/dir1"),path_dir1);
  196. pConfig->Write(_T("/windowx"),frame_x);
  197. pConfig->Write(_T("/windowy"),frame_y);
  198. pConfig->Write(_T("/windoww"),frame_w);
  199. pConfig->Write(_T("/windowh"),frame_h);
  200. if(exit)
  201. delete wxFileConfig::Set((wxFileConfig *)NULL);
  202. }