| 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2005 to 2015 by Jonathan Duddington |
| 4 | * email: [email protected] |
| 5 | * Copyright (C) 2015-2017 Reece H. Dunn |
| 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 "wctype_portable.h"cxx . . $ `<file>/kar/wctype_portable.h`/ |
| 25 | #include <errno.h> |
| 26 | #include <stdint.h> |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <strings.h> |
| 31 | |
| 32 | #if defined(_WIN32) || defined(_WIN64) |
| 33 | #include <windows.h> |
| 34 | #else |
| 35 | #include <dirent.h> |
| 36 | #endif |
| 37 | |
| 38 | #include "espeak_ng.h"cxx . . $ `<file>/external/espeak/espeak_ng.h`/ |
| 39 | #include "speak_lib.h"cxx . . $ `<file>/external/espeak/speak_lib.h`/ |
| 40 | #include "encoding.h"cxx . . $ `<file>/external/espeak/encoding.h`/ |
| 41 | |
| 42 | #include "voice.h"cxx . . $ `<file>/external/espeak/voice.h`/ // for voice_t, DoVoiceChange, N_PEAKS |
| 43 | #include "common.h"cxx . . $ `<file>/external/espeak/common.h`/ // for GetFileLength, strncpy0 |
| 44 | #include "dictionary.h"cxx . . $ `<file>/external/espeak/dictionary.h`/ // for LoadDictionary |
| 45 | #include "langopts.h"cxx . . $ `<file>/external/espeak/langopts.h`/ // for LoadLanguageOptions |
| 46 | #include "mnemonics.h"cxx . . $ `<file>/external/espeak/mnemonics.h`/ // for LookupMnemName, MNEM_TAB |
| 47 | #include "phoneme.h"cxx . . $ `<file>/external/espeak/phoneme.h`/ // for REPLACE_PHONEMES, n_replace_pho... |
| 48 | #include "speech.h"cxx . . $ `<file>/external/espeak/speech.h`/ // for PATHSEP |
| 49 | #include "mbrola.h"cxx . . $ `<file>/external/espeak/mbrola.h`/ // for LoadMbrolaTable |
| 50 | #include "synthdata.h"cxx . . $ `<file>/external/espeak/synthdata.h`/ // for SelectPhonemeTableName, LookupP... |
| 51 | #include "synthesize.h"cxx . . $ `<file>/external/espeak/synthesize.h`/ // for SetSpeed, SPEED_FACTORS, speed |
| 52 | #include "translate.h"cxx . . $ `<file>/external/espeak/translate.h`/ // for LANGUAGE_OPTIONS, DeleteTranslator |
| 53 | #include "wavegen.h"cxx . . $ `<file>/external/espeak/wavegen.h`/ // for InitBreath |
| 54 | |
| 55 | #include "espeak_praat.h"cxx . . $ `<file>/external/espeak/espeak_praat.h`/ // for theEspeakPraatFileInMemorySet |
| 56 | |
| 57 | static int AddToVoicesListcxx . . $ AddToVoicesList(1163be050dbfff7).(const char *fname, int len_path_voices, int is_language_file); |
| 58 | |
| 59 | |
| 60 | static const MNEM_TAB genderscxx . . $ genders.[] = { |
| 61 | { "male", ENGENDER_MALE }, |
| 62 | { "female", ENGENDER_FEMALE }, |
| 63 | { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, ENGENDER_MALE } |
| 64 | }; |
| 65 | |
| 66 | int tone_pointscxx . . $ tone_points.[12] = { 600, 170, 1200, 135, 2000, 110, 3000, 110, -1, 0 }; |
| 67 | |
| 68 | // limit the rate of change for each formant number |
| 69 | static const int formant_rate_22050cxx . . $ formant_rate_22050.[9] = { 240, 170, 170, 170, 170, 170, 170, 170, 170 }; // values for 22kHz sample rate |
| 70 | int formant_ratecxx . . $ formant_rate.[9]; // values adjusted for actual sample rate |
| 71 | |
| 72 | #define DEFAULT_LANGUAGE_PRIORITYcxx . . $ `external/espeak/voices.cpp:72:9`! 5 |
| 73 | #define N_VOICES_LISTcxx . . $ `external/espeak/voices.cpp:73:9`! 350 |
| 74 | int n_voices_listcxx . . $ n_voices_list. = 0; |
| 75 | espeak_VOICEcxx . . $ espeak_VOICE# *voices_listcxx . . $ voices_list.[N_VOICES_LISTcxx . . $ `external/espeak/voices.cpp:73:9`!]; |
| 76 | |
| 77 | static espeak_VOICEcxx . . $ espeak_VOICE# current_voice_selectedcxx . . $ current_voice_selected.; |
| 78 | |
| 79 | #define N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`! 12 |
| 80 | static const char variants_eithercxx . . $ variants_either.[N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`!] = { 1, 2, 12, 3, 13, 4, 14, 5, 11, 0 }; |
| 81 | static const char variants_malecxx . . $ variants_male.[N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`!] = { 1, 2, 3, 4, 5, 6, 0 }; |
| 82 | static const char variants_femalecxx . . $ variants_female.[N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`!] = { 11, 12, 13, 14, 0 }; |
| 83 | static const char *const variant_listscxx . . $ variant_lists.[3] = { variants_eithercxx . . $ variants_either., variants_malecxx . . $ variants_male., variants_femalecxx . . $ variants_female. }; |
| 84 | |
| 85 | static voice_t voicedatacxx . . $ voicedata.; |
| 86 | voice_t *voicecxx . . $ voice. = &voicedatacxx . . $ voicedata.; |
| 87 | |
| 88 | static char *fgets_stripcxx . . $ fgets_strip(8f279ba863457a36).(char *buf, int size, FileInMemorycxx . . $ FileInMemory# f_in) |
| 89 | { |
| 90 | // strip trailing spaces, and truncate lines at // comment |
| 91 | int len; |
| 92 | char *p; |
| 93 | |
| 94 | if (FileInMemory_fgetscxx . . $ FileInMemory_fgets(8f279ba863457a36).(buf, size, f_in) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 95 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 96 | |
| 97 | if (buf[0] == '#') { |
| 98 | buf[0] = 0; |
| 99 | return buf; |
| 100 | } |
| 101 | |
| 102 | len = strlen(buf); |
| 103 | while ((--len > 0) && isspace(buf[len])) |
| 104 | buf[len] = 0; |
| 105 | |
| 106 | if ((p = strstr(buf, "//")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 107 | *p = 0; |
| 108 | |
| 109 | return buf; |
| 110 | } |
| 111 | |
| 112 | static void SetToneAdjustcxx . . $ SetToneAdjust(b925784a8612db61).(voice_t *voicet, int *tone_pts) |
| 113 | { |
| 114 | int ix; |
| 115 | int pt; |
| 116 | int y; |
| 117 | int freq1 = 0; |
| 118 | int height1 = tone_pts[1]; |
| 119 | |
| 120 | for (pt = 0; pt < 12; pt += 2) { |
| 121 | if (tone_pts[pt] == -1) { |
| 122 | tone_pts[pt] = N_TONE_ADJUSTcxx . . $ `external/espeak/voice.h:79:10`!*8; |
| 123 | if (pt > 0) |
| 124 | tone_pts[pt+1] = tone_pts[pt-1]; |
| 125 | } |
| 126 | int freq2; |
| 127 | int height2; |
| 128 | |
| 129 | freq2 = tone_pts[pt] / 8; // 8Hz steps |
| 130 | height2 = tone_pts[pt+1]; |
| 131 | if ((freq2 - freq1) > 0) { |
| 132 | for (ix = freq1; ix < freq2; ix++) { |
| 133 | y = height1 + (int)((ix-freq1) * (height2-height1) / (freq2-freq1)); |
| 134 | if (y > 255) |
| 135 | y = 255; |
| 136 | voicet->tone_adjust[ix] = y; |
| 137 | } |
| 138 | } |
| 139 | freq1 = freq2; |
| 140 | height1 = height2; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void ReadTonePointscxx . . $ ReadTonePoints(56561451ddc58846).(char *string, int *tone_pts) |
| 145 | { |
| 146 | // tone_pts[] is int[12] |
| 147 | int ix; |
| 148 | |
| 149 | for (ix = 0; ix < 12; ix++) |
| 150 | tone_pts[ix] = -1; |
| 151 | |
| 152 | sscanf(string, "%d %d %d %d %d %d %d %d %d %d", |
| 153 | &tone_pts[0], &tone_pts[1], &tone_pts[2], &tone_pts[3], |
| 154 | &tone_pts[4], &tone_pts[5], &tone_pts[6], &tone_pts[7], |
| 155 | &tone_pts[8], &tone_pts[9]); |
| 156 | } |
| 157 | |
| 158 | espeak_VOICEcxx . . $ espeak_VOICE# *ReadVoiceFilecxx . . $ ReadVoiceFile(a5e6870cc86b1ca7).(FileInMemorycxx . . $ FileInMemory# f_in, const char *fname, int is_language_file) |
| 159 | { |
| 160 | // Read a Voice file, allocate a VOICE_DATA and set data from the |
| 161 | // file's language, gender, name lines |
| 162 | |
| 163 | char linebuf[120]; |
| 164 | char vname[80]; |
| 165 | char vgender[80]; |
| 166 | char vlanguage[80]; |
| 167 | char languages[300]; // allow space for several alternate language names and priorities |
| 168 | |
| 169 | unsigned int len; |
| 170 | int langix = 0; |
| 171 | int n_languages = 0; |
| 172 | char *p; |
| 173 | espeak_VOICEcxx . . $ espeak_VOICE# *voice_data; |
| 174 | int priority; |
| 175 | int age; |
| 176 | int n_variants = 4; // default, number of variants of this voice before using another voice |
| 177 | int gender; |
| 178 | |
| 179 | vname[0] = 0; |
| 180 | vgender[0] = 0; |
| 181 | age = 0; |
| 182 | |
| 183 | while (fgets_stripcxx . . $ fgets_strip(8f279ba863457a36).(linebuf, sizeof(linebuf), f_in) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 184 | // isolate the attribute name |
| 185 | for (p = linebuf; (*p != 0) && !iswspace_portable(*p); p++) ; |
| 186 | *p++ = 0; |
| 187 | |
| 188 | if (linebuf[0] == 0) continue; |
| 189 | |
| 190 | switch ((VOICELANGATTRIBUTES) LookupMnem(keyword_tab, linebuf)) |
| 191 | { |
| 192 | case V_NAME: |
| 193 | while (isspace(*p)) p++; |
| 194 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(vname, p, sizeof(vname)); |
| 195 | break; |
| 196 | case V_LANGUAGE: |
| 197 | priority = DEFAULT_LANGUAGE_PRIORITYcxx . . $ `external/espeak/voices.cpp:72:9`!; |
| 198 | vlanguage[0] = 0; |
| 199 | |
| 200 | sscanf(p, "%s %d", vlanguage, &priority); |
| 201 | len = strlen(vlanguage) + 2; |
| 202 | // check for space in languages[] |
| 203 | if (len < (sizeof(languages)-langix-1)) { |
| 204 | languages[langix] = priority; |
| 205 | |
| 206 | strcpy(&languages[langix+1], vlanguage); |
| 207 | langix += len; |
| 208 | n_languages++; |
| 209 | } |
| 210 | break; |
| 211 | case V_GENDER: |
| 212 | sscanf(p, "%s %d", vgender, &age); |
| 213 | if (is_language_file) |
| 214 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Error (%s): gender attribute specified on a language file\n", fname); |
| 215 | break; |
| 216 | case V_VARIANTS: |
| 217 | sscanf(p, "%d", &n_variants); |
| 218 | } |
| 219 | } |
| 220 | languages[langix++] = 0; |
| 221 | |
| 222 | gender = LookupMnem(genderscxx . . $ genders., vgender); |
| 223 | |
| 224 | if (n_languages == 0) |
| 225 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; // no language lines in the voice file |
| 226 | |
| 227 | p = (char *)calloccxx . . $ calloc(95acc9b79bb49189).(sizeof(espeak_VOICEcxx . . $ espeak_VOICE#) + langix + strlen(fname) + strlen(vname) + 3, 1); |
| 228 | voice_data = (espeak_VOICEcxx . . $ espeak_VOICE# *)p; |
| 229 | p = &p[sizeof(espeak_VOICEcxx . . $ espeak_VOICE#)]; |
| 230 | |
| 231 | memcpy(p, languages, langix); |
| 232 | voice_data->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. = p; |
| 233 | |
| 234 | strcpy(&p[langix], fname); |
| 235 | voice_data->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier. = &p[langix]; |
| 236 | voice_data->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. = &p[langix]; |
| 237 | |
| 238 | if (vname[0] != 0) { |
| 239 | langix += strlen(fname)+1; |
| 240 | strcpy(&p[langix], vname); |
| 241 | voice_data->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. = &p[langix]; |
| 242 | } |
| 243 | |
| 244 | voice_data->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. = age; |
| 245 | voice_data->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. = gender; |
| 246 | voice_data->variantcxx . . $ $anonymous_type_6337c0e5abb454c9_8#variant. = 0; |
| 247 | voice_data->xx1cxx . . $ $anonymous_type_6337c0e5abb454c9_8#xx1. = n_variants; |
| 248 | return voice_data; |
| 249 | } |
| 250 | |
| 251 | void VoiceResetcxx . . $ VoiceReset(d4f767463ce0a6b3).(int tone_only) |
| 252 | { |
| 253 | // Set voice to the default values |
| 254 | |
| 255 | int pk; |
| 256 | static const unsigned char default_heights[N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!] = { 130, 128, 120, 116, 100, 100, 128, 128, 128 }; // changed for v.1.47 |
| 257 | static const unsigned char default_widths[N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!] = { 140, 128, 128, 160, 171, 171, 128, 128, 128 }; |
| 258 | |
| 259 | static const int breath_widths[N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!] = { 0, 200, 200, 400, 400, 400, 600, 600, 600 }; |
| 260 | |
| 261 | // default is: pitch 80,118 |
| 262 | voicecxx . . $ voice.->pitch_base = 0x47000; |
| 263 | voicecxx . . $ voice.->pitch_range = 4104; |
| 264 | |
| 265 | voicecxx . . $ voice.->formant_factor = 256; |
| 266 | |
| 267 | voicecxx . . $ voice.->speed_percent = 100; |
| 268 | voicecxx . . $ voice.->echo_delay = 0; |
| 269 | voicecxx . . $ voice.->echo_amp = 0; |
| 270 | voicecxx . . $ voice.->flutter = 64; |
| 271 | voicecxx . . $ voice.->n_harmonic_peaks = 5; |
| 272 | voicecxx . . $ voice.->peak_shape = 0; |
| 273 | voicecxx . . $ voice.->voicing = 64; |
| 274 | voicecxx . . $ voice.->consonant_amp = 90; // change from 100 to 90 for v.1.47 |
| 275 | voicecxx . . $ voice.->consonant_ampv = 100; |
| 276 | voicecxx . . $ voice.->samplerate = samplerate; |
| 277 | memset(voicecxx . . $ voice.->klattv, 0, sizeof(voicecxx . . $ voice.->klattv)); |
| 278 | |
| 279 | speed.fast_settings = espeakRATE_MAXIMUMcxx . . $ `external/espeak/speak_lib.h:84:9`!; |
| 280 | |
| 281 | voicecxx . . $ voice.->roughness = 2; |
| 282 | |
| 283 | InitBreath(); |
| 284 | for (pk = 0; pk < N_PEAKScxx . . $ `external/espeak/voice.h:35:9`!; pk++) { |
| 285 | voicecxx . . $ voice.->freq[pk] = 256; |
| 286 | voicecxx . . $ voice.->freq2[pk] = voicecxx . . $ voice.->freq[pk]; |
| 287 | voicecxx . . $ voice.->height[pk] = default_heights[pk]*2; |
| 288 | voicecxx . . $ voice.->height2[pk] = voicecxx . . $ voice.->height[pk]; |
| 289 | voicecxx . . $ voice.->width[pk] = default_widths[pk]*2; |
| 290 | voicecxx . . $ voice.->breath[pk] = 0; |
| 291 | voicecxx . . $ voice.->breathw[pk] = breath_widths[pk]; // default breath formant widths |
| 292 | voicecxx . . $ voice.->freqadd[pk] = 0; |
| 293 | |
| 294 | // adjust formant smoothing depending on sample rate |
| 295 | formant_ratecxx . . $ formant_rate.[pk] = (formant_rate_22050cxx . . $ formant_rate_22050.[pk] * 22050)/samplerate; |
| 296 | } |
| 297 | |
| 298 | // This table provides the opportunity for tone control. |
| 299 | // Adjustment of harmonic amplitudes, steps of 8Hz |
| 300 | // value of 128 means no change |
| 301 | SetToneAdjustcxx . . $ SetToneAdjust(b925784a8612db61).(voicecxx . . $ voice., tone_pointscxx . . $ tone_points.); |
| 302 | |
| 303 | // default values of speed factors |
| 304 | voicecxx . . $ voice.->speedf1 = 256; |
| 305 | voicecxx . . $ voice.->speedf2 = 238; |
| 306 | voicecxx . . $ voice.->speedf3 = 232; |
| 307 | |
| 308 | if (tone_only == 0) { |
| 309 | n_replace_phonemes = 0; |
| 310 | #if USE_MBROLAcxx . . $ `external/espeak/espeak__config.h:18:9`! |
| 311 | LoadMbrolaTable(NULL, NULL, 0); |
| 312 | #endif |
| 313 | } |
| 314 | |
| 315 | // probably unnecessary, but removing this would break tests |
| 316 | voicecxx . . $ voice.->width[0] = (voicecxx . . $ voice.->width[0] * 105)/100; |
| 317 | } |
| 318 | |
| 319 | static void VoiceFormantcxx . . $ VoiceFormant(fda57c8427c60377).(char *p) |
| 320 | { |
| 321 | // Set parameters for a formant |
| 322 | int ix; |
| 323 | int formant; |
| 324 | int freq = 100; |
| 325 | int height = 100; |
| 326 | int width = 100; |
| 327 | int freqadd = 0; |
| 328 | |
| 329 | ix = sscanf(p, "%d %d %d %d %d", &formant, &freq, &height, &width, &freqadd); |
| 330 | if (ix < 2) |
| 331 | return; |
| 332 | |
| 333 | if ((formant < 0) || (formant > 8)) |
| 334 | return; |
| 335 | |
| 336 | if (freq >= 0) { |
| 337 | voicecxx . . $ voice.->freq[formant] = (int)(freq * 2.56001); |
| 338 | voicecxx . . $ voice.->freq2[formant] = voicecxx . . $ voice.->freq[formant]; |
| 339 | } |
| 340 | if (height >= 0) { |
| 341 | voicecxx . . $ voice.->height[formant] = (int)(height * 2.56001); |
| 342 | voicecxx . . $ voice.->height2[formant] = voicecxx . . $ voice.->height[formant]; |
| 343 | } |
| 344 | if (width >= 0) |
| 345 | voicecxx . . $ voice.->width[formant] = (int)(width * 2.56001); |
| 346 | voicecxx . . $ voice.->freqadd[formant] = freqadd; |
| 347 | |
| 348 | // probably unnecessary, but removing this would break tests |
| 349 | if (formant == 0) |
| 350 | voicecxx . . $ voice.->width[0] = (voicecxx . . $ voice.->width[0] * 105)/100; |
| 351 | } |
| 352 | |
| 353 | static void PhonemeReplacementcxx . . $ PhonemeReplacement(fda57c8427c60377).(char *p) |
| 354 | { |
| 355 | int n; |
| 356 | int phon; |
| 357 | int flags = 0; |
| 358 | char phon_string1[12]; |
| 359 | char phon_string2[12]; |
| 360 | |
| 361 | strcpy(phon_string2, "NULL"); |
| 362 | n = sscanf(p, "%d %s %s", &flags, phon_string1, phon_string2); |
| 363 | if ((n < 2) || (n_replace_phonemes >= N_REPLACE_PHONEMEScxx . . $ `external/espeak/phoneme.h:262:9`!)) |
| 364 | return; |
| 365 | |
| 366 | if ((phon = LookupPhonemeString(phon_string1)) == 0) |
| 367 | return; // not recognised |
| 368 | |
| 369 | replace_phonemes[n_replace_phonemes].old_ph = phon; |
| 370 | replace_phonemes[n_replace_phonemes].new_ph = LookupPhonemeString(phon_string2); |
| 371 | replace_phonemes[n_replace_phonemes++].type = flags; |
| 372 | } |
| 373 | |
| 374 | int Read8Numberscxx . . $ Read8Numbers(b0a0d720b596a511).(char *data_in, int data[8]) |
| 375 | { |
| 376 | // Read 8 integer numbers |
| 377 | memset(data, 0, 8*sizeof(int)); |
| 378 | return sscanf(data_in, "%d %d %d %d %d %d %d %d", |
| 379 | &data[0], &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], &data[7]); |
| 380 | } |
| 381 | |
| 382 | void ReadNumberscxx . . $ ReadNumbers(b9a25e77a2f4993b).(char *p, int *flags, int maxValue, const MNEM_TAB *keyword_table, int key) { |
| 383 | // read a list of numbers from string p |
| 384 | // store them as flags in *flags |
| 385 | // the meaning of the numbers is bit ordinals, not integer values |
| 386 | // give an error if number > maxValue is read |
| 387 | while (*p != 0) { |
| 388 | while (isspace(*p)) p++; |
| 389 | int n; |
| 390 | if ((n = atoicxx . . $ atoi(f5ecf3191ed0cd93).(p)) > 0) { |
| 391 | p++; |
| 392 | if (n < maxValue) { |
| 393 | *flags |= (1 << n); |
| 394 | } else { |
| 395 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "%s: Bad option number %d\n", LookupMnemName(keyword_table, key), n); |
| 396 | } |
| 397 | } |
| 398 | while (isalnum(*p)) p++; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | voice_t *LoadVoicecxx . . $ LoadVoice(7a9427dcaeff0687).(const char *vname, int control) |
| 403 | { |
| 404 | // control, bit 0 1= no_default |
| 405 | // bit 1 1 = change tone only, not language |
| 406 | // bit 2 1 = don't report error on LoadDictionary |
| 407 | // bit 4 1 = vname = full path |
| 408 | // bit 8 1 = INTERNAL: compiling phonemes; do not try to |
| 409 | // load the phoneme table |
| 410 | // bit 16 1 = UNDOCUMENTED |
| 411 | |
| 412 | //TRACE |
| 413 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"enter"); |
| 414 | FileInMemorycxx . . $ FileInMemory# f_voice = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 415 | char *p; |
| 416 | int key; |
| 417 | int ix; |
| 418 | int value; |
| 419 | int langix = 0; |
| 420 | int tone_only = control & 2; |
| 421 | bool language_set = false; |
| 422 | bool phonemes_set = false; |
| 423 | |
| 424 | char voicename[40]; |
| 425 | char language_name[40]; |
| 426 | char translator_name[40]; |
| 427 | char new_dictionary[40]; |
| 428 | char phonemes_name[40] = ""; |
| 429 | const char *language_type; |
| 430 | char buf[sizeof(path_home)+30]; |
| 431 | #if USE_MBROLAcxx . . $ `external/espeak/espeak__config.h:18:9`! |
| 432 | char name1[40]; |
| 433 | char name2[80]; |
| 434 | #endif |
| 435 | |
| 436 | int pitch1; |
| 437 | int pitch2; |
| 438 | |
| 439 | static char voice_identifier[40]; // file name for current_voice_selected |
| 440 | static char voice_name[40]; // voice name for current_voice_selected |
| 441 | static char voice_languages[100]; // list of languages and priorities for current_voice_selected |
| 442 | |
| 443 | if (!tone_only) { |
| 444 | MAKE_MEM_UNDEFINEDcxx . . $ `external/espeak/speech.h:39:13`!(&voice_identifier, sizeof(voice_identifier)); |
| 445 | MAKE_MEM_UNDEFINEDcxx . . $ `external/espeak/speech.h:39:13`!(&voice_name, sizeof(voice_name)); |
| 446 | MAKE_MEM_UNDEFINEDcxx . . $ `external/espeak/speech.h:39:13`!(&voice_languages, sizeof(voice_languages)); |
| 447 | } |
| 448 | |
| 449 | if ((vname == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || vname[0] == 0) && !(control & 8)) { |
| 450 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 451 | } |
| 452 | |
| 453 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"strncpy0... ", control, U" ", Melder_peek8to32_u (vname), U"."); |
| 454 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(voicename, vname, sizeof(voicename)); |
| 455 | if (control & 0x10) { |
| 456 | strcpy(buf, vname); |
| 457 | if (GetFileLengthcxx . . $ GetFileLength(5c4306d8553b3696).(buf) <= 0) |
| 458 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 459 | } else { |
| 460 | if (voicename[0] == 0 && !(control & 8)/*compiling phonemes*/) |
| 461 | strcpy(voicename, ESPEAKNG_DEFAULT_VOICEcxx . . $ `external/espeak/espeak_ng.h:39:9`!); |
| 462 | |
| 463 | char path_voices[sizeof(path_home)+12]; |
| 464 | sprintf(path_voices, "%s%cvoices%c", path_home, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!); |
| 465 | sprintf(buf, "%s%s", path_voices, voicename); // look in the main voices directory |
| 466 | |
| 467 | if (GetFileLengthcxx . . $ GetFileLength(5c4306d8553b3696).(buf) <= 0) { |
| 468 | sprintf(path_voices, "%s%clang%c", path_home, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!); |
| 469 | sprintf(buf, "%s%s", path_voices, voicename); // look in the main languages directory |
| 470 | } |
| 471 | } |
| 472 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"opening... ", Melder_peek8to32_u (buf), U"."); |
| 473 | |
| 474 | f_voice = FileInMemorySet_fopencxx . . $ FileInMemorySet_fopen(3c6da2b95de6d644).(theEspeakPraatFileInMemorySetcxx . . $ theEspeakPraatFileInMemorySet(e171e0b8438add33).(), buf, "r"); |
| 475 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"opened"); |
| 476 | |
| 477 | if (!(control & 8)/*compiling phonemes*/) |
| 478 | language_type = ESPEAKNG_DEFAULT_VOICEcxx . . $ `external/espeak/espeak_ng.h:39:9`!; // default |
| 479 | else |
| 480 | language_type = ""; |
| 481 | |
| 482 | if (f_voice == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 483 | if (control & 3) |
| 484 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; // can't open file |
| 485 | |
| 486 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"selecting phoneme table... ", Melder_peek8to32_u (voicename), U"."); |
| 487 | if (SelectPhonemeTableName(voicename) >= 0) |
| 488 | language_type = voicename; |
| 489 | } |
| 490 | |
| 491 | if (!tone_only && (translator != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)) { |
| 492 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"deleting translator... "); |
| 493 | DeleteTranslator(translator); |
| 494 | translator = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 495 | } |
| 496 | |
| 497 | strcpy(translator_name, language_type); |
| 498 | strcpy(new_dictionary, language_type); |
| 499 | |
| 500 | if (!tone_only) { |
| 501 | voicecxx . . $ voice. = &voicedatacxx . . $ voicedata.; |
| 502 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"strncpy0... ", Melder_peek8to32_u (vname), U"."); |
| 503 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(voice_identifier, vname, sizeof(voice_identifier)); |
| 504 | voice_name[0] = 0; |
| 505 | voice_languages[0] = 0; |
| 506 | |
| 507 | current_voice_selectedcxx . . $ current_voice_selected..identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier. = voice_identifier; |
| 508 | current_voice_selectedcxx . . $ current_voice_selected..namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. = voice_name; |
| 509 | current_voice_selectedcxx . . $ current_voice_selected..languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. = voice_languages; |
| 510 | } else { |
| 511 | // append the variant file name to the voice identifier |
| 512 | if ((p = strchr(voice_identifier, '+')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 513 | *p = 0; // remove previous variant name |
| 514 | sprintf(buf, "+%s", &vname[3]); // omit !v/ from the variant filename |
| 515 | strcat(voice_identifier, buf); |
| 516 | } |
| 517 | VoiceResetcxx . . $ VoiceReset(d4f767463ce0a6b3).(tone_only); |
| 518 | |
| 519 | while ((f_voice != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && (fgets_stripcxx . . $ fgets_strip(8f279ba863457a36).(buf, sizeof(buf), f_voice) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)) { |
| 520 | // isolate the attribute name |
| 521 | for (p = buf; (*p != 0) && !isspace(*p); p++) ; |
| 522 | *p++ = 0; |
| 523 | |
| 524 | if (buf[0] == 0) continue; |
| 525 | |
| 526 | key = LookupMnem(langopts_tab, buf); |
| 527 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"key ", key); |
| 528 | |
| 529 | if (key != 0) { |
| 530 | LoadLanguageOptions(translator, key, p); |
| 531 | } else { |
| 532 | key = LookupMnem(keyword_tab, buf); |
| 533 | switch (key) |
| 534 | { |
| 535 | case V_LANGUAGE: |
| 536 | { |
| 537 | unsigned int len; |
| 538 | int priority; |
| 539 | |
| 540 | if (tone_only) |
| 541 | break; |
| 542 | |
| 543 | priority = DEFAULT_LANGUAGE_PRIORITYcxx . . $ `external/espeak/voices.cpp:72:9`!; |
| 544 | language_name[0] = 0; |
| 545 | |
| 546 | sscanf(p, "%s %d", language_name, &priority); |
| 547 | if (strcmp(language_name, "variant") == 0) |
| 548 | break; |
| 549 | |
| 550 | len = strlen(language_name) + 2; |
| 551 | // check for space in languages[] |
| 552 | if (len < (sizeof(voice_languages)-langix-1)) { |
| 553 | voice_languages[langix] = priority; |
| 554 | |
| 555 | strcpy(&voice_languages[langix+1], language_name); |
| 556 | langix += len; |
| 557 | } |
| 558 | |
| 559 | // only act on the first language line |
| 560 | if (language_set == false) { |
| 561 | language_type = strtok(language_name, "-"); |
| 562 | language_set = true; |
| 563 | strcpy(translator_name, language_type); |
| 564 | strcpy(new_dictionary, language_type); |
| 565 | strcpy(phonemes_name, language_type); |
| 566 | SelectPhonemeTableName(phonemes_name); |
| 567 | |
| 568 | translator = SelectTranslator(translator_name); |
| 569 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(voicecxx . . $ voice.->language_name, language_name, sizeof(voicecxx . . $ voice.->language_name)); |
| 570 | } |
| 571 | } |
| 572 | break; |
| 573 | case V_NAME: |
| 574 | if (tone_only == 0) { |
| 575 | while (isspace(*p)) p++; |
| 576 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(voice_name, p, sizeof(voice_name)); |
| 577 | } |
| 578 | break; |
| 579 | case V_GENDER: |
| 580 | { |
| 581 | int age = 0; |
| 582 | char vgender[80]; |
| 583 | sscanf(p, "%s %d", vgender, &age); |
| 584 | current_voice_selectedcxx . . $ current_voice_selected..gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. = LookupMnem(genderscxx . . $ genders., vgender); |
| 585 | current_voice_selectedcxx . . $ current_voice_selected..agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. = age; |
| 586 | } |
| 587 | break; |
| 588 | case V_DICTIONARY: // dictionary |
| 589 | sscanf(p, "%s", new_dictionary); |
| 590 | break; |
| 591 | case V_PHONEMES: // phoneme table |
| 592 | sscanf(p, "%s", phonemes_name); |
| 593 | break; |
| 594 | case V_FORMANT: |
| 595 | VoiceFormantcxx . . $ VoiceFormant(fda57c8427c60377).(p); |
| 596 | break; |
| 597 | case V_PITCH: |
| 598 | // default is pitch 82 118 |
| 599 | if (sscanf(p, "%d %d", &pitch1, &pitch2) == 2) { |
| 600 | voicecxx . . $ voice.->pitch_base = (pitch1 - 9) << 12; |
| 601 | voicecxx . . $ voice.->pitch_range = (pitch2 - pitch1) * 108; |
| 602 | double factor = (double)(pitch1 - 82)/82; |
| 603 | voicecxx . . $ voice.->formant_factor = (int)((1+factor/4) * 256); // nominal formant shift for a different voice pitch |
| 604 | } |
| 605 | break; |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | case V_REPLACE: |
| 612 | if (phonemes_set == false) { |
| 613 | // must set up a phoneme table before we can lookup phoneme mnemonics |
| 614 | SelectPhonemeTableName(phonemes_name); |
| 615 | phonemes_set = true; |
| 616 | } |
| 617 | PhonemeReplacementcxx . . $ PhonemeReplacement(fda57c8427c60377).(p); |
| 618 | break; |
| 619 | |
| 620 | case V_ECHO: |
| 621 | // echo. suggest: 135mS 11% |
| 622 | value = 0; |
| 623 | voicecxx . . $ voice.->echo_amp = 0; |
| 624 | sscanf(p, "%d %d", &voicecxx . . $ voice.->echo_delay, &voicecxx . . $ voice.->echo_amp); |
| 625 | break; |
| 626 | case V_FLUTTER: // flutter |
| 627 | if (sscanf(p, "%d", &value) == 1) |
| 628 | voicecxx . . $ voice.->flutter = value * 32; |
| 629 | break; |
| 630 | case V_ROUGHNESS: // roughness |
| 631 | if (sscanf(p, "%d", &value) == 1) |
| 632 | voicecxx . . $ voice.->roughness = value; |
| 633 | break; |
| 634 | case V_CLARITY: // formantshape |
| 635 | if (sscanf(p, "%d", &value) == 1) { |
| 636 | if (value > 4) { |
| 637 | voicecxx . . $ voice.->peak_shape = 1; // squarer formant peaks |
| 638 | value = 4; |
| 639 | } |
| 640 | voicecxx . . $ voice.->n_harmonic_peaks = 1+value; |
| 641 | } |
| 642 | break; |
| 643 | case V_TONE: |
| 644 | { |
| 645 | int tone_data[12]; |
| 646 | ReadTonePointscxx . . $ ReadTonePoints(56561451ddc58846).(p, tone_data); |
| 647 | SetToneAdjustcxx . . $ SetToneAdjust(b925784a8612db61).(voicecxx . . $ voice., tone_data); |
| 648 | } |
| 649 | break; |
| 650 | case V_VOICING: |
| 651 | if (sscanf(p, "%d", &value) == 1) |
| 652 | voicecxx . . $ voice.->voicing = (value * 64)/100; |
| 653 | break; |
| 654 | case V_BREATH: |
| 655 | voicecxx . . $ voice.->breath[0] = Read8Numberscxx . . $ Read8Numbers(b0a0d720b596a511).(p, &voicecxx . . $ voice.->breath[1]); |
| 656 | for (ix = 1; ix < 8; ix++) { |
| 657 | if (ix % 2) |
| 658 | voicecxx . . $ voice.->breath[ix] = -voicecxx . . $ voice.->breath[ix]; |
| 659 | } |
| 660 | break; |
| 661 | case V_BREATHW: |
| 662 | voicecxx . . $ voice.->breathw[0] = Read8Numberscxx . . $ Read8Numbers(b0a0d720b596a511).(p, &voicecxx . . $ voice.->breathw[1]); |
| 663 | break; |
| 664 | case V_CONSONANTS: |
| 665 | value = sscanf(p, "%d %d", &voicecxx . . $ voice.->consonant_amp, &voicecxx . . $ voice.->consonant_ampv); |
| 666 | break; |
| 667 | case V_SPEED: |
| 668 | sscanf(p, "%d", &voicecxx . . $ voice.->speed_percent); |
| 669 | SetSpeed(3); |
| 670 | break; |
| 671 | #if USE_MBROLAcxx . . $ `external/espeak/espeak__config.h:18:9`! |
| 672 | case V_MBROLA: |
| 673 | { |
| 674 | int srate = 16000; |
| 675 | |
| 676 | name2[0] = 0; |
| 677 | sscanf(p, "%s %s %d", name1, name2, &srate); |
| 678 | espeak_ng_STATUS status = LoadMbrolaTable(name1, name2, &srate); |
| 679 | if (status != ENS_OK) { |
| 680 | espeak_ng_PrintStatusCodeMessage(status, stderr, NULL); |
| 681 | FileInMemory_fclose(f_voice); |
| 682 | return NULL; |
| 683 | } |
| 684 | else |
| 685 | voice->samplerate = srate; |
| 686 | } |
| 687 | break; |
| 688 | #endif |
| 689 | #if USE_KLATTcxx . . $ `external/espeak/espeak__config.h:17:9`! |
| 690 | case V_KLATT: |
| 691 | voicecxx . . $ voice.->klattv[0] = 1; // default source: IMPULSIVE |
| 692 | Read8Numberscxx . . $ Read8Numbers(b0a0d720b596a511).(p, voicecxx . . $ voice.->klattv); |
| 693 | voicecxx . . $ voice.->klattv[KLATT_Kopencxx . . $ `external/espeak/synthesize.h:90:9`!] -= 40; |
| 694 | break; |
| 695 | #endif |
| 696 | case V_FAST: |
| 697 | sscanf(p, "%d", &speed.fast_settings); |
| 698 | SetSpeed(3); |
| 699 | break; |
| 700 | |
| 701 | case V_MAINTAINER: |
| 702 | case V_STATUS: |
| 703 | break; |
| 704 | default: |
| 705 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Bad voice attribute: %s\n", buf); |
| 706 | break; |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"closing..."); |
| 711 | if (f_voice != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 712 | FileInMemory_fclosecxx . . $ FileInMemory_fclose(18557d97a31d1c3b).(f_voice); |
| 713 | |
| 714 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"selecting translator... ", Melder_pointer (translator), U" ", tone_only, U" ", sizeof (Translator)); |
| 715 | if ((translator == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && (!tone_only)) { |
| 716 | // not set by language attribute |
| 717 | translator = SelectTranslator(translator_name); |
| 718 | } |
| 719 | |
| 720 | if (!tone_only) { |
| 721 | if (!!(control & 8/*compiling phonemes*/)) { |
| 722 | /* Set by espeak_ng_CompilePhonemeDataPath when it |
| 723 | * calls LoadVoice("", 8) to set up a dummy(?) voice. |
| 724 | * As phontab may not yet exist this avoids the spurious |
| 725 | * error message and guarantees consistent results by |
| 726 | * not actually reading a potentially bogus phontab... |
| 727 | */ |
| 728 | ix = 0; |
| 729 | } else if ((ix = SelectPhonemeTableName(phonemes_name)) < 0) { |
| 730 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Unknown phoneme table: '%s'\n", phonemes_name); |
| 731 | ix = 0; |
| 732 | } |
| 733 | |
| 734 | voicecxx . . $ voice.->phoneme_tab_ix = ix; |
| 735 | translator->phoneme_tab_ix = ix; |
| 736 | |
| 737 | if (!(control & 8/*compiling phonemes*/)) { |
| 738 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Loading dictionary..."); |
| 739 | LoadDictionary(translator, new_dictionary, control & 4); |
| 740 | if (dictionary_name[0] == 0) { |
| 741 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Deleting translator..."); |
| 742 | DeleteTranslator(translator); |
| 743 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; // no dictionary loaded |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | /* Terminate languages list with a zero-priority entry */ |
| 748 | voice_languages[langix] = 0; |
| 749 | } |
| 750 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"return"); |
| 751 | |
| 752 | return voicecxx . . $ voice.; |
| 753 | } |
| 754 | |
| 755 | static char *ExtractVoiceVariantNamecxx . . $ ExtractVoiceVariantName(75f8fb248a90efb7).(char *vname, int variant_num, int add_dir) |
| 756 | { |
| 757 | // Remove any voice variant suffix (name or number) from a voice name |
| 758 | // Returns the voice variant name |
| 759 | |
| 760 | static char variant_name[40]; |
| 761 | char variant_prefix[5]; |
| 762 | |
| 763 | MAKE_MEM_UNDEFINEDcxx . . $ `external/espeak/speech.h:39:13`!(&variant_name, sizeof(variant_name)); |
| 764 | variant_name[0] = 0; |
| 765 | sprintf(variant_prefix, "!v%c", PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!); |
| 766 | if (add_dir == 0) |
| 767 | variant_prefix[0] = 0; |
| 768 | |
| 769 | if (vname != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 770 | char *p; |
| 771 | if ((p = strchr(vname, '+')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 772 | // The voice name has a +variant suffix |
| 773 | variant_num = 0; |
| 774 | *p++ = 0; // delete the suffix from the voice name |
| 775 | if (IsDigit09cxx . . $ IsDigit09(4c679297bf94b9eb).(*p)) |
| 776 | variant_num = atoicxx . . $ atoi(f5ecf3191ed0cd93).(p); // variant number |
| 777 | else { |
| 778 | // voice variant name, not number |
| 779 | sprintf(variant_name, "%s%s", variant_prefix, p); |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | if (variant_num > 0) { |
| 785 | if (variant_num < 10) |
| 786 | sprintf(variant_name, "%sm%d", variant_prefix, variant_num); // male |
| 787 | else |
| 788 | sprintf(variant_name, "%sf%d", variant_prefix, variant_num-10); // female |
| 789 | } |
| 790 | |
| 791 | return variant_name; |
| 792 | } |
| 793 | |
| 794 | voice_t *LoadVoiceVariantcxx . . $ LoadVoiceVariant(7a9427dcaeff0687).(const char *vname, int variant_num) |
| 795 | { |
| 796 | // Load a voice file. |
| 797 | // Also apply a voice variant if specified by "variant", or by "+number" or "+name" in the "vname" |
| 798 | |
| 799 | voice_t *v; |
| 800 | char *variant_name; |
| 801 | char buf[60]; |
| 802 | |
| 803 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buf, vname, sizeof(buf)); |
| 804 | variant_name = ExtractVoiceVariantNamecxx . . $ ExtractVoiceVariantName(75f8fb248a90efb7).(buf, variant_num, 1); |
| 805 | |
| 806 | if ((v = LoadVoicecxx . . $ LoadVoice(7a9427dcaeff0687).(buf, 0)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 807 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 808 | |
| 809 | if (variant_name[0] != 0) |
| 810 | v = LoadVoicecxx . . $ LoadVoice(7a9427dcaeff0687).(variant_name, 2); |
| 811 | return v; |
| 812 | } |
| 813 | |
| 814 | static int __cdeclcxx . . $ `external/espeak/speech.h:74:9`! VoiceNameSortercxx . . $ VoiceNameSorter(9148c8c3ff42c9d8).(const void *p1, const void *p2) |
| 815 | { |
| 816 | int ix; |
| 817 | espeak_VOICEcxx . . $ espeak_VOICE# *v1 = *(espeak_VOICEcxx . . $ espeak_VOICE# **)p1; |
| 818 | espeak_VOICEcxx . . $ espeak_VOICE# *v2 = *(espeak_VOICEcxx . . $ espeak_VOICE# **)p2; |
| 819 | |
| 820 | if ((ix = strcmp(&v1->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[1], &v2->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[1])) != 0) // primary language name |
| 821 | return ix; |
| 822 | if ((ix = v1->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[0] - v2->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[0]) != 0) // priority number |
| 823 | return ix; |
| 824 | return strcmp(v1->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name., v2->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name.); |
| 825 | } |
| 826 | |
| 827 | static int __cdeclcxx . . $ `external/espeak/speech.h:74:9`! VoiceScoreSortercxx . . $ VoiceScoreSorter(9148c8c3ff42c9d8).(const void *p1, const void *p2) |
| 828 | { |
| 829 | int ix; |
| 830 | espeak_VOICEcxx . . $ espeak_VOICE# *v1 = *(espeak_VOICEcxx . . $ espeak_VOICE# **)p1; |
| 831 | espeak_VOICEcxx . . $ espeak_VOICE# *v2 = *(espeak_VOICEcxx . . $ espeak_VOICE# **)p2; |
| 832 | |
| 833 | if ((ix = v2->scorecxx . . $ $anonymous_type_6337c0e5abb454c9_8#score. - v1->scorecxx . . $ $anonymous_type_6337c0e5abb454c9_8#score.) != 0) |
| 834 | return ix; |
| 835 | return strcmp(v1->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name., v2->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name.); |
| 836 | } |
| 837 | |
| 838 | static int ScoreVoicecxx . . $ ScoreVoice(500b803fae8fcfa).(espeak_VOICEcxx . . $ espeak_VOICE# *voice_spec, const char *spec_language, int spec_n_parts, int spec_lang_len, espeak_VOICEcxx . . $ espeak_VOICE# *voicet) |
| 839 | { |
| 840 | const char *p; |
| 841 | int score = 0; |
| 842 | int x; |
| 843 | |
| 844 | p = voicet->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.; // list of languages+dialects for which this voice is suitable |
| 845 | |
| 846 | if (spec_n_parts < 0) { |
| 847 | // match on the subdirectory |
| 848 | if (memcmp(voicet->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier., spec_language, spec_lang_len) == 0) |
| 849 | return 100; |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | if (spec_n_parts == 0) |
| 854 | score = 100; |
| 855 | else { |
| 856 | if ((*p == 0) && (strcmp(spec_language, "variants") == 0)) { |
| 857 | // match on a voice with no languages if the required language is "variants" |
| 858 | score = 100; |
| 859 | } |
| 860 | |
| 861 | // compare the required language with each of the languages of this voice |
| 862 | while (*p != 0) { |
| 863 | int language_priority = *p++; |
| 864 | |
| 865 | |
| 866 | int n_parts = 1; |
| 867 | int matching = 1; |
| 868 | int matching_parts = 0; |
| 869 | int ix; |
| 870 | for (ix = 0;; ix++) { |
| 871 | int c1, c2; |
| 872 | if ((ix >= spec_lang_len) || ((c1 = spec_language[ix]) == '-')) |
| 873 | c1 = 0; |
| 874 | if ((c2 = p[ix]) == '-') |
| 875 | c2 = 0; |
| 876 | |
| 877 | if (c1 != c2) |
| 878 | matching = 0; |
| 879 | |
| 880 | if (p[ix] == '-') { |
| 881 | n_parts++; |
| 882 | if (matching) |
| 883 | matching_parts++; |
| 884 | } |
| 885 | if (p[ix] == 0) |
| 886 | break; |
| 887 | } |
| 888 | p += (ix+1); |
| 889 | matching_parts += matching; // number of parts which match |
| 890 | |
| 891 | if (matching_parts == 0) |
| 892 | continue; // no matching parts for this language |
| 893 | |
| 894 | x = 5; |
| 895 | // reduce the score if not all parts of the required language match |
| 896 | int diff; |
| 897 | if ((diff = (spec_n_parts - matching_parts)) > 0) |
| 898 | x -= diff; |
| 899 | |
| 900 | // reduce score if the language is more specific than required |
| 901 | if ((diff = (n_parts - matching_parts)) > 0) |
| 902 | x -= diff; |
| 903 | |
| 904 | x = x*100 - (language_priority * 2); |
| 905 | |
| 906 | if (x > score) |
| 907 | score = x; |
| 908 | } |
| 909 | } |
| 910 | if (score == 0) |
| 911 | return 0; |
| 912 | |
| 913 | if (voice_spec->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 914 | if (strcmp(voice_spec->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name., voicet->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name.) == 0) { |
| 915 | // match on voice name |
| 916 | score += 500; |
| 917 | } else if (strcmp(voice_spec->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name., voicet->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier.) == 0) |
| 918 | score += 400; |
| 919 | } |
| 920 | |
| 921 | if (((voice_spec->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_MALE) || (voice_spec->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_FEMALE)) && |
| 922 | ((voicet->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_MALE) || (voicet->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_FEMALE))) { |
| 923 | if (voice_spec->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == voicet->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender.) |
| 924 | score += 50; |
| 925 | else |
| 926 | score -= 50; |
| 927 | } |
| 928 | |
| 929 | if ((voice_spec->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. <= 12) && (voicet->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_FEMALE) && (voicet->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. > 12)) |
| 930 | score += 5; // give some preference for non-child female voice if a child is requested |
| 931 | |
| 932 | if (voicet->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. != 0) { |
| 933 | int required_age; |
| 934 | if (voice_spec->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. == 0) |
| 935 | required_age = 30; |
| 936 | else |
| 937 | required_age = voice_spec->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age.; |
| 938 | |
| 939 | int ratio; |
| 940 | ratio = (required_age*100)/voicet->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age.; |
| 941 | if (ratio < 100) |
| 942 | ratio = 10000/ratio; |
| 943 | ratio = (ratio - 100)/10; // 0=exact match, 10=out by factor of 2 |
| 944 | x = 5 - ratio; |
| 945 | if (x > 0) x = 0; |
| 946 | |
| 947 | score = score + x; |
| 948 | |
| 949 | if (voice_spec->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. > 0) |
| 950 | score += 10; // required age specified, favour voices with a specified age (near it) |
| 951 | } |
| 952 | if (score < 1) |
| 953 | score = 1; |
| 954 | return score; |
| 955 | } |
| 956 | |
| 957 | static int SetVoiceScorescxx . . $ SetVoiceScores(a786de115825ad29).(espeak_VOICEcxx . . $ espeak_VOICE# *voice_select, espeak_VOICEcxx . . $ espeak_VOICE# **voices, int control) |
| 958 | { |
| 959 | // control: bit0=1 include mbrola voices |
| 960 | int ix; |
| 961 | int score; |
| 962 | int nv; // number of candidates |
| 963 | int n_parts = 0; |
| 964 | int lang_len = 0; |
| 965 | espeak_VOICEcxx . . $ espeak_VOICE# *vp; |
| 966 | char language[80]; |
| 967 | |
| 968 | // count number of parts in the specified language |
| 969 | if ((voice_select->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && (voice_select->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[0] != 0)) { |
| 970 | n_parts = 1; |
| 971 | lang_len = strlen(voice_select->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.); |
| 972 | for (ix = 0; (ix <= lang_len) && ((unsigned)ix < sizeof(language)); ix++) { |
| 973 | if ((language[ix] = tolower(voice_select->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[ix])) == '-') |
| 974 | n_parts++; |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | if ((n_parts == 1) && (control & 1)) { |
| 979 | if (strcmp(language, "mbrola") == 0) { |
| 980 | language[2] = 0; // truncate to "mb" |
| 981 | lang_len = 2; |
| 982 | } |
| 983 | |
| 984 | char buf[sizeof(path_home)+80]; |
| 985 | sprintf(buf, "%s/voices/%s", path_home, language); |
| 986 | if (GetFileLengthcxx . . $ GetFileLength(5c4306d8553b3696).(buf) == -EISDIRcxx . . $ `<external>/8987895939074593727/errno-base.h:25:9`!) { |
| 987 | // A subdirectory name has been specified. List all the voices in that subdirectory |
| 988 | language[lang_len++] = PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!; |
| 989 | language[lang_len] = 0; |
| 990 | n_parts = -1; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | // select those voices which match the specified language |
| 995 | nv = 0; |
| 996 | for (ix = 0; ix < n_voices_listcxx . . $ n_voices_list.; ix++) { |
| 997 | vp = voices_listcxx . . $ voices_list.[ix]; |
| 998 | |
| 999 | if (((control & 1) == 0) && (memcmp(vp->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier., "mb/", 3) == 0)) |
| 1000 | continue; |
| 1001 | |
| 1002 | if (voice_select->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! || memcmp(voice_select->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.,"all", 3) == 0) { |
| 1003 | voices[nv++] = vp; |
| 1004 | continue; |
| 1005 | } |
| 1006 | |
| 1007 | if ((score = ScoreVoicecxx . . $ ScoreVoice(500b803fae8fcfa).(voice_select, language, n_parts, lang_len, voices_listcxx . . $ voices_list.[ix])) > 0) { |
| 1008 | voices[nv++] = vp; |
| 1009 | vp->scorecxx . . $ $anonymous_type_6337c0e5abb454c9_8#score. = score; |
| 1010 | } |
| 1011 | } |
| 1012 | voices[nv] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; // list terminator |
| 1013 | |
| 1014 | if (nv == 0) |
| 1015 | return 0; |
| 1016 | |
| 1017 | // sort the selected voices by their score |
| 1018 | qsortcxx . . $ qsort(ebb60b13a65e77d7).(voices, nv, sizeof(espeak_VOICEcxx . . $ espeak_VOICE# *), (int(__cdeclcxx . . $ `external/espeak/speech.h:74:9`! *)(const void *, const void *))VoiceScoreSortercxx . . $ VoiceScoreSorter(9148c8c3ff42c9d8).); |
| 1019 | |
| 1020 | return nv; |
| 1021 | } |
| 1022 | |
| 1023 | espeak_VOICEcxx . . $ espeak_VOICE# *SelectVoiceByNamecxx . . $ SelectVoiceByName(735d0e64632a2a26).(espeak_VOICEcxx . . $ espeak_VOICE# **voices, const char *name2) |
| 1024 | { |
| 1025 | int ix; |
| 1026 | int match_fname = -1; |
| 1027 | int match_fname2 = -1; |
| 1028 | int match_name = -1; |
| 1029 | const char *id; // this is the filename within espeak-ng-data/voices |
| 1030 | int last_part_len; |
| 1031 | char last_part[41]; |
| 1032 | char name[40]; |
| 1033 | |
| 1034 | if (voices == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1035 | if (n_voices_listcxx . . $ n_voices_list. == 0) |
| 1036 | espeak_ListVoices(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); // create the voices list |
| 1037 | voices = voices_listcxx . . $ voices_list.; |
| 1038 | } |
| 1039 | |
| 1040 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(name, name2, sizeof(name)); |
| 1041 | |
| 1042 | sprintf(last_part, "%c%s", PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!, name); |
| 1043 | last_part_len = strlen(last_part); |
| 1044 | |
| 1045 | for (ix = 0; voices[ix] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; ix++) { |
| 1046 | if (strcasecmp(name, voices[ix]->namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name.) == 0) { |
| 1047 | match_name = ix; // found matching voice name |
| 1048 | break; |
| 1049 | } else { |
| 1050 | id = voices[ix]->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier.; |
| 1051 | if (strcasecmp(name, id) == 0) |
| 1052 | match_fname = ix; // matching identifier, use this if no matching name |
| 1053 | else if (strcasecmp(last_part, &id[strlen(id)-last_part_len]) == 0) |
| 1054 | match_fname2 = ix; |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | if (match_name < 0) { |
| 1059 | match_name = match_fname; // no matching name, try matching filename |
| 1060 | if (match_name < 0) |
| 1061 | match_name = match_fname2; // try matching just the last part of the filename |
| 1062 | } |
| 1063 | |
| 1064 | if (match_name < 0) |
| 1065 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1066 | |
| 1067 | return voices[match_name]; |
| 1068 | } |
| 1069 | |
| 1070 | char const *SelectVoicecxx . . $ SelectVoice(508dab432d56f032).(espeak_VOICEcxx . . $ espeak_VOICE# *voice_select, int *found) |
| 1071 | { |
| 1072 | // Returns a path within espeak-voices, with a possible +variant suffix |
| 1073 | // variant is an output-only parameter |
| 1074 | |
| 1075 | int nv; // number of candidates |
| 1076 | int ix, ix2; |
| 1077 | int j; |
| 1078 | int n_variants; |
| 1079 | int variant_number; |
| 1080 | int gender; |
| 1081 | int aged = 1; |
| 1082 | char *variant_name; |
| 1083 | const char *p, *p_start; |
| 1084 | espeak_VOICEcxx . . $ espeak_VOICE# *vp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1085 | espeak_VOICEcxx . . $ espeak_VOICE# *vp2; |
| 1086 | espeak_VOICEcxx . . $ espeak_VOICE# voice_select2; |
| 1087 | espeak_VOICEcxx . . $ espeak_VOICE# *voices[N_VOICES_LISTcxx . . $ `external/espeak/voices.cpp:73:9`!]; // list of candidates |
| 1088 | espeak_VOICEcxx . . $ espeak_VOICE# *voices2[N_VOICES_LISTcxx . . $ `external/espeak/voices.cpp:73:9`!+N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`!]; |
| 1089 | static espeak_VOICEcxx . . $ espeak_VOICE# voice_variants[N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`!]; |
| 1090 | static char voice_id[50]; |
| 1091 | |
| 1092 | MAKE_MEM_UNDEFINEDcxx . . $ `external/espeak/speech.h:39:13`!(&voice_variants, sizeof(voice_variants)); |
| 1093 | MAKE_MEM_UNDEFINEDcxx . . $ `external/espeak/speech.h:39:13`!(&voice_id, sizeof(voice_id)); |
| 1094 | |
| 1095 | *found = 1; |
| 1096 | memcpy(&voice_select2, voice_select, sizeof(voice_select2)); |
| 1097 | |
| 1098 | if (n_voices_listcxx . . $ n_voices_list. == 0) |
| 1099 | espeak_ListVoices(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); // create the voices list |
| 1100 | |
| 1101 | if ((voice_select2.languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) || (voice_select2.languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[0] == 0)) { |
| 1102 | // no language is specified. Get language from the named voice |
| 1103 | char buf[60]; |
| 1104 | |
| 1105 | if (voice_select2.namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1106 | if ((voice_select2.namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. = voice_select2.identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier.) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1107 | voice_select2.namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. = ESPEAKNG_DEFAULT_VOICEcxx . . $ `external/espeak/espeak_ng.h:39:9`!; |
| 1108 | } |
| 1109 | |
| 1110 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buf, voice_select2.namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name., sizeof(buf)); |
| 1111 | variant_name = ExtractVoiceVariantNamecxx . . $ ExtractVoiceVariantName(75f8fb248a90efb7).(buf, 0, 0); |
| 1112 | |
| 1113 | vp = SelectVoiceByNamecxx . . $ SelectVoiceByName(735d0e64632a2a26).(voices_listcxx . . $ voices_list., buf); |
| 1114 | if (vp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1115 | voice_select2.languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. = &(vp->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[1]); |
| 1116 | |
| 1117 | if ((voice_select2.gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_UNKNOWN) && (voice_select2.agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. == 0) && (voice_select2.variantcxx . . $ $anonymous_type_6337c0e5abb454c9_8#variant. == 0)) { |
| 1118 | if (variant_name[0] != 0) { |
| 1119 | sprintf(voice_id, "%s+%s", vp->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier., variant_name); |
| 1120 | return voice_id; |
| 1121 | } |
| 1122 | |
| 1123 | return vp->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier.; |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | // select and sort voices for the required language |
| 1129 | nv = SetVoiceScorescxx . . $ SetVoiceScores(a786de115825ad29).(&voice_select2, voices, 0); |
| 1130 | |
| 1131 | if (nv == 0) { |
| 1132 | // no matching voice, choose the default |
| 1133 | *found = 0; |
| 1134 | if ((voices[0] = SelectVoiceByNamecxx . . $ SelectVoiceByName(735d0e64632a2a26).(voices_listcxx . . $ voices_list., ESPEAKNG_DEFAULT_VOICEcxx . . $ `external/espeak/espeak_ng.h:39:9`!)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1135 | nv = 1; |
| 1136 | } |
| 1137 | |
| 1138 | gender = 0; |
| 1139 | if ((voice_select2.gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_FEMALE) || ((voice_select2.agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. > 0) && (voice_select2.agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. < 13))) |
| 1140 | gender = ENGENDER_FEMALE; |
| 1141 | else if (voice_select2.gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. == ENGENDER_MALE) |
| 1142 | gender = ENGENDER_MALE; |
| 1143 | |
| 1144 | #define AGE_OLDcxx . . $ `external/espeak/voices.cpp:1144:10`! 60 |
| 1145 | if (voice_select2.agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. < AGE_OLDcxx . . $ `external/espeak/voices.cpp:1144:10`!) |
| 1146 | aged = 0; |
| 1147 | |
| 1148 | p = p_start = variant_listscxx . . $ variant_lists.[gender]; |
| 1149 | if (aged == 0) |
| 1150 | p++; // the first voice in the variants list is older |
| 1151 | |
| 1152 | // add variants for the top voices |
| 1153 | n_variants = 0; |
| 1154 | for (ix = 0, ix2 = 0; ix < nv; ix++) { |
| 1155 | vp = voices[ix]; |
| 1156 | // is the main voice the required gender? |
| 1157 | bool skip = false; |
| 1158 | |
| 1159 | if ((gender != ENGENDER_UNKNOWN) && (vp->gendercxx . . $ $anonymous_type_6337c0e5abb454c9_8#gender. != gender)) |
| 1160 | skip = true; |
| 1161 | if ((ix2 == 0) && aged && (vp->agecxx . . $ $anonymous_type_6337c0e5abb454c9_8#age. < AGE_OLDcxx . . $ `external/espeak/voices.cpp:1144:10`!)) |
| 1162 | skip = true; |
| 1163 | |
| 1164 | if (skip == false) |
| 1165 | voices2[ix2++] = vp; |
| 1166 | |
| 1167 | for (j = 0; (j < vp->xx1cxx . . $ $anonymous_type_6337c0e5abb454c9_8#xx1.) && (n_variants < N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`!);) { |
| 1168 | if ((variant_number = *p) == 0) { |
| 1169 | p = p_start; |
| 1170 | continue; |
| 1171 | } |
| 1172 | |
| 1173 | vp2 = &voice_variants[n_variants++]; // allocate space for voice variant |
| 1174 | memcpy(vp2, vp, sizeof(espeak_VOICEcxx . . $ espeak_VOICE#)); // copy from the original voice |
| 1175 | vp2->variantcxx . . $ $anonymous_type_6337c0e5abb454c9_8#variant. = variant_number; |
| 1176 | voices2[ix2++] = vp2; |
| 1177 | p++; |
| 1178 | j++; |
| 1179 | } |
| 1180 | } |
| 1181 | // add any more variants to the end of the list |
| 1182 | while ((vp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && ((variant_number = *p++) != 0) && (n_variants < N_VOICE_VARIANTScxx . . $ `external/espeak/voices.cpp:79:9`!)) { |
| 1183 | vp2 = &voice_variants[n_variants++]; // allocate space for voice variant |
| 1184 | memcpy(vp2, vp, sizeof(espeak_VOICEcxx . . $ espeak_VOICE#)); // copy from the original voice |
| 1185 | vp2->variantcxx . . $ $anonymous_type_6337c0e5abb454c9_8#variant. = variant_number; |
| 1186 | voices2[ix2++] = vp2; |
| 1187 | } |
| 1188 | |
| 1189 | // index the sorted list by the required variant number |
| 1190 | if (ix2 == 0) |
| 1191 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1192 | vp = voices2[voice_select2.variantcxx . . $ $anonymous_type_6337c0e5abb454c9_8#variant. % ix2]; |
| 1193 | |
| 1194 | if (vp->variantcxx . . $ $anonymous_type_6337c0e5abb454c9_8#variant. != 0) { |
| 1195 | variant_name = ExtractVoiceVariantNamecxx . . $ ExtractVoiceVariantName(75f8fb248a90efb7).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, vp->variantcxx . . $ $anonymous_type_6337c0e5abb454c9_8#variant., 0); |
| 1196 | sprintf(voice_id, "%s+%s", vp->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier., variant_name); |
| 1197 | return voice_id; |
| 1198 | } |
| 1199 | |
| 1200 | return vp->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier.; |
| 1201 | } |
| 1202 | |
| 1203 | static void GetVoicescxx . . $ GetVoices(7b85637613228108).(const char *path, int len_path_voices, int is_language_file) |
| 1204 | { |
| 1205 | /* ppgb: deleted the Windows-specific file handling from this function */ |
| 1206 | #if DATA_FROM_SOURCECODE_FILEScxx . . $ `external/espeak/espeak__config.h:23:9`! /* ppgb: whole function adapted to Praat */ |
| 1207 | FileInMemorySetcxx . . $ FileInMemorySet# me = theEspeakPraatFileInMemorySetcxx . . $ theEspeakPraatFileInMemorySet(e171e0b8438add33).(); |
| 1208 | static MelderStringcxx . . $ MelderString# criterion; |
| 1209 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& criterion, Melder_peek8to32_u (path)); |
| 1210 | MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& criterion, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!); |
| 1211 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (criterion.length == len_path_voices); // sanity check |
| 1212 | for (long ifile = 1; ifile <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; ifile ++) { |
| 1213 | FileInMemorycxx . . $ FileInMemory# fim = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifile]; |
| 1214 | if (Melder_stringMatchesCriterioncxx . . $ Melder_stringMatchesCriterion(3e677ada61cce709). (fim -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), kMelder_stringcxx . . $ kMelder_string# :: STARTS_WITHcxx . . $ kMelder_string#STARTS_WITH., criterion.stringcxx . . $ MelderString#string., true)) { |
| 1215 | FileInMemorycxx . . $ FileInMemory# f_voice = FileInMemory_fopencxx . . $ FileInMemory_fopen(c104e0235e2c5ecb). (fim, "r"); |
| 1216 | conststring8cxx . . $ conststring8# fname = Melder_peek32to8_fileSystemcxx . . $ Melder_peek32to8_fileSystem(c6a971952cbb8e31). (fim -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1217 | espeak_VOICEcxx . . $ espeak_VOICE# *voice_data = ReadVoiceFilecxx . . $ ReadVoiceFile(a5e6870cc86b1ca7). (f_voice, fname + len_path_voices, is_language_file); |
| 1218 | FileInMemory_fclosecxx . . $ FileInMemory_fclose(18557d97a31d1c3b). (f_voice); |
| 1219 | if (voice_data) |
| 1220 | voices_listcxx . . $ voices_list. [n_voices_listcxx . . $ n_voices_list. ++] = voice_data; |
| 1221 | } |
| 1222 | } |
| 1223 | #else /* ppgb: the original code, which uses opendir: */ |
| 1224 | char fname[sizeof(path_home)+100]; |
| 1225 | DIR *dir; |
| 1226 | struct dirent *ent; |
| 1227 | if ((dir = opendir((char *)path)) == NULL) // note: (char *) is needed for WINCE |
| 1228 | return; |
| 1229 | while ((ent = readdir(dir)) != NULL) { |
| 1230 | if (n_voices_list >= (N_VOICES_LIST-2)) { |
| 1231 | fprintf(stderr, "Warning: maximum number %d of (N_VOICES_LIST = %d - 1) reached\n", n_voices_list + 1, N_VOICES_LIST); |
| 1232 | break; // voices list is full |
| 1233 | } |
| 1234 | if (ent->d_name[0] == '.') |
| 1235 | continue; |
| 1236 | sprintf(fname, "%s%c%s", path, PATHSEP, ent->d_name); |
| 1237 | if (AddToVoicesList(fname, len_path_voices, is_language_file) != 0) { |
| 1238 | // ppgb: there should probably be a warning here |
| 1239 | continue; |
| 1240 | } |
| 1241 | } |
| 1242 | closedir(dir); |
| 1243 | #endif /* DATA_FROM_SOURCECODE_FILES */ |
| 1244 | } |
| 1245 | |
| 1246 | #pragma GCC visibility push(default) |
| 1247 | #if ! DATA_FROM_SOURCECODE_FILEScxx . . $ `external/espeak/espeak__config.h:23:9`! |
| 1248 | ESPEAK_NG_API espeak_ng_STATUS espeak_ng_SetVoiceByFile(const char *filename) |
| 1249 | { |
| 1250 | int ix; |
| 1251 | espeak_VOICE voice_selector; |
| 1252 | char *variant_name; |
| 1253 | char buf[60]; |
| 1254 | |
| 1255 | strncpy0(buf, filename, sizeof(buf)); |
| 1256 | |
| 1257 | variant_name = ExtractVoiceVariantName(buf, 0, 1); |
| 1258 | |
| 1259 | for (ix = 0;; ix++) { |
| 1260 | // convert voice name to lower case (ascii) |
| 1261 | if ((buf[ix] = tolower(buf[ix])) == 0) |
| 1262 | break; |
| 1263 | } |
| 1264 | |
| 1265 | memset(&voice_selector, 0, sizeof(voice_selector)); |
| 1266 | voice_selector.name = (char *)filename; // include variant name in voice stack ?? |
| 1267 | |
| 1268 | // first check for a voice with this filename |
| 1269 | // This may avoid the need to call espeak_ListVoices(). |
| 1270 | |
| 1271 | if (LoadVoice(buf, 0x10) != NULL) { |
| 1272 | if (variant_name[0] != 0) |
| 1273 | LoadVoice(variant_name, 2); |
| 1274 | |
| 1275 | DoVoiceChange(voice); |
| 1276 | voice_selector.languages = voice->language_name; |
| 1277 | SetVoiceStack(&voice_selector, variant_name); |
| 1278 | return ENS_OK; |
| 1279 | } |
| 1280 | |
| 1281 | return ENS_VOICE_NOT_FOUND; |
| 1282 | } |
| 1283 | #endif // ! DATA_FROM_SOURCECODE_FILES |
| 1284 | |
| 1285 | ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! espeak_ng_STATUS espeak_ng_SetVoiceByNamecxx . . $ espeak_ng_SetVoiceByName(731404ba8a6c1921).(const char *name) |
| 1286 | { |
| 1287 | espeak_VOICEcxx . . $ espeak_VOICE# *v; |
| 1288 | int ix; |
| 1289 | espeak_VOICEcxx . . $ espeak_VOICE# voice_selector; |
| 1290 | char *variant_name; |
| 1291 | char buf[60]; |
| 1292 | |
| 1293 | strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(buf, name, sizeof(buf)); |
| 1294 | |
| 1295 | variant_name = ExtractVoiceVariantNamecxx . . $ ExtractVoiceVariantName(75f8fb248a90efb7).(buf, 0, 1); |
| 1296 | |
| 1297 | for (ix = 0;; ix++) { |
| 1298 | // convert voice name to lower case (ascii) |
| 1299 | if ((buf[ix] = tolower(buf[ix])) == 0) |
| 1300 | break; |
| 1301 | } |
| 1302 | |
| 1303 | memset(&voice_selector, 0, sizeof(voice_selector)); |
| 1304 | voice_selector.namecxx . . $ $anonymous_type_6337c0e5abb454c9_8#name. = (char *)name; // include variant name in voice stack ?? |
| 1305 | |
| 1306 | // first check for a voice with this filename |
| 1307 | // This may avoid the need to call espeak_ListVoices(). |
| 1308 | |
| 1309 | if (LoadVoicecxx . . $ LoadVoice(7a9427dcaeff0687).(buf, 1) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1310 | if (variant_name[0] != 0) |
| 1311 | LoadVoicecxx . . $ LoadVoice(7a9427dcaeff0687).(variant_name, 2); |
| 1312 | |
| 1313 | DoVoiceChange(voicecxx . . $ voice.); |
| 1314 | voice_selector.languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. = voicecxx . . $ voice.->language_name; |
| 1315 | SetVoiceStack(&voice_selector, variant_name); |
| 1316 | return ENS_OK; |
| 1317 | } |
| 1318 | |
| 1319 | if (n_voices_listcxx . . $ n_voices_list. == 0) |
| 1320 | espeak_ListVoices(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); // create the voices list |
| 1321 | |
| 1322 | if ((v = SelectVoiceByNamecxx . . $ SelectVoiceByName(735d0e64632a2a26).(voices_listcxx . . $ voices_list., buf)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1323 | if (LoadVoicecxx . . $ LoadVoice(7a9427dcaeff0687).(v->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier., 0) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1324 | if (variant_name[0] != 0) |
| 1325 | LoadVoicecxx . . $ LoadVoice(7a9427dcaeff0687).(variant_name, 2); |
| 1326 | DoVoiceChange(voicecxx . . $ voice.); |
| 1327 | voice_selector.languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages. = voicecxx . . $ voice.->language_name; |
| 1328 | SetVoiceStack(&voice_selector, variant_name); |
| 1329 | return ENS_OK; |
| 1330 | } |
| 1331 | } |
| 1332 | return ENS_VOICE_NOT_FOUND; |
| 1333 | } |
| 1334 | |
| 1335 | ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! espeak_ng_STATUS espeak_ng_SetVoiceByPropertiescxx . . $ espeak_ng_SetVoiceByProperties(869a29ecd5532ed1).(espeak_VOICEcxx . . $ espeak_VOICE# *voice_selector) |
| 1336 | { |
| 1337 | const char *voice_id; |
| 1338 | int voice_found; |
| 1339 | |
| 1340 | voice_id = SelectVoicecxx . . $ SelectVoice(508dab432d56f032).(voice_selector, &voice_found); |
| 1341 | if (voice_found == 0) |
| 1342 | return ENS_VOICE_NOT_FOUND; |
| 1343 | |
| 1344 | LoadVoiceVariantcxx . . $ LoadVoiceVariant(7a9427dcaeff0687).(voice_id, 0); |
| 1345 | DoVoiceChange(voicecxx . . $ voice.); |
| 1346 | SetVoiceStack(voice_selector, ""); |
| 1347 | |
| 1348 | return ENS_OK; |
| 1349 | } |
| 1350 | |
| 1351 | #pragma GCC visibility pop |
| 1352 | |
| 1353 | void FreeVoiceListcxx . . $ FreeVoiceList(49f6e7a06ebc5aa8).(void) |
| 1354 | { |
| 1355 | int ix; |
| 1356 | for (ix = 0; ix < n_voices_listcxx . . $ n_voices_list.; ix++) { |
| 1357 | if (voices_listcxx . . $ voices_list.[ix] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1358 | freecxx . . $ free(bd21765a0afc8e3c).(voices_listcxx . . $ voices_list.[ix]); |
| 1359 | voices_listcxx . . $ voices_list.[ix] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1360 | } |
| 1361 | } |
| 1362 | n_voices_listcxx . . $ n_voices_list. = 0; |
| 1363 | } |
| 1364 | |
| 1365 | #pragma GCC visibility push(default) |
| 1366 | |
| 1367 | ESPEAK_APIcxx . . $ `external/espeak/speak_lib.h:38:9`! const espeak_VOICEcxx . . $ espeak_VOICE# **espeak_ListVoicescxx . . $ espeak_ListVoices(5446c9db9da6cb3e).(espeak_VOICEcxx . . $ espeak_VOICE# *voice_spec) |
| 1368 | { |
| 1369 | char path_voices[sizeof(path_home)+12]; |
| 1370 | |
| 1371 | espeak_VOICEcxx . . $ espeak_VOICE# *v; |
| 1372 | static espeak_VOICEcxx . . $ espeak_VOICE# **voices = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1373 | |
| 1374 | // free previous voice list data |
| 1375 | FreeVoiceListcxx . . $ FreeVoiceList(49f6e7a06ebc5aa8).(); |
| 1376 | |
| 1377 | sprintf(path_voices, "%s%cvoices", path_home, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!); |
| 1378 | GetVoicescxx . . $ GetVoices(7b85637613228108).(path_voices, strlen(path_voices)+1, 0); |
| 1379 | |
| 1380 | sprintf(path_voices, "%s%clang", path_home, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!); |
| 1381 | GetVoicescxx . . $ GetVoices(7b85637613228108).(path_voices, strlen(path_voices)+1, 1); |
| 1382 | |
| 1383 | voices_listcxx . . $ voices_list.[n_voices_listcxx . . $ n_voices_list.] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; // voices list terminator |
| 1384 | espeak_VOICEcxx . . $ espeak_VOICE# **new_voices = (espeak_VOICEcxx . . $ espeak_VOICE# **)realloccxx . . $ realloc(42b2a9dd8f084bf2).(voices, sizeof(espeak_VOICEcxx . . $ espeak_VOICE# *)*(n_voices_listcxx . . $ n_voices_list.+1)); |
| 1385 | if (new_voices == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1386 | return (const espeak_VOICEcxx . . $ espeak_VOICE# **)voices; |
| 1387 | voices = new_voices; |
| 1388 | |
| 1389 | // sort the voices list |
| 1390 | qsortcxx . . $ qsort(ebb60b13a65e77d7).(voices_listcxx . . $ voices_list., n_voices_listcxx . . $ n_voices_list., sizeof(espeak_VOICEcxx . . $ espeak_VOICE# *), |
| 1391 | (int(__cdeclcxx . . $ `external/espeak/speech.h:74:9`! *)(const void *, const void *))VoiceNameSortercxx . . $ VoiceNameSorter(9148c8c3ff42c9d8).); |
| 1392 | |
| 1393 | if (voice_spec) { |
| 1394 | // select the voices which match the voice_spec, and sort them by preference |
| 1395 | SetVoiceScorescxx . . $ SetVoiceScores(a786de115825ad29).(voice_spec, voices, 1); |
| 1396 | } else { |
| 1397 | // list all: omit variant and mbrola voices |
| 1398 | int ix; |
| 1399 | int j; |
| 1400 | |
| 1401 | j = 0; |
| 1402 | for (ix = 0; (v = voices_listcxx . . $ voices_list.[ix]) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; ix++) { |
| 1403 | if ((v->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[0] != 0) && (strcmp(&v->languagescxx . . $ $anonymous_type_6337c0e5abb454c9_8#languages.[1], "variant") != 0) |
| 1404 | && (memcmp(v->identifiercxx . . $ $anonymous_type_6337c0e5abb454c9_8#identifier., "mb/", 3) != 0)) |
| 1405 | voices[j++] = v; |
| 1406 | } |
| 1407 | voices[j] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1408 | } |
| 1409 | return (const espeak_VOICEcxx . . $ espeak_VOICE# **)voices; |
| 1410 | } |
| 1411 | |
| 1412 | ESPEAK_APIcxx . . $ `external/espeak/speak_lib.h:38:9`! espeak_VOICEcxx . . $ espeak_VOICE# *espeak_GetCurrentVoicecxx . . $ espeak_GetCurrentVoice(aaef10f439e105e0).(void) |
| 1413 | { |
| 1414 | return ¤t_voice_selectedcxx . . $ current_voice_selected.; |
| 1415 | } |
| 1416 | |
| 1417 | #pragma GCC visibility pop |
| 1418 | |
| 1419 | static int AddToVoicesListcxx . . $ AddToVoicesList(1163be050dbfff7).(const char *fname, int len_path_voices, int is_language_file) { |
| 1420 | int ftype = GetFileLengthcxx . . $ GetFileLength(5c4306d8553b3696).(fname); |
| 1421 | |
| 1422 | if (ftype == -EISDIRcxx . . $ `<external>/8987895939074593727/errno-base.h:25:9`!) { |
| 1423 | // a sub-directory |
| 1424 | GetVoicescxx . . $ GetVoices(7b85637613228108).(fname, len_path_voices, is_language_file); // ppgb comment: recurse |
| 1425 | } else if (ftype > 0) { |
| 1426 | // a regular file, add it to the voices list |
| 1427 | FileInMemorycxx . . $ FileInMemory# f_voice; |
| 1428 | if ((f_voice = FileInMemorySet_fopencxx . . $ FileInMemorySet_fopen(3c6da2b95de6d644).(theEspeakPraatFileInMemorySetcxx . . $ theEspeakPraatFileInMemorySet(e171e0b8438add33).(), fname, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1429 | return 1; |
| 1430 | |
| 1431 | // pass voice file name within the voices directory |
| 1432 | espeak_VOICEcxx . . $ espeak_VOICE# *voice_data; |
| 1433 | voice_data = ReadVoiceFilecxx . . $ ReadVoiceFile(a5e6870cc86b1ca7).(f_voice, fname+len_path_voices, is_language_file); |
| 1434 | FileInMemory_fclosecxx . . $ FileInMemory_fclose(18557d97a31d1c3b).(f_voice); |
| 1435 | |
| 1436 | if (voice_data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 1437 | voices_listcxx . . $ voices_list.[n_voices_listcxx . . $ n_voices_list.++] = voice_data; |
| 1438 | } |
| 1439 | return 0; |
| 1440 | } |