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.

langopts.c 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (C) 2005 to 2015 by Jonathan Duddington
  3. * email: [email protected]
  4. * Copyright (C) 2015-2017 Reece H. Dunn
  5. * Copyright (C) 2022 Juho Hiltunen
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see: <http://www.gnu.org/licenses/>.
  19. */
  20. #include "config.h"
  21. #include <errno.h>
  22. #include <stdint.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. static int LookupTune(const char *name);
  27. #include <espeak-ng/espeak_ng.h>
  28. #include <espeak-ng/speak_lib.h>
  29. #include <espeak-ng/encoding.h>
  30. #include "langopts.h"
  31. #include "mnemonics.h" // for MNEM_TAB
  32. #include "translate.h" // for Translator
  33. #include "voice.h" // for CheckTranslator()
  34. #include "synthdata.h" // for n_tunes, tunes
  35. enum {
  36. V_NAME = 1,
  37. V_LANGUAGE,
  38. V_GENDER,
  39. V_PHONEMES,
  40. V_DICTIONARY,
  41. V_VARIANTS,
  42. V_MAINTAINER,
  43. V_STATUS,
  44. // these affect voice quality, are independent of language
  45. V_FORMANT,
  46. V_PITCH,
  47. V_ECHO,
  48. V_FLUTTER,
  49. V_ROUGHNESS,
  50. V_CLARITY,
  51. V_TONE,
  52. V_VOICING,
  53. V_BREATH,
  54. V_BREATHW,
  55. // these override defaults set by the translator
  56. V_LOWERCASE_SENTENCE,
  57. V_WORDGAP,
  58. V_INTONATION,
  59. V_TUNES,
  60. V_STRESSLENGTH,
  61. V_STRESSAMP,
  62. V_STRESSADD,
  63. V_DICTRULES,
  64. V_STRESSRULE,
  65. V_STRESSOPT,
  66. V_NUMBERS,
  67. V_MBROLA,
  68. V_KLATT,
  69. V_FAST,
  70. V_SPEED,
  71. V_DICTMIN,
  72. // these need a phoneme table to have been specified
  73. V_REPLACE,
  74. V_CONSONANTS
  75. };
  76. extern const MNEM_TAB langopts_tab[];
  77. void LoadLanguageOptions(Translator *translator, int key, char *keyValue ) {
  78. int ix;
  79. int n;
  80. switch (key) {
  81. case V_DICTMIN: {
  82. if (CheckTranslator(translator, langopts_tab, key) != 0)
  83. break;
  84. if (sscanf(keyValue, "%d", &n) == 1)
  85. translator->dict_min_size = n;
  86. break;
  87. }
  88. case V_DICTRULES: { // conditional dictionary rules and list entries
  89. if (CheckTranslator(translator, langopts_tab, key) != 0)
  90. break;
  91. ReadNumbers(keyValue, &translator->dict_condition, 32, langopts_tab, key);
  92. break;
  93. }
  94. case V_INTONATION: {
  95. sscanf(keyValue, "%d", &option_tone_flags);
  96. if ((option_tone_flags & 0xff) != 0) {
  97. if (CheckTranslator(translator, langopts_tab, key) != 0)
  98. break;
  99. translator->langopts.intonation_group = option_tone_flags & 0xff;
  100. }
  101. break;
  102. }
  103. case V_LOWERCASE_SENTENCE: {
  104. if (CheckTranslator(translator, langopts_tab, key) != 0)
  105. break;
  106. translator->langopts.lowercase_sentence = true;
  107. break;
  108. }
  109. case V_STRESSADD: { // stressAdd
  110. if (CheckTranslator(translator, langopts_tab, key) != 0)
  111. break;
  112. int stress_add_set = 0;
  113. int stress_add[8];
  114. stress_add_set = Read8Numbers(keyValue, stress_add);
  115. for (ix = 0; ix < stress_add_set; ix++) {
  116. translator->stress_lengths[ix] += stress_add[ix];
  117. }
  118. break;
  119. }
  120. case V_STRESSAMP: {
  121. if (CheckTranslator(translator, langopts_tab, key) != 0)
  122. break;
  123. int stress_amps_set = 0;
  124. int stress_amps[8];
  125. stress_amps_set = Read8Numbers(keyValue, stress_amps);
  126. for (ix = 0; ix < stress_amps_set; ix++) {
  127. translator->stress_amps[ix] = stress_amps[ix];
  128. }
  129. break;
  130. }
  131. case V_STRESSLENGTH: {
  132. if (CheckTranslator(translator, langopts_tab, key) != 0)
  133. break;
  134. //printf("parsing: %s", keyValue);
  135. int stress_lengths_set = 0;
  136. int stress_lengths[8];
  137. stress_lengths_set = Read8Numbers(keyValue, stress_lengths);
  138. for (ix = 0; ix < stress_lengths_set; ix++) {
  139. translator->stress_lengths[ix] = stress_lengths[ix];
  140. }
  141. break;
  142. }
  143. case V_STRESSOPT: {
  144. if (CheckTranslator(translator, langopts_tab, key) != 0)
  145. break;
  146. ReadNumbers(keyValue, &translator->langopts.stress_flags, 32, langopts_tab, key);
  147. break;
  148. }
  149. case V_STRESSRULE: {
  150. if (CheckTranslator(translator, langopts_tab, key) != 0)
  151. break;
  152. sscanf(keyValue, "%d %d %d", &translator->langopts.stress_rule,
  153. &translator->langopts.unstressed_wd1,
  154. &translator->langopts.unstressed_wd2);
  155. break;
  156. }
  157. case V_TUNES: {
  158. if (CheckTranslator(translator, langopts_tab, key) != 0)
  159. break;
  160. char names[8][40];
  161. n = sscanf(keyValue, "%s %s %s %s %s %s", names[0], names[1], names[2], names[3], names[4], names[5]);
  162. translator->langopts.intonation_group = 0;
  163. for (ix = 0; ix < n; ix++) {
  164. if (strcmp(names[ix], "NULL") == 0)
  165. continue;
  166. if ((n = LookupTune(names[ix])) < 0)
  167. fprintf(stderr, "Unknown tune '%s'\n", names[ix]);
  168. else
  169. translator->langopts.tunes[ix] = n;
  170. }
  171. break;
  172. }
  173. case V_MAINTAINER:
  174. case V_STATUS:
  175. break;
  176. }
  177. }
  178. static int LookupTune(const char *name) {
  179. int ix;
  180. for (ix = 0; ix < n_tunes; ix++) {
  181. if (strcmp(name, tunes[ix].name) == 0)
  182. return ix;
  183. }
  184. return -1;
  185. }