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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 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_spectload;
  35. wxString path_spectload2;
  36. wxString path_pitches;
  37. wxString path_wave;
  38. wxString path_speech;
  39. wxString path_phfile;
  40. wxString path_phsource;
  41. wxString path_dictsource;
  42. wxString path_speaktext;
  43. wxString path_modifiervoice;
  44. wxString path_dir1;
  45. int option_speed=160;
  46. char path_dsource[sizeof(path_home)+20];
  47. char voice_name2[40];
  48. BEGIN_EVENT_TABLE(Options, wxDialog)
  49. EVT_BUTTON(wxID_SAVE,Options::OnCommand)
  50. EVT_BUTTON(wxID_CLOSE,Options::OnCommand)
  51. END_EVENT_TABLE()
  52. Options::Options(wxWindow *parent) : wxDialog(parent,-1,_T("Options"),wxDefaultPosition,wxDefaultSize)
  53. {//===================================================================================================
  54. m_lab[0] = new wxStaticText(this,-1,_T("Sample rate"),wxPoint(72,84));
  55. m_samplerate = new wxTextCtrl(this,-1,_T(""),wxPoint(8,80),wxSize(60,24));
  56. SetNumeric(m_samplerate,samplerate);
  57. m_save = new wxButton(this,wxID_SAVE,_T("Save"),wxPoint(8,120));
  58. m_close = new wxButton(this,wxID_CLOSE,_T("Cancel"),wxPoint(98,120));
  59. Show();
  60. }
  61. Options::~Options()
  62. {//================
  63. int ix;
  64. for(ix=0; ix < 1; ix++)
  65. delete m_lab[ix];
  66. delete m_samplerate;
  67. delete m_save;
  68. delete m_close;
  69. }
  70. void Options::OnCommand(wxCommandEvent& event)
  71. {//===========================================
  72. int id;
  73. int value;
  74. switch(id = event.GetId())
  75. {
  76. case wxID_SAVE:
  77. value = GetNumeric(m_samplerate);
  78. if(value > 0) WavegenInit(value,0);
  79. Destroy();
  80. break;
  81. case wxID_CLOSE:
  82. Destroy();
  83. break;
  84. }
  85. }
  86. void ConfigSetPaths()
  87. {//==================
  88. // set c_string paths from wxStrings
  89. strncpy0(path_source,path_phsource.mb_str(wxConvLocal),sizeof(path_source)-1);
  90. strcat(path_source,"/");
  91. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_source)-1);
  92. strcat(path_dsource,"/");
  93. }
  94. void ConfigInit()
  95. {//==============
  96. long value;
  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. pConfig->Read(_T("/samplerate"),&value,22050);
  133. #ifdef PLATFORM_WINDOWS
  134. value = 22050;
  135. #endif
  136. WavegenInit(value,0);
  137. basedir = wxString(path_base,wxConvLocal); // this is only used to set defaults for other paths if they are not in the config file
  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. ConfigSetPaths();
  153. } // end of ConfigInit
  154. void ConfigSave(int exit)
  155. {//======================
  156. wxFileConfig *pConfig = (wxFileConfig *)(wxConfigBase::Get());
  157. #ifndef PLATFORM_WINDOWS
  158. pConfig->Write(_T("/samplerate"),samplerate);
  159. #endif
  160. pConfig->Write(_T("/spectload"),path_spectload);
  161. pConfig->Write(_T("/spectload2"),path_spectload2);
  162. pConfig->Write(_T("/pitchpath"),path_pitches);
  163. pConfig->Write(_T("/wavepath"),path_wave);
  164. pConfig->Write(_T("/speechpath"),path_speech);
  165. pConfig->Write(_T("/voicename"),wxString(voice_name2,wxConvLocal));
  166. pConfig->Write(_T("/phsource"),path_phsource);
  167. pConfig->Write(_T("/phfile"),path_phfile);
  168. pConfig->Write(_T("/dictsource"),path_dictsource);
  169. pConfig->Write(_T("/speaktext"),path_speaktext);
  170. pConfig->Write(_T("/speed"),option_speed);
  171. pConfig->Write(_T("/modifiervoice"),path_modifiervoice);
  172. pConfig->Write(_T("/dir1"),path_dir1);
  173. if(exit)
  174. delete wxFileConfig::Set((wxFileConfig *)NULL);
  175. }