| 1 |
"How to integrate eSpeak into Praat" |
| 2 |
© 2012,2015,2017,2021,2023 David Weenink, 2024-2026 Paul Boersma |
| 3 |
|
| 4 |
This script is `generate/espeak/GENERATE.praat` in the Praat source distribution. |
| 5 |
It looks like a Praat %notebook and can indeed be dry-run as such, |
| 6 |
but it is actually meant as a Praat %script from which you copy–paste |
| 7 |
`bash` lines into a terminal window and run Praat chunks with "Run selection". |
| 8 |
|
| 9 |
All paths in this script are relative to where this script is. |
| 10 |
|
| 11 |
1. Getting the eSpeak sources |
| 12 |
============================= |
| 13 |
|
| 14 |
The eSpeak NG program and its library are the successor of eSpeak |
| 15 |
(eSpeak was maintained by Jonathan Duddington); eSpeak NG is a fork |
| 16 |
maintained by Reece H. Dunn. |
| 17 |
|
| 18 |
If you download the eSpeak NG code for the first time, you can do this by downloading or cloning the sources from upstream, |
| 19 |
namely from `https://github.com/espeak-ng/espeak-ng`, in one of two ways. |
| 20 |
|
| 21 |
If you just need the sources and don’t plan to send bug fixes to the eSpeak team, |
| 22 |
you can just download the ZIP file and unpack it, |
| 23 |
in e.g. `../../../support/external/eSpeak`, giving a folder `../../../support/external/eSpeak/espeak-ng`, |
| 24 |
to whose name you could then append the appropriate version number, |
| 25 |
(which you can find in the second line of `../../../support/external/eSpeak/espeak-ng/configure.ac`) |
| 26 |
or the download date (this is better, because versions changes much more often than the version number). |
| 27 |
If the eSpeak version number is `1.52-dev` and the download date is 2024-08-24, |
| 28 |
the resulting folder `../../../support/external/eSpeak/espeak-ng-20240824` takes up 66.5 MB. |
| 29 |
|
| 30 |
Alternatively, you %clone the Git repository: |
| 31 |
{; |
| 32 |
cd ../../../support/external/eSpeak |
| 33 |
git clone https://github.com/espeak-ng/espeak-ng.git |
| 34 |
mv espeak-ng espeak-ng-20240824 |
| 35 |
} |
| 36 |
This way, the folder `../../../support/external/eSpeak/espeak-ng-20240824` will be 152.1 MB large. |
| 37 |
The difference between the two ways of creating the folder is due to the existence of the `.git` file, |
| 38 |
which takes up 85.7 MB. |
| 39 |
|
| 40 |
2. Building eSpeak language dictionaries |
| 41 |
======================================== |
| 42 |
|
| 43 |
The eSpeak NG sources as downloaded above are not complete. We will have to build the dictionaries. |
| 44 |
If you can build Praat itself, you have already installed a compiler, and compiler tools (`make`, `pkg-config`). |
| 45 |
Also install `automake`, `autoconf` and `libtool`. |
| 46 |
{; |
| 47 |
cd ../../../support/external/eSpeak/espeak-ng-20240824 |
| 48 |
./autogen.sh |
| 49 |
./configure |
| 50 |
# or: CC=gcc CFLAGS="-Wprototype..." ./configure prefix=/usr/local (or /usr) |
| 51 |
make |
| 52 |
} |
| 53 |
This creates in the subfolder `espeak-ng-data` the 117 files `XXX_dict` (the voices were already there), |
| 54 |
as well as `phontab`, `phondata`, `phondata-manifest`, `phonindex`, and `intonations`. |
| 55 |
Next to these 122 files in `espeak-ng-data`, there are 104 voices in its subfolder `voices/!v`, |
| 56 |
and 131 files in its subfolder `lang`, for a total of 360 files (version downloaded 2024-08-24). |
| 57 |
|
| 58 |
If you have the Git version, you can establish updates via |
| 59 |
{; |
| 60 |
cd ../../../support/external/eSpeak/espeak-ng-20240824 |
| 61 |
git pull https://github.com/espeak-ng/espeak-ng.git |
| 62 |
make clean |
| 63 |
make |
| 64 |
} |
| 65 |
|
| 66 |
3. Copying eSpeak data to the Praat sources |
| 67 |
=========================================== |
| 68 |
|
| 69 |
Copy the files in `../../../support/external/eSpeak/espeak-ng-20240824/espeak-ng-data` |
| 70 |
to `./data` and its subfolders `lang` and `voices`, |
| 71 |
for instance by just copying the whole folder and deleting the subfolders `mbrola_ph` and `voices/mb`. |
| 72 |
|
| 73 |
In the eSpeak NG app, the `espeak-ng-data` folder is used to supply the data the synthesizer needs. |
| 74 |
The synthesizer needs to know the location of this folder to work correctly; |
| 75 |
also, the synthesizer’s versions and the `espeak-ng-data` versions of the data files have to be synchronized. |
| 76 |
This scheme is not acceptable in Praat, since we cannot expect users to maintain |
| 77 |
a separate folder for the eSpeak NG data. |
| 78 |
Therefore we convert the 360 data files into source code files that contain FileInMemory objects, |
| 79 |
inside the folder of this script. The eSpeak source code will have to be converted to accomplish this. |
| 80 |
|
| 81 |
As the license of eSpeak is GPL 3 or later, our derived FileInMemory objects are distributed under GPL 3 or later as well: |
| 82 |
{ |
| 83 |
procedure saveFileInMemorySetAsCppFile: .name$ |
| 84 |
.fileName$ = .name$ + ".cpp" |
| 85 |
.head$ = |
| 86 |
... "/* " + .fileName$ + newline$ + |
| 87 |
... " *" + newline$ + |
| 88 |
... " * This file was automatically created from files in the folder `generate/espeak/data`" + newline$ + |
| 89 |
... " * by the script `generate/espeak/GENERATE.praat` in the Praat source distribution." + newline$ + |
| 90 |
... " *" + newline$ + |
| 91 |
... " * eSpeak NG version: 1.52-dev, downloaded 2024-08-24T19:38Z from https://github.com/espeak-ng/espeak-ng" + newline$ + |
| 92 |
... " * File creation date: " + date$ () + newline$ + |
| 93 |
... " *" + newline$ + |
| 94 |
... " * Copyright (C) 2005-2014 Jonathan Duddington (for eSpeak)" + newline$ + |
| 95 |
... " * Copyright (C) 2015-2023 Reese Dunn (for eSpeak-NG)" + newline$ + |
| 96 |
... " * Copyright (C) 2012-2024 David Weenink, 2024,2026 Paul Boersma (for Praat)" + newline$ + |
| 97 |
... " *" + newline$ + |
| 98 |
... " * This program is free software; you can redistribute it and/or modify " + newline$ + |
| 99 |
... " * it under the terms of the GNU General Public License as published by" + newline$ + |
| 100 |
... " * the Free Software Foundation; either version 3 of the License, or" + newline$ + |
| 101 |
... " * (at your option) any later version." + newline$ + |
| 102 |
... " *" + newline$ + |
| 103 |
... " * This program is distributed in the hope that it will be useful," + newline$ + |
| 104 |
... " * but WITHOUT ANY WARRANTY; without even the implied warranty of" + newline$ + |
| 105 |
... " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" + newline$ + |
| 106 |
... " * GNU General Public License for more details." + newline$ + |
| 107 |
... " *" + newline$ + |
| 108 |
... " * You should have received a copy of the GNU General Public License" + newline$ + |
| 109 |
... " * along with this program; if not, see: <http://www.gnu.org/licenses/>." + newline$ + |
| 110 |
... " */" + newline$ + newline$ + |
| 111 |
... “#include "espeak_praat.h"” + newline$ |
| 112 |
.code$ = Show as code: .name$, 100 |
| 113 |
.tail$ = "/* End of file " + .fileName$ + " */" + newline$ |
| 114 |
writeFile: .fileName$, .head$, .code$, .tail$ |
| 115 |
endproc |
| 116 |
} |
| 117 |
|
| 118 |
Create FileInMemory objects for the five `phon` files. |
| 119 |
|
| 120 |
%Hack: we have to make five sets of one, because `Create FileInMemory...` turns the relative path |
| 121 |
into an absolute path, while `Create FileInMemorySet from directory contents...` |
| 122 |
retains the relative path, which is what we want. |
| 123 |
|
| 124 |
{ |
| 125 |
procedure defineDataFolders |
| 126 |
generationFolder$ = "." ; the folder of this script, i.e. `generate/espeak` in the Praat sources |
| 127 |
generationDataFolder$ = generationFolder$ + "/data" |
| 128 |
generationLanguageFolder$ = generationDataFolder$ + "/lang" |
| 129 |
generationVoicesFolder$ = generationDataFolder$ + "/voices/!v" |
| 130 |
generationSourceFolder$ = generationFolder$ + "/src" |
| 131 |
endproc |
| 132 |
} |
| 133 |
|
| 134 |
{; |
| 135 |
@defineDataFolders |
| 136 |
fim1 = Create FileInMemorySet from directory contents: "fim1", generationDataFolder$, "*phondata" |
| 137 |
fim2 = Create FileInMemorySet from directory contents: "fim2", generationDataFolder$, "*phonindex" |
| 138 |
fim3 = Create FileInMemorySet from directory contents: "fim3", generationDataFolder$, "*phontab" |
| 139 |
fim4 = Create FileInMemorySet from directory contents: "fim4", generationDataFolder$, "*intonations" |
| 140 |
fim5 = Create FileInMemorySet from directory contents: "fim5", generationDataFolder$, "*phondata-manifest" |
| 141 |
selectObject: fim1, fim2, fim3, fim4, fim5 |
| 142 |
Merge |
| 143 |
Rename: "phon" |
| 144 |
removeObject: fim1, fim2, fim3, fim4, fim5 |
| 145 |
} |
| 146 |
Create FileInMemory objects for the 117 dictionary files, with 23,013,656 bytes in total. |
| 147 |
{; |
| 148 |
@defineDataFolders |
| 149 |
Create FileInMemorySet from directory contents: "dicts", generationDataFolder$, "*_dict" |
| 150 |
numberOfDicts = Get number of files |
| 151 |
assert numberOfDicts = 117 |
| 152 |
} |
| 153 |
Create FileInMemory objects for the 134 language files. Three language files (eu, ko, qu) |
| 154 |
are at the top level of the `lang` folder: |
| 155 |
{; |
| 156 |
@defineDataFolders |
| 157 |
Create FileInMemorySet from directory contents: "languages", generationLanguageFolder$, "*" |
| 158 |
numberOfLanguages = Get number of files |
| 159 |
assert numberOfLanguages = 3 |
| 160 |
} |
| 161 |
The remaining 134 language files are in subfolders: |
| 162 |
{; |
| 163 |
@defineDataFolders |
| 164 |
languageFolders$# = folderNames$# (generationLanguageFolder$ + "/*") |
| 165 |
for languageFolder to size (languageFolders$#) |
| 166 |
languageFolder$ = languageFolders$# [languageFolder] |
| 167 |
languageFiles = Create FileInMemorySet from directory contents: "language", generationLanguageFolder$ + "/" + languageFolder$ , "*" |
| 168 |
plusObject: "FileInMemorySet languages" |
| 169 |
merged = Merge |
| 170 |
# should be: Merge second into first |
| 171 |
removeObject: languageFiles, "FileInMemorySet languages" |
| 172 |
selectObject: merged |
| 173 |
Rename: "languages" |
| 174 |
endfor |
| 175 |
numberOfLanguages = Get number of files |
| 176 |
assert numberOfLanguages = 137 |
| 177 |
} |
| 178 |
Create FileInMemory objects for the 104 voice files. |
| 179 |
{; |
| 180 |
@defineDataFolders |
| 181 |
Create FileInMemorySet from directory contents: "voices", generationVoicesFolder$, "*" |
| 182 |
numberOfVoices = Get number of files |
| 183 |
assert numberOfVoices = 104 |
| 184 |
} |
| 185 |
We safely save these into the generation folder: |
| 186 |
{; |
| 187 |
@defineDataFolders |
| 188 |
selectObject: "FileInMemorySet phon" |
| 189 |
@saveFileInMemorySetAsCppFile: "espeak_praat_FileInMemorySet_addPhon" |
| 190 |
selectObject: "FileInMemorySet dicts" |
| 191 |
@saveFileInMemorySetAsCppFile: "espeak_praat_FileInMemorySet_addDicts" |
| 192 |
selectObject: "FileInMemorySet languages" |
| 193 |
@saveFileInMemorySetAsCppFile: "espeak_praat_FileInMemorySet_addLanguages" |
| 194 |
selectObject: "FileInMemorySet voices" |
| 195 |
@saveFileInMemorySetAsCppFile: "espeak_praat_FileInMemorySet_addVoices" |
| 196 |
} |
| 197 |
After some inspection for correctness, %move (not %copy, in order to save space) |
| 198 |
these files into `src/external/espeak`. |
| 199 |
|
| 200 |
4. Copying eSpeak source code to the Praat sources |
| 201 |
================================================== |
| 202 |
|
| 203 |
The following files are in `support/external/eSpeak/espeak-ng-20240824/src`: |
| 204 |
{ |
| 205 |
procedure defineSourceFolders |
| 206 |
srcRootFolder$ = "../../../support/external/eSpeak/espeak-ng-20240824/src" |
| 207 |
|
| 208 |
sourceFolder$ = srcRootFolder$ + "/libespeak-ng" |
| 209 |
sourceFiles$# = { "common.c", "compiledict.c", "compilembrola.c", "dictionary.c", |
| 210 |
... "encoding.c", "error.c", "espeak_api.c", "espeak_command.c", |
| 211 |
... "event.c", "fifo.c", "ieee80.c", "intonation.c", |
| 212 |
... "klatt.c", "langopts.c", "mnemonics.c", "numbers.c", "phoneme.c", "phonemelist.c", |
| 213 |
... "readclause.c", "setlengths.c", "soundicon.c", "spect.c", "speech.c", "ssml.c", |
| 214 |
... "synthdata.c", "synthesize.c", "synth_mbrola.c", "translate.c", "translateword.c", "tr_languages.c", |
| 215 |
... "voices.c", "wavegen.c" } |
| 216 |
|
| 217 |
privateHeaderFolder$ = sourceFolder$ |
| 218 |
privateHeaderFiles$# = { "common.h", "compiledict.h", "dictionary.h", |
| 219 |
... "error.h", "espeak_command.h", "event.h", "fifo.h", "intonation.h", |
| 220 |
... "klatt.h", "langopts.h", "mnemonics.h", "mbrola.h", "numbers.h", "phoneme.h", "phonemelist.h", |
| 221 |
... "readclause.h", "setlengths.h", "sintab.h", "soundicon.h", "speech.h", "ssml.h", |
| 222 |
... "synthdata.h", "synthesize.h", "translate.h", "translateword.h", |
| 223 |
... "voice.h", "wavegen.h" } |
| 224 |
|
| 225 |
publicHeaderFolder$ = srcRootFolder$ + "/include/espeak-ng" |
| 226 |
publicHeaderFiles$# = { "encoding.h", "espeak_ng.h", "speak_lib.h" } |
| 227 |
|
| 228 |
ucdSourceFolder$ = srcRootFolder$ + "/ucd-tools/src" |
| 229 |
ucdSourceFiles$# = { "case.c", "categories.c", "proplist.c" } |
| 230 |
|
| 231 |
ucdHeaderFolder$ = srcRootFolder$ + "/ucd-tools/src/include/ucd" |
| 232 |
ucdHeaderFiles$# = { "ucd.h" } |
| 233 |
endproc |
| 234 |
} |
| 235 |
All of these are moved to `generate/espeak/src`, without any recursion, while renaming `c` to `cpp` files: |
| 236 |
{; |
| 237 |
@defineSourceFolders |
| 238 |
for i to size (sourceFiles$#) |
| 239 |
text$ = readFile$: sourceFolder$ + "/" + sourceFiles$# [i] |
| 240 |
writeFile: generationSourceFolder$ + "/" + sourceFiles$# [i] + "pp", text$ |
| 241 |
endfor |
| 242 |
for i to size (privateHeaderFiles$#) |
| 243 |
text$ = readFile$: privateHeaderFolder$ + "/" + privateHeaderFiles$# [i] |
| 244 |
writeFile: generationSourceFolder$ + "/" + privateHeaderFiles$# [i], text$ |
| 245 |
endfor |
| 246 |
for i to size (publicHeaderFiles$#) |
| 247 |
text$ = readFile$: publicHeaderFolder$ + "/" + publicHeaderFiles$# [i] |
| 248 |
writeFile: generationSourceFolder$ + "/" + publicHeaderFiles$# [i], text$ |
| 249 |
endfor |
| 250 |
for i to size (ucdSourceFiles$#) |
| 251 |
text$ = readFile$: ucdSourceFolder$ + "/" + ucdSourceFiles$# [i] |
| 252 |
writeFile: generationSourceFolder$ + "/" + ucdSourceFiles$# [i] + "pp", text$ |
| 253 |
endfor |
| 254 |
for i to size (ucdHeaderFiles$#) |
| 255 |
text$ = readFile$: ucdHeaderFolder$ + "/" + ucdHeaderFiles$# [i] |
| 256 |
writeFile: generationSourceFolder$ + "/" + ucdHeaderFiles$# [i], text$ |
| 257 |
endfor |
| 258 |
} |
| 259 |
|
| 260 |
5. Adapting eSpeak source code to Praat |
| 261 |
======================================= |
| 262 |
|
| 263 |
Many changes to the sources have to be made. If the original eSpeak sources don't change too much, |
| 264 |
this can be done by a visual `diff` between for instance `./src/speech.cpp` (in the present generation folder) |
| 265 |
and `../../external/espeak/speech.cpp` (in the actual Praat sources). |
| 266 |
The former is the one to be changed (in the way described below). |
| 267 |
Once all the source and header files are fine, they can be moved over the ones in `../../external/espeak`. |
| 268 |
After this, the folder `./src` will be empty again. |
| 269 |
|
| 270 |
- Simplify all includes, e.g. "espeak-ng/something.h" to "something.h" |
| 271 |
- Rename `config.h` to `espeak__config.h`, and simplify it strongly, |
| 272 |
reducing it to |
| 273 |
{; |
| 274 |
/* |
| 275 |
The config file typically contains lots of stuff that is specific to the machine on which eSpeak is compiled. |
| 276 |
However, in Praat we relegate all of this to `melder.h`. |
| 277 |
|
| 278 |
This file should be included before any other include file, in order to prevent definition clashes. |
| 279 |
|
| 280 |
In the Praat sources, this file should be included only in `.cpp` files inside `src/external/espeak`. |
| 281 |
Inclusion elsewhere in Praat can lead to clashes (e.g., `USE_ASYNC` undergoes an `#ifdef` in `mad`). |
| 282 |
*/ |
| 283 |
|
| 284 |
#define PACKAGE_VERSION "1.52-dev" |
| 285 |
|
| 286 |
#define USE_ASYNC 0 |
| 287 |
#define USE_LIBPCAUDIO 0 |
| 288 |
|
| 289 |
/* |
| 290 |
Integration into Praat |
| 291 |
*/ |
| 292 |
#define DATA_FROM_SOURCECODE_FILES 1 |
| 293 |
#define PATH_ESPEAK_DATA "./data" /* a relative path */ |
| 294 |
} |
| 295 |
- Adapt the source files that include `config.h` to including `espeak__config.h`. |
| 296 |
- Cast many return values and error values. |
| 297 |
|
| 298 |
- Adapt `GetVoices()` in `voices.cpp`: |
| 299 |
{; |
| 300 |
#if DATA_FROM_SOURCECODE_FILES /* ppgb: whole function adapted to Praat */ |
| 301 |
FileInMemorySet me = theEspeakPraatFileInMemorySet(); |
| 302 |
static MelderString criterion; |
| 303 |
MelderString_copy (& criterion, Melder_peek8to32_u (path)); |
| 304 |
MelderString_appendCharacter (& criterion, PATHSEP); |
| 305 |
Melder_assert (criterion.length == len_path_voices); // sanity check |
| 306 |
for (long ifile = 1; ifile <= my size; ifile ++) { |
| 307 |
FileInMemory fim = my at [ifile]; |
| 308 |
if (Melder_stringMatchesCriterion (fim -> string.get(), kMelder_string :: STARTS_WITH, criterion.string, true)) { |
| 309 |
FileInMemory f_voice = FileInMemory_fopen (fim, "r"); |
| 310 |
conststring8 fname = Melder_peek32to8_fileSystem (fim -> string.get()); |
| 311 |
espeak_VOICE *voice_data = ReadVoiceFile (f_voice, fname + len_path_voices, is_language_file); |
| 312 |
FileInMemory_fclose (f_voice); |
| 313 |
if (voice_data) |
| 314 |
voices_list [n_voices_list ++] = voice_data; |
| 315 |
} |
| 316 |
} |
| 317 |
#else /* ppgb: the original code, which uses opendir: */ |
| 318 |
char fname[sizeof(path_home)+100]; |
| 319 |
DIR *dir; |
| 320 |
struct dirent *ent; |
| 321 |
if ((dir = opendir((char *)path)) == NULL) // note: (char *) is needed for WINCE |
| 322 |
return; |
| 323 |
while ((ent = readdir(dir)) != NULL) { |
| 324 |
if (n_voices_list >= (N_VOICES_LIST-2)) { |
| 325 |
fprintf(stderr, "Warning: maximum number %d of (N_VOICES_LIST = %d - 1) reached\n", n_voices_list + 1, N_VOICES_LIST); |
| 326 |
break; // voices list is full |
| 327 |
} |
| 328 |
if (ent->d_name[0] == '.') |
| 329 |
continue; |
| 330 |
sprintf(fname, "%s%c%s", path, PATHSEP, ent->d_name); |
| 331 |
if (AddToVoicesList(fname, len_path_voices, is_language_file) != 0) |
| 332 |
continue; |
| 333 |
} |
| 334 |
closedir(dir); |
| 335 |
#endif /* DATA_FROM_SOURCECODE_FILES */ |
| 336 |
} |
| 337 |
|
| 338 |
# 7. in error.cpp replace writing to stderr with calls to Melder_throw() |
| 339 |
|
| 340 |
In `dictionary.cpp`, `soundicon.cpp`, `speech.cpp`, `synthdata.cpp`, and `voices.cpp`: |
| 341 |
- replace `FILE *` with `FileInMemory` (also in `common.cpp`); |
| 342 |
- `#include "espeak_praat.h"`; |
| 343 |
- prepend "FileInMemorySet_" to all calls of stat and fopen, adding a first argument `theEspeakPraatFileInMemorySet()`; |
| 344 |
- prepend "FileInMemory_" to all calls of fclose, feof, fseek, ftell, fgets, fread, fgetc, fprintf and ungetc; |
| 345 |
|
| 346 |
Here we list all the (remaining) occurrences of those functions in those five files |
| 347 |
(`fprintf` should stay if to `stderr` or `f_trans`): |
| 348 |
{; |
| 349 |
if 0 |
| 350 |
@defineSourceFolders |
| 351 |
sourceFolder$ = generationSourceFolder$ |
| 352 |
else |
| 353 |
sourceFolder$ = "../../external/espeak" |
| 354 |
endif |
| 355 |
sourceFiles$# = { "dictionary.cpp", "soundicon.cpp", "speech.cpp", "synthdata.cpp", "voices.cpp", "common.cpp" } |
| 356 |
targets$# = { "stat", "fopen", "fclose", "feof", "fseek", "ftell", "fgets", "fread", "fgetc", "fprintf", "ungetc" } |
| 357 |
writeInfo() |
| 358 |
for file to size (sourceFiles$#) |
| 359 |
lines$# = readLinesFromFile$#: sourceFolder$ + "/" + sourceFiles$# [file] |
| 360 |
for line to size (lines$#) |
| 361 |
line$ = lines$# [line] |
| 362 |
for target to size (targets$#) |
| 363 |
target$ = targets$# [target] |
| 364 |
if index_regex (line$, "[^_]" + target$) |
| 365 |
appendInfoLine: sourceFiles$# [file], " ", line, " ", line$ |
| 366 |
endif |
| 367 |
endfor |
| 368 |
endfor |
| 369 |
endfor |
| 370 |
} |
| 371 |
Replace `FILE *` with `FileInMemory` in the relevant files. |
| 372 |
{; |
| 373 |
if 0 |
| 374 |
@defineSourceFolders |
| 375 |
sourceFolder$ = generationSourceFolder$ |
| 376 |
else |
| 377 |
sourceFolder$ = "../../external/espeak" |
| 378 |
endif |
| 379 |
sourceFiles$# = { "dictionary.cpp", "soundicon.cpp", "speech.cpp", "synthdata.cpp", "voices.cpp", "common.cpp", "common.h" } |
| 380 |
writeInfo() |
| 381 |
for file to size (sourceFiles$#) |
| 382 |
lines$# = readLinesFromFile$#: sourceFolder$ + "/" + sourceFiles$# [file] |
| 383 |
for line to size (lines$#) |
| 384 |
line$ = lines$# [line] |
| 385 |
if index_regex (line$, "FILE\W") |
| 386 |
appendInfoLine: sourceFiles$# [file], " ", line, " ", line$ |
| 387 |
endif |
| 388 |
endfor |
| 389 |
endfor |
| 390 |
} |
| 391 |
In `speech.cpp`: |
| 392 |
- make `sync_espeak_Key`, `sync_espeak_Char`, `sync_espeak_SetPunctuationList` static, moving `sync_espeak_Char` first |
| 393 |
- uninclude "espeak_command.h" (because `delete_espeak_command` falls under `USE_ASYNC`, |
| 394 |
`SetParameter` is also in `setlengths.h`, and `sync_espeak_Char` has become static) |
| 395 |
- include "setlengths.h" (for `SetParameter`) |
| 396 |
|
| 397 |
- `GetFileLength()` in `common.cpp` will simply end up like this (remove the Windows-specific stuff): |
| 398 |
{; |
| 399 |
int GetFileLength(const char *filename) |
| 400 |
{ |
| 401 |
struct stat statbuf; |
| 402 |
if (FileInMemorySet_stat(theEspeakPraatFileInMemorySet(), filename, &statbuf) != 0) |
| 403 |
return -errno; |
| 404 |
if (S_ISDIR(statbuf.st_mode)) |
| 405 |
return -EISDIR; |
| 406 |
return statbuf.st_size; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
# 9. delete all "#pragma GCC visibility" lines |
| 411 |
|
| 412 |
We inserted a number of explicit casts: |
| 413 |
static_cast<espeak_ng_STATUS> (errno) |
| 414 |
|
| 415 |
The overaching header file is `espeak_ng.h`, |
| 416 |
so any #defines that should be global to espeak should be defined in `espeak_ng.h`. |
| 417 |
|
| 418 |
In `espeak_ng.h`, we should ignore all the `dllexport` and `dllimport` labels: |
| 419 |
//ppgb #if defined(_WIN32) || defined(_WIN64) |
| 420 |
//ppgb #ifdef LIBESPEAK_NG_EXPORT |
| 421 |
//ppgb #define ESPEAK_NG_API __declspec(dllexport) |
| 422 |
//ppgb #else |
| 423 |
//ppgb #define ESPEAK_NG_API __declspec(dllimport) |
| 424 |
//ppgb #endif |
| 425 |
//ppgb #else |
| 426 |
#define ESPEAK_NG_API |
| 427 |
//ppgb #endif |
| 428 |
|
| 429 |
In `speak_ng.h`, we replace the Windows-specific part |
| 430 |
#define PLATFORM_WINDOWS 1 |
| 431 |
#define PATHSEP '\\' |
| 432 |
with |
| 433 |
#if DATA_FROM_SOURCECODE_FILES |
| 434 |
#define PLATFORM_WINDOWS 0 |
| 435 |
#define PATHSEP '/' |
| 436 |
#else |
| 437 |
#define PLATFORM_WINDOWS 1 |
| 438 |
#define PATHSEP '\\' |
| 439 |
#endif |
| 440 |
#endif |
| 441 |
This is because we hard-coded the relative paths to the data files with forward slashes. |
| 442 |
|
| 443 |
In `speech.cpp`, in the function `espeak_ng_Initialize`, we remove `setlocale`, |
| 444 |
because the locale of the entire program shouldn't be overwritten by a library: |
| 445 |
/* |
| 446 |
(Paul Boersma 20240426:) |
| 447 |
When using this library in an app, e.g. Praat, |
| 448 |
we should not set the locale, because it will interfere with the locale |
| 449 |
that has been set in praat_init(). |
| 450 |
To nevertheless experiment with setting the locale here, |
| 451 |
remove the space from "set locale" in the definition of SET_LOCALE |
| 452 |
and set USE_SET_LOCALE_IN_THIS_LIBRARY to 1 instead of 0. |
| 453 |
(The space is needed to be able to automatically determine that the name |
| 454 |
of the function does not appear in the present source file `speech.cpp`.) |
| 455 |
*/ |
| 456 |
#define SET_LOCALE set locale |
| 457 |
#define USE_SET_LOCALE_IN_THIS_LIBRARY 0 |
| 458 |
#if USE_SET_LOCALE_IN_THIS_LIBRARY |
| 459 |
if (SET_LOCALE(LC_CTYPE, "C.UTF-8") == NULL) { |
| 460 |
if (SET_LOCALE(LC_CTYPE, "UTF-8") == NULL) { |
| 461 |
if (SET_LOCALE(LC_CTYPE, "en_US.UTF-8") == NULL) |
| 462 |
SET_LOCALE(LC_CTYPE, ""); |
| 463 |
} |
| 464 |
} |
| 465 |
#endif |
| 466 |
However, eSpeak does need Unicode knowledge to work correctly, |
| 467 |
so that iswalpha and all other isw* functions should be replaced |
| 468 |
with iswalpha_portable and so on. |
| 469 |
|
| 470 |
There is a bug in wavegen.cpp, where it reads |
| 471 |
MarkerEvent(marker_type, q[1], q[2], q[3], out_ptr); |
| 472 |
The problem here is that q[2] and q[3] are of type intptr_t, |
| 473 |
whereas MarkerEvent expects int arguments. This is no problem |
| 474 |
on 32-bit systems, but on 64-bit systems the higher 4 bytes of q[2] are discarded. |
| 475 |
On little-endian systems, these higher 4 bytes are the last 4 bytes, |
| 476 |
and these rarely contain any relevant phoneme codes, so the problem rarely surfaces; |
| 477 |
however, on big-endian systems the higher 4 bytes are the first 4 bytes, |
| 478 |
so that all phoneme codes are in effect lost. A correct version is: |
| 479 |
MarkerEvent(marker_type, q[1], * (int *) & q[2], * ((int *) & q[2] + 1), out_ptr); |
| 480 |
On 64-bit systems this splits up q[2] into two ints (in correct order), |
| 481 |
and on 32-bit systems * ((int *) & q[2] + 1) is actually q[3], which is also correct. |
| 482 |
MarkerEvent() itself pastes the two ints together again, in correct order. |
| 483 |
|
| 484 |
#include "speak_lib.h" |
| 485 |
#include "encoding.h" |
| 486 |
#include "ucd.h" |
| 487 |
|
| 488 |
#undef INCLUDE_MBROLA |
| 489 |
#undef PLATFORM_POSIX |
| 490 |
#undef PLATFORM_WINDOWS |
| 491 |
#undef USE_NANOSLEEP |
| 492 |
|