| 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 | |
| 21 | #include "espeak__config.h"cxx . . $ `<file>/external/espeak/espeak__config.h`/ |
| 22 | |
| 23 | #include <ctype.h> |
| 24 | #include <errno.h> |
| 25 | #include <stdint.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #include "espeak_ng.h"cxx . . $ `<file>/external/espeak/espeak_ng.h`/ |
| 31 | #include "speak_lib.h"cxx . . $ `<file>/external/espeak/speak_lib.h`/ |
| 32 | #include "encoding.h"cxx . . $ `<file>/external/espeak/encoding.h`/ |
| 33 | |
| 34 | #include "langopts.h"cxx . . $ `<file>/external/espeak/langopts.h`/ |
| 35 | #include "mnemonics.h"cxx . . $ `<file>/external/espeak/mnemonics.h`/ // for MNEM_TAB |
| 36 | #include "translate.h"cxx . . $ `<file>/external/espeak/translate.h`/ // for Translator |
| 37 | #include "soundicon.h"cxx . . $ `<file>/external/espeak/soundicon.h`/ // for soundicon_tab, n_soundicon_tab |
| 38 | #include "speech.h"cxx . . $ `<file>/external/espeak/speech.h`/ // for path_home, PATHSEP |
| 39 | #include "synthdata.h"cxx . . $ `<file>/external/espeak/synthdata.h`/ // for n_tunes, tunes |
| 40 | #include "voice.h"cxx . . $ `<file>/external/espeak/voice.h`/ // for ReadNumbers, Read8Numbers, ... |
| 41 | |
| 42 | static int CheckTranslatorcxx . . $ CheckTranslator(5bd99569610dd3ab).(Translator *tr, const MNEM_TAB *keyword_tab, int key); |
| 43 | static int LookupTunecxx . . $ LookupTune(5c4306d8553b3696).(const char *name); |
| 44 | |
| 45 | void LoadLanguageOptionscxx . . $ LoadLanguageOptions(5d08074edf57aaac).(Translator *transltr, int key, char *keyValue ) { |
| 46 | if (CheckTranslatorcxx . . $ CheckTranslator(5bd99569610dd3ab).(transltr, langopts_tab, key) != 0) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | int ix; |
| 51 | int n; |
| 52 | |
| 53 | switch (key) { |
| 54 | case V_DICTMIN: { |
| 55 | |
| 56 | |
| 57 | if (sscanf(keyValue, "%d", &n) == 1) |
| 58 | transltr->dict_min_size = n; |
| 59 | |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | case V_DICTRULES: { // conditional dictionary rules and list entries |
| 64 | ReadNumbers(keyValue, &transltr->dict_condition, 32, langopts_tab, key); |
| 65 | break; |
| 66 | } |
| 67 | case V_INTONATION: { |
| 68 | sscanf(keyValue, "%d", &option_tone_flags); |
| 69 | if ((option_tone_flags & 0xff) != 0) { |
| 70 | transltr->langopts.intonation_group = option_tone_flags & 0xff; |
| 71 | } |
| 72 | break; |
| 73 | } |
| 74 | case V_NUMBERS: { |
| 75 | // expect a list of numbers |
| 76 | while (*keyValue != 0) { |
| 77 | while (isspace(*keyValue)) keyValue++; |
| 78 | if ((n = atoicxx . . $ atoi(f5ecf3191ed0cd93).(keyValue)) > 0) { |
| 79 | keyValue++; |
| 80 | if (n < 32) { |
| 81 | transltr->langopts.numbers |= (1 << n); |
| 82 | } else { |
| 83 | if (n < 64) |
| 84 | transltr->langopts.numbers2 |= (1 << (n-32)); |
| 85 | else |
| 86 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "numbers: Bad option number %d\n", n); } |
| 87 | } |
| 88 | while (isalnum(*keyValue)) keyValue++; |
| 89 | } |
| 90 | ProcessLanguageOptions(&(transltr->langopts)); |
| 91 | |
| 92 | break; |
| 93 | } |
| 94 | case V_LOWERCASE_SENTENCE: { |
| 95 | transltr->langopts.lowercase_sentence = true; |
| 96 | break; |
| 97 | } |
| 98 | case V_SPELLINGSTRESS: { |
| 99 | transltr->langopts.spelling_stress = true; |
| 100 | break; |
| 101 | } |
| 102 | case V_STRESSADD: { // stressAdd |
| 103 | int stress_add_set = 0; |
| 104 | int stress_add[8]; |
| 105 | |
| 106 | stress_add_set = Read8Numbers(keyValue, stress_add); |
| 107 | |
| 108 | for (ix = 0; ix < stress_add_set; ix++) { |
| 109 | transltr->stress_lengths[ix] += stress_add[ix]; |
| 110 | } |
| 111 | |
| 112 | break; |
| 113 | } |
| 114 | case V_STRESSAMP: { |
| 115 | |
| 116 | int stress_amps_set = 0; |
| 117 | int stress_amps[8]; |
| 118 | |
| 119 | stress_amps_set = Read8Numbers(keyValue, stress_amps); |
| 120 | |
| 121 | for (ix = 0; ix < stress_amps_set; ix++) { |
| 122 | transltr->stress_amps[ix] = stress_amps[ix]; |
| 123 | } |
| 124 | |
| 125 | break; |
| 126 | } |
| 127 | case V_STRESSLENGTH: { |
| 128 | //printf("parsing: %s", keyValue); |
| 129 | int stress_lengths_set = 0; |
| 130 | int stress_lengths[8]; |
| 131 | stress_lengths_set = Read8Numbers(keyValue, stress_lengths); |
| 132 | |
| 133 | for (ix = 0; ix < stress_lengths_set; ix++) { |
| 134 | transltr->stress_lengths[ix] = stress_lengths[ix]; |
| 135 | } |
| 136 | break; |
| 137 | } |
| 138 | case V_STRESSOPT: { |
| 139 | ReadNumbers(keyValue, &transltr->langopts.stress_flags, 32, langopts_tab, key); |
| 140 | break; |
| 141 | } |
| 142 | case V_STRESSRULE: { |
| 143 | sscanf(keyValue, "%d %d %d", &transltr->langopts.stress_rule, |
| 144 | &transltr->langopts.unstressed_wd1, |
| 145 | &transltr->langopts.unstressed_wd2); |
| 146 | |
| 147 | break; |
| 148 | } |
| 149 | case V_TUNES: { |
| 150 | char names[6][40] = { {0}, {0}, {0}, {0}, {0}, {0} }; |
| 151 | n = sscanf(keyValue, "%s %s %s %s %s %s", names[0], names[1], names[2], names[3], names[4], names[5]); |
| 152 | transltr->langopts.intonation_group = 0; |
| 153 | |
| 154 | int value; |
| 155 | for (ix = 0; ix < n; ix++) { |
| 156 | if (strcmp(names[ix], "NULL") == 0) |
| 157 | continue; |
| 158 | |
| 159 | |
| 160 | if ((value = LookupTunecxx . . $ LookupTune(5c4306d8553b3696).(names[ix])) < 0) |
| 161 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Unknown tune '%s'\n", names[ix]); |
| 162 | else |
| 163 | transltr->langopts.tunes[ix] = value; |
| 164 | } |
| 165 | break; |
| 166 | } |
| 167 | case V_WORDGAP: { |
| 168 | sscanf(keyValue, "%d %d", &transltr->langopts.word_gap, &transltr->langopts.vowel_pause); |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | default: { |
| 173 | if ((key & 0xff00) == 0x100) { |
| 174 | sscanf(keyValue, "%d", &transltr->langopts.param[key &0xff]); |
| 175 | } |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | void LoadConfigcxx . . $ LoadConfig(49f6e7a06ebc5aa8).(void) { |
| 182 | // Load configuration file, if one exists |
| 183 | char buf[sizeof(path_home)+10]; |
| 184 | FILE *f; |
| 185 | int ix; |
| 186 | char c1; |
| 187 | char string[200]; |
| 188 | |
| 189 | sprintf(buf, "%s%c%s", path_home, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!, "config"); |
| 190 | if ((f = fopen(buf, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 191 | return; |
| 192 | |
| 193 | while (fgets(buf, sizeof(buf), f) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 194 | if (buf[0] == '/') continue; |
| 195 | |
| 196 | if (memcmp(buf, "tone", 4) == 0) |
| 197 | ReadTonePoints(&buf[5], tone_points); |
| 198 | else if (memcmp(buf, "soundicon", 9) == 0) { |
| 199 | ix = sscanf(&buf[10], "_%c %s", &c1, string); |
| 200 | if (ix == 2) { |
| 201 | // add sound file information to soundicon array |
| 202 | // the file will be loaded to memory by LoadSoundFile2() |
| 203 | soundicon_tab[n_soundicon_tab].name = c1; |
| 204 | soundicon_tab[n_soundicon_tab].filename = strdup(string); |
| 205 | soundicon_tab[n_soundicon_tab++].length = 0; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | fclose(f); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | static int LookupTunecxx . . $ LookupTune(5c4306d8553b3696).(const char *name) { |
| 214 | int ix; |
| 215 | |
| 216 | for (ix = 0; ix < n_tunes; ix++) { |
| 217 | if (strcmp(name, tunes[ix].name) == 0) |
| 218 | return ix; |
| 219 | } |
| 220 | return -1; |
| 221 | } |
| 222 | |
| 223 | int CheckTranslatorcxx . . $ CheckTranslator(5bd99569610dd3ab).(Translator *tr, const MNEM_TAB *keyword_table, int key) |
| 224 | { |
| 225 | // Return 0 if translator is set. |
| 226 | // Return 1 and print an error message for specified key if not |
| 227 | // used for parsing language options |
| 228 | if (tr) |
| 229 | return 0; |
| 230 | |
| 231 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Cannot set %s: language not set, or is invalid.\n", LookupMnemName(keyword_table, key)); |
| 232 | return 1; |
| 233 | } |