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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_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(bool use_defaults)
  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. char *env;
  127. if((env = getenv("ESPEAK_DATA_PATH")) == NULL)
  128. env = getenv("HOME");
  129. snprintf(path_home,sizeof(path_home),"%s/espeak-data",env);
  130. path_base = path_home;
  131. #endif
  132. mkdir(path_home,S_IRWXU); // create if it doesn't already exist
  133. wxFileConfig *pConfig = new wxFileConfig(_T("espeakedit"));
  134. wxFileConfig::Set(pConfig);
  135. basedir = wxString(path_base,wxConvLocal); // this is only used to set defaults for other paths if they are not in the config file
  136. if (use_defaults)
  137. {
  138. path_spectload = basedir + _T("/phsource");
  139. path_spectload2 = basedir + _T("/phsource");
  140. path_pitches = basedir + _T("/pitch");
  141. path_phsource = basedir + _T("/phsource");
  142. path_phfile = path_phsource + _T("/phonemes");
  143. path_dictsource = basedir + _T("/dictsource");
  144. path_modifiervoice = basedir;
  145. path_dir1 = basedir;
  146. }
  147. else
  148. {
  149. pConfig->Read(_T("/spectload"),&path_spectload,basedir+_T("/phsource"));
  150. pConfig->Read(_T("/spectload2"),&path_spectload2,basedir+_T("/phsource"));
  151. pConfig->Read(_T("/pitchpath"),&path_pitches,basedir+_T("/pitch"));
  152. pConfig->Read(_T("/wavepath"),&path_wave,wxEmptyString);
  153. pConfig->Read(_T("/speechpath"),&path_speech,wxEmptyString);
  154. pConfig->Read(_T("/voicename"),&string,wxEmptyString);
  155. strcpy(voice_name2,string.mb_str(wxConvLocal));
  156. pConfig->Read(_T("/phsource"),&path_phsource,basedir+_T("/phsource"));
  157. pConfig->Read(_T("/phfile"),&path_phfile,path_phsource+_T("/phonemes"));
  158. pConfig->Read(_T("/dictsource"),&path_dictsource,basedir+_T("/dictsource"));
  159. pConfig->Read(_T("/speaktext"),&path_speaktext,wxEmptyString);
  160. pConfig->Read(_T("/modifiervoice"),&path_modifiervoice,basedir);
  161. pConfig->Read(_T("/dir1"),&path_dir1,basedir);
  162. option_speed = pConfig->Read(_T("/speed"),160);
  163. frame_x = pConfig->Read(_T("/windowx"), 0l);
  164. frame_y = pConfig->Read(_T("/windowy"), 0l);
  165. frame_h = pConfig->Read(_T("/windowh"), 0l);
  166. frame_w = pConfig->Read(_T("/windoww"), 0l);
  167. }
  168. ConfigSetPaths();
  169. } // end of ConfigInit
  170. void ConfigSave(int exit)
  171. {//======================
  172. wxFileConfig *pConfig = (wxFileConfig *)(wxConfigBase::Get());
  173. #ifndef PLATFORM_WINDOWS
  174. // pConfig->Write(_T("/samplerate"),samplerate);
  175. #endif
  176. pConfig->Write(_T("/spectload"),path_spectload);
  177. pConfig->Write(_T("/spectload2"),path_spectload2);
  178. pConfig->Write(_T("/pitchpath"),path_pitches);
  179. pConfig->Write(_T("/wavepath"),path_wave);
  180. pConfig->Write(_T("/speechpath"),path_speech);
  181. pConfig->Write(_T("/voicename"),wxString(voice_name2,wxConvLocal));
  182. pConfig->Write(_T("/phsource"),path_phsource);
  183. pConfig->Write(_T("/phfile"),path_phfile);
  184. pConfig->Write(_T("/dictsource"),path_dictsource);
  185. pConfig->Write(_T("/speaktext"),path_speaktext);
  186. pConfig->Write(_T("/speed"),option_speed);
  187. pConfig->Write(_T("/modifiervoice"),path_modifiervoice);
  188. pConfig->Write(_T("/dir1"),path_dir1);
  189. pConfig->Write(_T("/windowx"),frame_x);
  190. pConfig->Write(_T("/windowy"),frame_y);
  191. pConfig->Write(_T("/windoww"),frame_w);
  192. pConfig->Write(_T("/windowh"),frame_h);
  193. if(exit)
  194. delete wxFileConfig::Set((wxFileConfig *)NULL);
  195. }