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.

voices.cpp 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. /***************************************************************************
  2. * Copyright (C) 2005 by Jonathan Duddington *
  3. * [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 2 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, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "StdAfx.h"
  21. #include "stdio.h"
  22. #include "ctype.h"
  23. #include "wctype.h"
  24. #include "string.h"
  25. #include "stdlib.h"
  26. #include "speech.h"
  27. #ifdef PLATFORM_WINDOWS
  28. #include "windows.h"
  29. #else
  30. #ifndef PLATFORM_RISCOS
  31. #include "dirent.h"
  32. #endif
  33. #endif
  34. #include "speak_lib.h"
  35. #include "voice.h"
  36. #include "phoneme.h"
  37. #include "synthesize.h"
  38. #include "translate.h"
  39. MNEM_TAB genders [] = {
  40. {"unknown", 0},
  41. {"male", 1},
  42. {"female", 2},
  43. {NULL, 0 }};
  44. //int tone_points[10] = {250,140, 1200,110, -1,0, -1,0, -1,0};
  45. int tone_points[10] = {600,170, 1200,135, 2000,110, 3000,110, -1,0};
  46. // limit the rate of change for each formant number
  47. //static int formant_rate_22050[9] = {50, 104, 165, 230, 220, 220, 220, 220, 220}; // values for 22kHz sample rate
  48. static int formant_rate_22050[9] = {50, 100, 165, 200, 200, 200, 200, 200, 200}; // values for 22kHz sample rate
  49. int formant_rate[9]; // values adjusted for actual sample rate
  50. #define DEFAULT_LANGUAGE_PRIORITY 5
  51. #define N_VOICES_LIST 100
  52. static int n_voices_list = 0;
  53. static espeak_VOICE *voices_list[N_VOICES_LIST];
  54. static int len_path_voices;
  55. espeak_VOICE *voice_selected = NULL;
  56. espeak_VOICE *first_voice = NULL;
  57. char voice_name[40];
  58. #define V_NAME 1
  59. #define V_LANGUAGE 2
  60. #define V_GENDER 3
  61. #define V_TRANSLATOR 4
  62. #define V_PHONEMES 5
  63. #define V_DICTIONARY 6
  64. // these affect voice quality, are independent of language
  65. #define V_FORMANT 7
  66. #define V_PITCH 8
  67. #define V_ECHO 9
  68. #define V_FLUTTER 10
  69. #define V_ROUGHNESS 11
  70. #define V_CLARITY 12
  71. #define V_TONE 13
  72. // these override defaults set by the translator
  73. #define V_WORDGAP 15
  74. #define V_INTONATION 16
  75. #define V_STRESSLENGTH 17
  76. #define V_STRESSAMP 18
  77. #define V_STRESSADD 19
  78. #define V_DICTRULES 20
  79. #define V_STRESSRULE 21
  80. #define V_CHARSET 22
  81. #define V_NUMBERS 23
  82. #define V_OPTION 24
  83. #define V_MBROLA 25
  84. // these need a phoneme table to have been specified
  85. #define V_REPLACE 26
  86. typedef struct {
  87. const char *mnem;
  88. int data;
  89. } keywtab_t;
  90. static keywtab_t keyword_tab[] = {
  91. {"name", V_NAME},
  92. {"language", V_LANGUAGE},
  93. {"gender", V_GENDER},
  94. {"formant", V_FORMANT},
  95. {"pitch", V_PITCH},
  96. {"phonemes", V_PHONEMES},
  97. {"translator", V_TRANSLATOR},
  98. {"dictionary", V_DICTIONARY},
  99. {"stressLength", V_STRESSLENGTH},
  100. {"stressAmp", V_STRESSAMP},
  101. {"stressAdd", V_STRESSADD},
  102. {"intonation", V_INTONATION},
  103. {"dictrules", V_DICTRULES},
  104. {"stressrule", V_STRESSRULE},
  105. {"charset", V_CHARSET},
  106. {"replace", V_REPLACE},
  107. {"words", V_WORDGAP},
  108. {"echo", V_ECHO},
  109. {"flutter", V_FLUTTER},
  110. {"roughness", V_ROUGHNESS},
  111. {"clarity", V_CLARITY},
  112. {"tone", V_TONE},
  113. {"numbers", V_NUMBERS},
  114. {"option", V_OPTION},
  115. {"mbrola", V_MBROLA},
  116. // these just set a value in langopts.param[]
  117. {"l_dieresis", 0x100+LOPT_DIERESES},
  118. // {"l_lengthen", 0x100+LOPT_IT_LENGTHEN},
  119. {"l_prefix", 0x100+LOPT_PREFIXES},
  120. {"l_regressive_v", 0x100+LOPT_REGRESSIVE_VOICING},
  121. {"l_unpronouncable", 0x100+LOPT_UNPRONOUNCABLE},
  122. {"l_sonorant_min", 0x100+LOPT_SONORANT_MIN},
  123. {"l_length_mods", 0x100+LOPT_LENGTH_MODS},
  124. {NULL, 0} };
  125. #define N_VOICES 100
  126. static int n_voices_tab = 0;
  127. static voice_t *voices_tab[N_VOICES];
  128. #define N_VOICE_VARIANTS 12
  129. const char variants_either[N_VOICE_VARIANTS] = {1,2,12,3,13,4,14,5,11,0};
  130. const char variants_male[N_VOICE_VARIANTS] = {1,2,3,4,5,0};
  131. const char variants_female[N_VOICE_VARIANTS] = {11,12,13,14,0};
  132. const char *variant_lists[3] = {variants_either, variants_male, variants_female};
  133. void SetToneAdjust(voice_t *voice, int *tone_pts)
  134. {//==============================================
  135. int ix;
  136. int pt;
  137. int y;
  138. int freq1=0;
  139. int freq2;
  140. int height1 = tone_pts[1];
  141. int height2;
  142. double rate;
  143. for(pt=0; pt<10; pt+=2)
  144. {
  145. if(tone_pts[pt] == -1)
  146. {
  147. tone_pts[pt] = N_TONE_ADJUST*8;
  148. if(pt > 0)
  149. tone_pts[pt+1] = tone_pts[pt-1];
  150. }
  151. freq2 = tone_pts[pt] / 8; // 8Hz steps
  152. height2 = tone_pts[pt+1];
  153. if((freq2 - freq1) > 0)
  154. {
  155. rate = double(height2-height1)/(freq2-freq1);
  156. for(ix=freq1; ix<freq2; ix++)
  157. {
  158. y = height1 + int(rate * (ix-freq1));
  159. if(y > 255)
  160. y = 255;
  161. voice->tone_adjust[ix] = y;
  162. }
  163. }
  164. freq1 = freq2;
  165. height1 = height2;
  166. }
  167. }
  168. void ReadTonePoints(char *string, int *tone_pts)
  169. {//=============================================
  170. // tone_pts[] is int[10]
  171. int ix;
  172. for(ix=0; ix<10; ix++)
  173. tone_pts[ix] = -1;
  174. sscanf(string,"%d %d %d %d %d %d %d %d",
  175. &tone_pts[0],&tone_pts[1],&tone_pts[2],&tone_pts[3],
  176. &tone_pts[4],&tone_pts[5],&tone_pts[6],&tone_pts[7]);
  177. }
  178. static espeak_VOICE *ReadVoiceFile(FILE *f_in, const char *fname, const char*leafname)
  179. {//===================================================================================
  180. // Read a Voice file, allocate a VOICE_DATA and set data from the
  181. // file's language, gender, name lines
  182. char linebuf[120];
  183. char vname[80];
  184. char vgender[80];
  185. char vlanguage[80];
  186. char languages[300]; // allow space for several alternate language names and priorities
  187. unsigned int len;
  188. int langix = 0;
  189. int n_languages = 0;
  190. char *p;
  191. espeak_VOICE *voice_data;
  192. int priority;
  193. int age;
  194. int n_variants = 3; // default, number of variants of this voice before using another voice
  195. int gender;
  196. #ifdef PLATFORM_WINDOWS
  197. if(memcmp(leafname,"mb-",3) == 0)
  198. {
  199. // check whether the mbrola speech data is present for this voice
  200. memcpy(vname,&leafname[3],3);
  201. vname[3] = 0;
  202. sprintf(linebuf,"%s/mbrola/%s",path_home,vname);
  203. if(GetFileLength(linebuf) <= 0)
  204. return(0);
  205. }
  206. #endif
  207. vname[0] = 0;
  208. vgender[0] = 0;
  209. age = 0;
  210. while(fgets(linebuf,sizeof(linebuf),f_in) != NULL)
  211. {
  212. linebuf[strlen(linebuf)-1] = 0;
  213. if(memcmp(linebuf,"name",4)==0)
  214. {
  215. p = &linebuf[4];
  216. while(isspace(*p)) p++;
  217. strncpy0(vname,p,sizeof(vname));
  218. }
  219. else
  220. if(memcmp(linebuf,"language",8)==0)
  221. {
  222. priority = DEFAULT_LANGUAGE_PRIORITY;
  223. vlanguage[0] = 0;
  224. sscanf(&linebuf[8],"%s %d",vlanguage,&priority);
  225. len = strlen(vlanguage) + 2;
  226. // check for space in languages[]
  227. if(len < (sizeof(languages)-langix-1))
  228. {
  229. languages[langix] = priority;
  230. strcpy(&languages[langix+1],vlanguage);
  231. langix += len;
  232. n_languages++;
  233. }
  234. }
  235. else
  236. if(memcmp(linebuf,"gender",6)==0)
  237. {
  238. sscanf(&linebuf[6],"%s %d",vgender,&age);
  239. }
  240. else
  241. if(memcmp(linebuf,"variants",8)==0)
  242. {
  243. sscanf(&linebuf[8],"%d",&n_variants);
  244. }
  245. }
  246. languages[langix++] = 0;
  247. gender = LookupMnem(genders,vgender);
  248. if(n_languages == 0)
  249. {
  250. #ifdef deleted
  251. // Read voice variant files
  252. // Don't use this, instead preset the variants_* arrays
  253. // no language is specified, this voice file only affects the voice characteristics
  254. if(memcmp(leafname,"!variant",8)==0)
  255. {
  256. if(((variant = atoi(&leafname[8])) > 0) && (strlen(variants_either) < N_VOICE_VARIANTS))
  257. {
  258. char string[2];
  259. string[0] = variant;
  260. string[1] = 0;
  261. strcat(variants_either,string);
  262. if(gender == 1)
  263. strcat(variants_male,string);
  264. if(gender == 2)
  265. strcat(variants_female,string);
  266. }
  267. }
  268. #endif
  269. return(NULL); // no language lines in the voice file
  270. }
  271. p = (char *)calloc(sizeof(espeak_VOICE) + langix + strlen(fname) + strlen(vname) + 3, 1);
  272. voice_data = (espeak_VOICE *)p;
  273. p = &p[sizeof(espeak_VOICE)];
  274. memcpy(p,languages,langix);
  275. voice_data->languages = p;
  276. strcpy(&p[langix],fname);
  277. voice_data->identifier = &p[langix];
  278. voice_data->name = &p[langix];
  279. if(vname[0] != 0)
  280. {
  281. langix += strlen(fname)+1;
  282. strcpy(&p[langix],vname);
  283. voice_data->name = &p[langix];
  284. }
  285. voice_data->age = age;
  286. voice_data->gender = gender;
  287. voice_data->variant = 0;
  288. voice_data->xx1 = n_variants;
  289. return(voice_data);
  290. } // end of ReadVoiceFile
  291. void VoiceReset(int tone_only)
  292. {//===========================
  293. // Set voice to the default values
  294. int pk;
  295. // default is: pitch 82,118
  296. voice->pitch_base = 0x49000; // default, 73 << 12;
  297. voice->pitch_range = 0x0f30; // default = 0x1000
  298. voice->echo_delay = 0;
  299. voice->echo_amp = 0;
  300. voice->flutter = 64;
  301. voice->n_harmonic_peaks = 5;
  302. voice->peak_shape = 1;
  303. #ifdef PLATFORM_RISCOS
  304. voice->roughness = 1;
  305. #else
  306. voice->roughness = 2;
  307. #endif
  308. for(pk=0; pk<N_PEAKS; pk++)
  309. {
  310. voice->freq[pk] = 256;
  311. voice->height[pk] = 256;
  312. voice->width[pk] = 256;
  313. // adjust formant smoothing depending on sample rate
  314. formant_rate[pk] = (formant_rate_22050[pk] * 22050)/samplerate;
  315. }
  316. // This table provides the opportunity for tone control.
  317. // Adjustment of harmonic amplitudes, steps of 8Hz
  318. // value of 128 means no change
  319. // memset(voice->tone_adjust,128,sizeof(voice->tone_adjust));
  320. SetToneAdjust(voice,tone_points);
  321. // default values of speed factors
  322. voice->speedf1 = 256;
  323. voice->speedf2 = 238;
  324. voice->speedf3 = 232;
  325. if(tone_only == 0)
  326. {
  327. n_replace_phonemes = 0;
  328. option_tone1 = 0;
  329. option_quiet = 0;
  330. LoadMbrolaTable(NULL,NULL);
  331. }
  332. } // end of VoiceReset
  333. static void VoiceFormant(char *p)
  334. {//==============================
  335. // Set parameters for a formant
  336. int ix;
  337. int formant;
  338. int freq = -1;
  339. int height = -1;
  340. int width = -1;
  341. ix = sscanf(p,"%d %d %d %d",&formant,&freq,&height,&width);
  342. if(ix < 2)
  343. return;
  344. if((formant < 0) || (formant > 8))
  345. return;
  346. if(freq >= 0)
  347. voice->freq[formant] = int(freq * 2.56001);
  348. if(height >= 0)
  349. voice->height[formant] = int(height * 2.56001);
  350. if(width >= 0)
  351. voice->width[formant] = int(width * 2.56001);
  352. }
  353. static voice_t *VoiceLookup(char *voicename)
  354. {//=========================================
  355. int ix;
  356. voice_t *v;
  357. for(ix=0; ix < N_VOICES; ix++)
  358. {
  359. if(ix == n_voices_tab)
  360. {
  361. // found a free slot
  362. v = (voice_t *)Alloc(sizeof(voice_t));
  363. if(v == NULL)
  364. return(NULL);
  365. voices_tab[n_voices_tab++] = v;
  366. strncpy0(v->name,voicename,sizeof(v->name));
  367. return(v);
  368. }
  369. else
  370. if(strcmp(voices_tab[ix]->name,voicename)==0)
  371. {
  372. return(voices_tab[ix]); // found the entry for the specified voice name
  373. }
  374. }
  375. return(NULL); // table is full
  376. } // end of VoiceLookup
  377. static void PhonemeReplacement(int type, char *p)
  378. {//==============================================
  379. int n;
  380. int phon;
  381. int flags = 0;
  382. char phon_string1[12];
  383. char phon_string2[12];
  384. strcpy(phon_string2,"NULL");
  385. n = sscanf(p,"%d %s %s",&flags,phon_string1,phon_string2);
  386. if((n < 2) || (n_replace_phonemes >= N_REPLACE_PHONEMES))
  387. return;
  388. if((phon = LookupPh(phon_string1)) == 0)
  389. return; // not recognised
  390. replace_phonemes[n_replace_phonemes].old_ph = phon;
  391. replace_phonemes[n_replace_phonemes].new_ph = LookupPh(phon_string2);
  392. replace_phonemes[n_replace_phonemes++].type = flags;
  393. } // end of PhonemeReplacement
  394. static int Read8Numbers(char *data_in,int *data)
  395. {//=============================================
  396. // Read 8 integer numbers
  397. return(sscanf(data_in,"%d %d %d %d %d %d %d %d",
  398. &data[0],&data[1],&data[2],&data[3],&data[4],&data[5],&data[6],&data[7]));
  399. }
  400. voice_t *LoadVoice(char *vname, int control)
  401. {//==========================================
  402. // control, bit 0 1= no_default
  403. // bit 1 1 = change tone only, not language
  404. // bit 2 1 = don't report error on LoadDictionary
  405. FILE *f_voice = NULL;
  406. keywtab_t *k;
  407. char *p;
  408. int key;
  409. int ix;
  410. int n;
  411. int value;
  412. int error = 0;
  413. int tone_only = control & 2;
  414. int language_set = 0;
  415. int phonemes_set = 0;
  416. int stress_amps_set = 0;
  417. int stress_lengths_set = 0;
  418. int stress_add_set = 0;
  419. int conditional_rules = 0;
  420. LANGUAGE_OPTIONS *langopts = NULL;
  421. voice_t *v;
  422. Translator *new_translator = NULL;
  423. char voicename[40];
  424. char language_name[40];
  425. char translator_name[40];
  426. char new_dictionary[40];
  427. char phonemes_name[40];
  428. char *language_type;
  429. char buf[200];
  430. char path_voices[140];
  431. char langname[4];
  432. int stress_amps[8];
  433. int stress_lengths[8];
  434. int stress_add[8];
  435. int pitch1;
  436. int pitch2;
  437. strcpy(voicename,vname);
  438. if(voicename[0]==0)
  439. strcpy(voicename,"default");
  440. sprintf(path_voices,"%s%cvoices%c",path_home,PATHSEP,PATHSEP);
  441. sprintf(buf,"%s%s",path_voices,voicename);
  442. if(GetFileLength(buf) <= 0)
  443. {
  444. // look for the voice in a sub-directory of the language name
  445. langname[0] = voicename[0];
  446. langname[1] = voicename[1];
  447. langname[2] = 0;
  448. sprintf(buf,"%s%s%c%s",path_voices,langname,PATHSEP,voicename);
  449. }
  450. f_voice = fopen(buf,"r");
  451. language_type = "en"; // default
  452. if(f_voice == NULL)
  453. {
  454. if(control & 3)
  455. return(NULL); // can't open file
  456. if(SelectPhonemeTableName(voicename) >= 0)
  457. language_type = voicename;
  458. }
  459. if(first_voice == NULL)
  460. {
  461. first_voice = ReadVoiceFile(f_voice,buf+strlen(path_voices),voicename);
  462. rewind(f_voice);
  463. }
  464. if(!tone_only && (translator != NULL))
  465. {
  466. delete translator;
  467. translator = NULL;
  468. }
  469. strcpy(translator_name,language_type);
  470. strcpy(new_dictionary,language_type);
  471. strcpy(phonemes_name,language_type);
  472. if((v = VoiceLookup(voicename)) != NULL)
  473. voice = v;
  474. VoiceReset(tone_only);
  475. if(!tone_only)
  476. SelectPhonemeTableName(phonemes_name); // set up phoneme_tab
  477. while((f_voice != NULL) && (fgets(buf,sizeof(buf),f_voice) != NULL))
  478. {
  479. if((p = strstr(buf,"//")) != NULL)
  480. *p = 0;
  481. // isolate the attribute name
  482. for(p=buf; (*p != 0) && !isspace(*p); p++);
  483. *p++ = 0;
  484. if(buf[0] == 0) continue;
  485. key = 0;
  486. for(k=keyword_tab; k->mnem != NULL; k++)
  487. {
  488. if(strcmp(buf,k->mnem)==0)
  489. {
  490. key = k->data;
  491. break;
  492. }
  493. }
  494. switch(key)
  495. {
  496. case V_LANGUAGE:
  497. // only act on the first language line
  498. if(language_set || tone_only)
  499. break;
  500. sscanf(p,"%s",language_name);
  501. language_type = strtok(language_name,"-");
  502. language_set = 1;
  503. strcpy(translator_name,language_type);
  504. strcpy(new_dictionary,language_type);
  505. strcpy(phonemes_name,language_type);
  506. SelectPhonemeTableName(phonemes_name);
  507. if(new_translator != NULL)
  508. delete new_translator;
  509. new_translator = SelectTranslator(translator_name);
  510. langopts = &new_translator->langopts;
  511. break;
  512. case V_NAME:
  513. case V_GENDER:
  514. break;
  515. case V_TRANSLATOR: // language_name
  516. if(tone_only) break;
  517. sscanf(p,"%s",translator_name);
  518. if(new_translator != NULL)
  519. delete new_translator;
  520. new_translator = SelectTranslator(translator_name);
  521. langopts = &new_translator->langopts;
  522. break;
  523. case V_DICTIONARY: // dictionary
  524. sscanf(p,"%s",new_dictionary);
  525. break;
  526. case V_PHONEMES: // phoneme table
  527. sscanf(p,"%s",phonemes_name);
  528. break;
  529. case V_FORMANT:
  530. VoiceFormant(p);
  531. break;
  532. case V_PITCH:
  533. // default is pitch 82 118
  534. n = sscanf(p,"%d %d",&pitch1,&pitch2);
  535. voice->pitch_base = (pitch1 - 9) << 12;
  536. voice->pitch_range = (pitch2 - pitch1) * 108;
  537. break;
  538. case V_STRESSLENGTH: // stressLength
  539. stress_lengths_set = Read8Numbers(p,stress_lengths);
  540. break;
  541. case V_STRESSAMP: // stressAmp
  542. stress_amps_set = Read8Numbers(p,stress_amps);
  543. break;
  544. case V_STRESSADD: // stressAdd
  545. stress_add_set = Read8Numbers(p,stress_add);
  546. break;
  547. case V_INTONATION: // intonation
  548. sscanf(p,"%d %d",&option_tone1,&option_tone2);
  549. break;
  550. case V_DICTRULES: // conditional dictionary rules and list entries
  551. while(*p != 0)
  552. {
  553. while(isspace(*p)) p++;
  554. n = -1;
  555. if((n = atoi(p)) > 0)
  556. {
  557. p++;
  558. conditional_rules |= (1 << n);
  559. }
  560. while(isalnum(*p)) p++;
  561. }
  562. break;
  563. case V_REPLACE:
  564. if(phonemes_set == 0)
  565. {
  566. // must set up a phoneme table before we can lookup phoneme mnemonics
  567. SelectPhonemeTableName(phonemes_name);
  568. phonemes_set = 1;
  569. }
  570. PhonemeReplacement(key,p);
  571. break;
  572. case V_WORDGAP: // words
  573. sscanf(p,"%d %d",&langopts->word_gap, &langopts->vowel_pause);
  574. break;
  575. case V_STRESSRULE:
  576. sscanf(p,"%d %d %d %d",&langopts->stress_rule,
  577. &langopts->stress_flags,
  578. &langopts->unstressed_wd1,
  579. &langopts->unstressed_wd2);
  580. break;
  581. case V_CHARSET:
  582. if((sscanf(p,"%d",&value)==1) && (value < N_CHARSETS))
  583. new_translator->charset_a0 = charsets[value];
  584. break;
  585. case V_NUMBERS:
  586. sscanf(p,"%d",&langopts->numbers);
  587. break;
  588. case V_OPTION:
  589. if(sscanf(p,"%d %d",&ix,&value) == 2)
  590. {
  591. if((ix >= 0) && (ix < N_LOPTS))
  592. langopts->param[ix] = value;
  593. }
  594. break;
  595. case V_ECHO:
  596. // echo. suggest: 135mS 11%
  597. value = 0;
  598. voice->echo_amp = 0;
  599. sscanf(p,"%d %d",&voice->echo_delay,&voice->echo_amp);
  600. break;
  601. case V_FLUTTER: // flutter
  602. if(sscanf(p,"%d",&value)==1)
  603. voice->flutter = value * 32;
  604. break;
  605. case V_ROUGHNESS: // roughness
  606. if(sscanf(p,"%d",&value)==1)
  607. voice->roughness = value;
  608. break;
  609. case V_CLARITY: // formantshape
  610. if(sscanf(p,"%d",&value)==1)
  611. {
  612. if(value > 4)
  613. {
  614. voice->peak_shape = 1; // squarer formant peaks
  615. value = 4;
  616. }
  617. voice->n_harmonic_peaks = 1+value;
  618. }
  619. break;
  620. case V_TONE:
  621. {
  622. int tone_data[10];
  623. ReadTonePoints(p,tone_data);
  624. SetToneAdjust(voice,tone_data);
  625. }
  626. break;
  627. case V_MBROLA:
  628. {
  629. char name[40];
  630. char phtrans[40];
  631. phtrans[0] = 0;
  632. sscanf(p,"%s %s",name,phtrans);
  633. LoadMbrolaTable(name,phtrans);
  634. }
  635. break;
  636. default:
  637. if((key & 0xff00) == 0x100)
  638. {
  639. sscanf(p,"%d",&langopts->param[key &0xff]);
  640. }
  641. else
  642. {
  643. fprintf(stderr,"Bad voice attribute: %s\n",buf);
  644. }
  645. break;
  646. }
  647. }
  648. if(f_voice != NULL)
  649. fclose(f_voice);
  650. if((new_translator == NULL) && (!tone_only))
  651. {
  652. // not set by language attribute
  653. new_translator = SelectTranslator(translator_name);
  654. }
  655. for(ix=0; ix<N_PEAKS; ix++)
  656. {
  657. voice->freq2[ix] = voice->freq[ix];
  658. voice->height2[ix] = voice->height[ix];
  659. voice->width2[ix] = voice->width[ix];
  660. }
  661. if(tone_only)
  662. {
  663. new_translator = translator;
  664. }
  665. else
  666. {
  667. if((ix = SelectPhonemeTableName(phonemes_name)) < 0)
  668. {
  669. fprintf(stderr,"Unknown phoneme table: '%s'\n",phonemes_name);
  670. }
  671. voice->phoneme_tab_ix = ix;
  672. error = new_translator->LoadDictionary(new_dictionary, control & 4);
  673. if(dictionary_name[0]==0)
  674. return(NULL); // no dictionary loaded
  675. new_translator->dict_condition = conditional_rules;
  676. }
  677. langopts = &new_translator->langopts;
  678. if((value = langopts->param[LOPT_LENGTH_MODS]) != 0)
  679. {
  680. SetLengthMods(new_translator,value);
  681. }
  682. voice->width[0] = (voice->width[0] * 105)/100;
  683. if(!tone_only)
  684. {
  685. translator = new_translator;
  686. strcpy(voice_name,voicename);
  687. }
  688. // relative lengths of different stress syllables
  689. for(ix=0; ix<stress_lengths_set; ix++)
  690. {
  691. translator->stress_lengths[ix] = stress_lengths[ix];
  692. }
  693. for(ix=0; ix<stress_add_set; ix++)
  694. {
  695. translator->stress_lengths[ix] += stress_add[ix];
  696. }
  697. for(ix=0; ix<stress_amps_set; ix++)
  698. {
  699. translator->stress_amps[ix] = stress_amps[ix];
  700. translator->stress_amps_r[ix] = stress_amps[ix] -1;
  701. }
  702. return(voice);
  703. } // end of LoadVoice
  704. voice_t *LoadVoiceVariant(const char *vname, int variant)
  705. {//======================================================
  706. voice_t *v;
  707. char *p;
  708. char buf[40];
  709. strcpy(buf,vname);
  710. if((p = strchr(buf,'+')) != NULL)
  711. {
  712. // The voice name has a +variant suffix
  713. *p = 0;
  714. variant = atoi(p+1);
  715. }
  716. v = LoadVoice(buf,0);
  717. if((v != NULL) && (variant > 0))
  718. {
  719. sprintf(buf,"!variant%d",variant);
  720. LoadVoice(buf,2);
  721. }
  722. return(v);
  723. }
  724. static int __cdecl VoiceNameSorter(const void *p1, const void *p2)
  725. {//=======================================================
  726. int ix;
  727. espeak_VOICE *v1 = *(espeak_VOICE **)p1;
  728. espeak_VOICE *v2 = *(espeak_VOICE **)p2;
  729. if((ix = strcmp(&v1->languages[1],&v2->languages[1])) != 0) // primary language name
  730. return(ix);
  731. if((ix = v1->languages[0] - v2->languages[0]) != 0) // priority number
  732. return(ix);
  733. return(strcmp(v1->name,v2->name));
  734. }
  735. static int __cdecl VoiceScoreSorter(const void *p1, const void *p2)
  736. {//========================================================
  737. int ix;
  738. espeak_VOICE *v1 = *(espeak_VOICE **)p1;
  739. espeak_VOICE *v2 = *(espeak_VOICE **)p2;
  740. if((ix = v2->score - v1->score) != 0)
  741. return(ix);
  742. return(strcmp(v2->name,v1->name));
  743. }
  744. static int ScoreVoice(espeak_VOICE *voice_spec, int spec_n_parts, int spec_lang_len, espeak_VOICE *voice)
  745. {//======================================================================================================
  746. int ix;
  747. char *p;
  748. int c1, c2;
  749. int language_priority;
  750. int n_parts;
  751. int matching;
  752. int matching_parts;
  753. int score = 0;
  754. int x;
  755. int ratio;
  756. int required_age;
  757. int diff;
  758. p = voice->languages; // list of languages+dialects for which this voice is suitable
  759. if(spec_n_parts == 0)
  760. {
  761. score = 100;
  762. }
  763. else
  764. {
  765. // compare the required language with each of the languages of this voice
  766. while(*p != 0)
  767. {
  768. language_priority = *p++;
  769. matching = 1;
  770. matching_parts = 0;
  771. n_parts = 1;
  772. for(ix=0; ; ix++)
  773. {
  774. if((ix >= spec_lang_len) || ((c1 = voice_spec->languages[ix]) == '-'))
  775. c1 = 0;
  776. if((c2 = p[ix]) == '-')
  777. c2 = 0;
  778. if(c1 != c2)
  779. {
  780. matching = 0;
  781. }
  782. if(p[ix] == '-')
  783. {
  784. n_parts++;
  785. if(matching)
  786. matching_parts++;
  787. }
  788. if(p[ix] == 0)
  789. break;
  790. }
  791. p += (ix+1);
  792. matching_parts += matching; // number of parts which match
  793. if(matching_parts == 0)
  794. break; // no matching parts for this language
  795. x = 5;
  796. // reduce the score if not all parts of the required language match
  797. if((diff = (spec_n_parts - matching_parts)) > 0)
  798. x -= diff;
  799. // reduce score if the language is more specific than required
  800. if((diff = (n_parts - matching_parts)) > 0)
  801. x -= diff;
  802. x = x*100 - (language_priority * 2);
  803. if(x > score)
  804. score = x;
  805. }
  806. }
  807. if(score == 0)
  808. return(0);
  809. if(voice_spec->name != NULL)
  810. {
  811. if(strcmp(voice_spec->name,voice->name)==0)
  812. {
  813. // match on voice name
  814. score += 500;
  815. }
  816. else
  817. if(strcmp(voice_spec->name,voice->identifier)==0)
  818. {
  819. score += 400;
  820. }
  821. }
  822. if(((voice_spec->gender == 1) || (voice_spec->gender == 2)) &&
  823. ((voice->gender == 1) || (voice->gender == 2)))
  824. {
  825. if(voice_spec->gender == voice->gender)
  826. score += 50;
  827. else
  828. score -= 50;
  829. }
  830. if((voice_spec->age <= 12) && (voice->gender == 2) && (voice->age > 12))
  831. {
  832. score += 5; // give some preference for non-child female voice if a child is requested
  833. }
  834. if(voice->age != 0)
  835. {
  836. if(voice_spec->age == 0)
  837. required_age = 30;
  838. else
  839. required_age = voice_spec->age;
  840. ratio = (required_age*100)/voice->age;
  841. if(ratio < 100)
  842. ratio = 10000/ratio;
  843. ratio = (ratio - 100)/10; // 0=exact match, 10=out by factor of 2
  844. x = 5 - ratio;
  845. if(x > 0) x = 0;
  846. score = score + x;
  847. if(voice_spec->age > 0)
  848. score += 10; // required age specified, favour voices with a specified age (near it)
  849. }
  850. if(score < 1)
  851. score = 1;
  852. return(score);
  853. } // end of ScoreVoice
  854. static int SetVoiceScores(espeak_VOICE *voice_select, espeak_VOICE **voices)
  855. {//=========================================================================
  856. int ix;
  857. int score;
  858. int nv; // number of candidates
  859. int n_parts=0;
  860. int lang_len=0;
  861. char *p;
  862. espeak_VOICE *vp;
  863. // count number of parts in the specified language
  864. if((voice_select->languages != NULL) && (voice_select->languages[0] != 0))
  865. {
  866. n_parts = 1;
  867. lang_len = strlen(voice_select->languages);
  868. for(p = voice_select->languages; *p != 0; p++)
  869. {
  870. if(*p == '-')
  871. n_parts++;
  872. }
  873. }
  874. // select those voices which match the specified language
  875. nv = 0;
  876. for(ix=0; ix<n_voices_list; ix++)
  877. {
  878. if((score = ScoreVoice(voice_select, n_parts, lang_len, voices_list[ix])) > 0)
  879. {
  880. voices[nv++] = vp = voices_list[ix];
  881. vp->score = score;
  882. }
  883. }
  884. voices[nv] = NULL; // list terminator
  885. if(nv==0)
  886. return(0);
  887. // sort the selected voices by their score
  888. qsort(voices,nv,sizeof(espeak_VOICE *),(int (__cdecl *)(const void *,const void *))VoiceScoreSorter);
  889. return(nv);
  890. } // end of SetVoiceScores
  891. static espeak_VOICE *SelectVoiceByName(espeak_VOICE **voices, const char *name)
  892. {//============================================================================
  893. int ix;
  894. int match_fname = -1;
  895. int match_fname2 = -1;
  896. int match_name = -1;
  897. char *id;
  898. int last_part_len;
  899. char last_part[41];
  900. sprintf(last_part,"%c%s",PATHSEP,name);
  901. last_part_len = strlen(last_part);
  902. for(ix=0; voices[ix] != NULL; ix++)
  903. {
  904. if(strcmp(name,voices[ix]->name)==0)
  905. {
  906. match_name = ix; // found matching voice name
  907. break;
  908. }
  909. else
  910. if(strcmp(name,id = voices[ix]->identifier)==0)
  911. {
  912. match_fname = ix; // matching identifier, use this if no matching name
  913. }
  914. else
  915. if(strcmp(last_part,&id[strlen(id)-last_part_len])==0)
  916. {
  917. match_fname2 = ix;
  918. }
  919. }
  920. if(match_name < 0)
  921. {
  922. match_name = match_fname; // no matching name, try matching filename
  923. if(match_name < 0)
  924. match_name = match_fname2; // try matching just the last part of the filename
  925. }
  926. if(match_name < 0)
  927. return(NULL);
  928. return(voices[match_name]);
  929. } // end of SelectVoiceByName
  930. espeak_VOICE *SelectVoice(espeak_VOICE *voice_select, int *variant)
  931. {//================================================================
  932. // Returns a path within espeak-voices, with a possible +variant suffix
  933. int nv; // number of candidates
  934. int ix, ix2;
  935. int j;
  936. int n_variants;
  937. int variant_number;
  938. int gender;
  939. int skip;
  940. int aged=1;
  941. const char *p, *p_start;
  942. espeak_VOICE *vp = NULL;
  943. espeak_VOICE *vp2;
  944. espeak_VOICE *voices[N_VOICES_LIST]; // list of candidates
  945. espeak_VOICE *voices2[N_VOICES_LIST+N_VOICE_VARIANTS];
  946. espeak_VOICE voice_variants[N_VOICE_VARIANTS];
  947. if(n_voices_list == 0)
  948. espeak_ListVoices(NULL); // create the voices list
  949. // select and sort voices for the required language
  950. nv = SetVoiceScores(voice_select,voices);
  951. if(nv == 0)
  952. {
  953. // no matching voice, choose the default
  954. if((voices[0] = SelectVoiceByName(voices_list,"default")) != NULL)
  955. nv = 1;
  956. }
  957. gender = 0;
  958. if((voice_select->gender == 2) || ((voice_select->age > 0) && (voice_select->age < 13)))
  959. gender = 2;
  960. else
  961. if(voice_select->gender == 1)
  962. gender = 1;
  963. #define AGE_OLD 60
  964. if(voice_select->age < AGE_OLD)
  965. aged = 0;
  966. p = p_start = variant_lists[gender];
  967. if(aged == 0)
  968. p++; // the first voice in the variants list is older
  969. // add variants for the top voices
  970. n_variants = 0;
  971. for(ix=0, ix2=0; ix<nv; ix++)
  972. {
  973. vp = voices[ix];
  974. // is the main voice the required gender?
  975. skip=0;
  976. if((gender != 0) && (vp->gender != gender))
  977. {
  978. skip=1;
  979. }
  980. if((ix2==0) && aged && (vp->age < AGE_OLD))
  981. {
  982. skip=1;
  983. }
  984. if(skip==0)
  985. {
  986. voices2[ix2++] = vp;
  987. }
  988. for(j=0; (j < vp->xx1) && (n_variants < N_VOICE_VARIANTS);)
  989. {
  990. if((variant_number = *p) == 0)
  991. {
  992. p = p_start;
  993. continue;
  994. }
  995. vp2 = &voice_variants[n_variants++]; // allocate space for voice variant
  996. memcpy(vp2,vp,sizeof(espeak_VOICE)); // copy from the original voice
  997. vp2->variant = variant_number;
  998. voices2[ix2++] = vp2;
  999. p++;
  1000. j++;
  1001. }
  1002. }
  1003. // add any more variants to the end of the list
  1004. while((vp != NULL) && ((variant_number = *p++) != 0) && (n_variants < N_VOICE_VARIANTS))
  1005. {
  1006. vp2 = &voice_variants[n_variants++]; // allocate space for voice variant
  1007. memcpy(vp2,vp,sizeof(espeak_VOICE)); // copy from the original voice
  1008. vp2->variant = variant_number;
  1009. voices2[ix2++] = vp2;
  1010. }
  1011. // index the sorted list by the required variant number
  1012. vp = voices2[voice_select->variant % ix2];
  1013. *variant = vp->variant;
  1014. return(vp);
  1015. } // end of SelectVoice
  1016. void GetVoices(const char *path)
  1017. {//=============================
  1018. FILE *f_voice;
  1019. espeak_VOICE *voice_data;
  1020. int ftype;
  1021. char fname[140];
  1022. #ifdef PLATFORM_RISCOS
  1023. #else
  1024. #ifdef PLATFORM_WINDOWS
  1025. WIN32_FIND_DATA FindFileData;
  1026. HANDLE hFind = INVALID_HANDLE_VALUE;
  1027. DWORD dwError;
  1028. sprintf(fname,"%s\\*",path);
  1029. hFind = FindFirstFile(fname, &FindFileData);
  1030. if(hFind == INVALID_HANDLE_VALUE)
  1031. return;
  1032. do {
  1033. sprintf(fname,"%s%c%s",path,PATHSEP,FindFileData.cFileName);
  1034. ftype = GetFileLength(fname);
  1035. if((ftype == -2) && (FindFileData.cFileName[0] != '.'))
  1036. {
  1037. // a sub-sirectory
  1038. GetVoices(fname);
  1039. }
  1040. else
  1041. if(ftype > 0)
  1042. {
  1043. // a regular line, add it to the voices list
  1044. if((f_voice = fopen(fname,"r")) == NULL)
  1045. continue;
  1046. // pass voice file name within the voices directory
  1047. voice_data = ReadVoiceFile(f_voice, fname+len_path_voices, FindFileData.cFileName);
  1048. fclose(f_voice);
  1049. if(voice_data != NULL)
  1050. {
  1051. voices_list[n_voices_list++] = voice_data;
  1052. }
  1053. }
  1054. } while(FindNextFile(hFind, &FindFileData) != 0);
  1055. FindClose(hFind);
  1056. #else
  1057. DIR *dir;
  1058. struct dirent *ent;
  1059. if((dir = opendir(path)) == NULL)
  1060. return;
  1061. while((ent = readdir(dir)) != NULL)
  1062. {
  1063. if(n_voices_list >= (N_VOICES_LIST-2))
  1064. break; // voices list is full
  1065. sprintf(fname,"%s%c%s",path,PATHSEP,ent->d_name);
  1066. ftype = GetFileLength(fname);
  1067. if((ftype == -2) && (ent->d_name[0] != '.'))
  1068. {
  1069. // a sub-sirectory
  1070. GetVoices(fname);
  1071. }
  1072. else
  1073. if(ftype > 0)
  1074. {
  1075. // a regular line, add it to the voices list
  1076. if((f_voice = fopen(fname,"r")) == NULL)
  1077. continue;
  1078. // pass voice file name within the voices directory
  1079. voice_data = ReadVoiceFile(f_voice, fname+len_path_voices, ent->d_name);
  1080. fclose(f_voice);
  1081. if(voice_data != NULL)
  1082. {
  1083. voices_list[n_voices_list++] = voice_data;
  1084. }
  1085. }
  1086. }
  1087. closedir(dir);
  1088. #endif
  1089. #endif
  1090. } // end of GetVoices
  1091. espeak_ERROR SetVoiceByName(const char *name)
  1092. {//=========================================
  1093. espeak_VOICE *v;
  1094. int variant=0;
  1095. char *p;
  1096. char variant_name[20];
  1097. static char buf[60];
  1098. strncpy0(buf,name,sizeof(buf));
  1099. if((p = strchr(buf,'+')) != NULL)
  1100. {
  1101. // remove the voice variant suffix, from eg. en+3
  1102. *p = 0;
  1103. variant = atoi(p+1);
  1104. }
  1105. // first check for a voice with this filename
  1106. if(LoadVoice(buf,1) != NULL)
  1107. {
  1108. voice_selected = first_voice;
  1109. if(variant > 0)
  1110. {
  1111. // apply a voice variant
  1112. sprintf(variant_name,"!variant%d",variant);
  1113. LoadVoice(variant_name,2);
  1114. }
  1115. WavegenSetVoice(voice);
  1116. return(EE_OK);
  1117. }
  1118. if(n_voices_list == 0)
  1119. espeak_ListVoices(NULL); // create the voices list
  1120. if((v = SelectVoiceByName(voices_list,buf)) != NULL)
  1121. {
  1122. if(LoadVoiceVariant(v->identifier,variant) != NULL)
  1123. {
  1124. voice_selected = v;
  1125. WavegenSetVoice(voice);
  1126. return(EE_OK);
  1127. }
  1128. }
  1129. return(EE_INTERNAL_ERROR); // voice name not found
  1130. } // end of espeak_SetVoiceByName
  1131. espeak_ERROR SetVoiceByProperties(espeak_VOICE *voice_selector)
  1132. {//============================================================
  1133. int variant;
  1134. voice_selected = SelectVoice(voice_selector,&variant);
  1135. LoadVoiceVariant(voice_selected->identifier,variant);
  1136. WavegenSetVoice(voice);
  1137. return(EE_OK);
  1138. } // end of espeak_SetVoiceByProperties
  1139. //=======================================================================
  1140. // Library Interface Functions
  1141. //=======================================================================
  1142. #pragma GCC visibility push(default)
  1143. ESPEAK_API const espeak_VOICE **espeak_ListVoices(espeak_VOICE *voice_spec)
  1144. {//========================================================================
  1145. #ifndef PLATFORM_RISCOS
  1146. int ix;
  1147. static espeak_VOICE *voices[N_VOICES_LIST];
  1148. char selected_voice_id[80];
  1149. char path_voices[130];
  1150. // free previous voice list data
  1151. if((voice_selected != NULL) && (voice_selected->identifier != NULL))
  1152. strncpy0(selected_voice_id,voice_selected->identifier,sizeof(selected_voice_id));
  1153. else
  1154. selected_voice_id[0] = 0;
  1155. voice_selected = NULL;
  1156. for(ix=0; ix<n_voices_list; ix++)
  1157. {
  1158. if(voices_list[ix] != NULL)
  1159. free(voices_list[ix]);
  1160. }
  1161. n_voices_list = 0;
  1162. sprintf(path_voices,"%s%cvoices",path_home,PATHSEP);
  1163. len_path_voices = strlen(path_voices)+1;
  1164. GetVoices(path_voices);
  1165. voices_list[n_voices_list] = NULL; // voices list terminator
  1166. // sort the voices list
  1167. qsort(voices_list,n_voices_list,sizeof(espeak_VOICE *),
  1168. (int (__cdecl *)(const void *,const void *))VoiceNameSorter);
  1169. // restore pointer to current voice
  1170. if(selected_voice_id[0] != 0)
  1171. {
  1172. for(ix=0; ix<n_voices_list; ix++)
  1173. {
  1174. if(strcmp(selected_voice_id, voices_list[ix]->identifier)==0)
  1175. {
  1176. voice_selected = voices_list[ix];
  1177. break;
  1178. }
  1179. }
  1180. }
  1181. if(voice_spec)
  1182. {
  1183. // select the voices which match the voice_spec, and sort them by preference
  1184. SetVoiceScores(voice_spec,voices);
  1185. return((const espeak_VOICE **)voices);
  1186. }
  1187. #endif
  1188. return((const espeak_VOICE **)voices_list);
  1189. } // end of espeak_ListVoices
  1190. ESPEAK_API espeak_VOICE *espeak_GetCurrentVoice(void)
  1191. {//==================================================
  1192. return(voice_selected);
  1193. }
  1194. #pragma GCC visibility pop