| 1 | # Adding or Improving a Language |
| 2 | |
| 3 | - [Considerations Before Preparation](#considerations-before-preparation) |
| 4 | - [Language Tag](#language-tag) |
| 5 | - [Language Family](#language-family) |
| 6 | - [Accent (optional)](#accent-optional) |
| 7 | - [Configuration Files](#configuration-files) |
| 8 | - [Makefile.am file](#makefileam-file) |
| 9 | - [Phonemes file](#phonemes-file) |
| 10 | - [Language File](#language-file) |
| 11 | - [Phoneme Definition File](#phoneme-definition-file) |
| 12 | - [Dictionary Files](#dictionary-files) |
| 13 | - [Building Phonemes](#building-phonemes) |
| 14 | - [Adding tests](#adding-tests) |
| 15 | - [Program Code](#program-code) |
| 16 | - [Compiling Rules File for Debugging](#compiling-rules-file-for-debugging) |
| 17 | - [Improving a Language](#improving-a-language) |
| 18 | |
| 19 | ---------- |
| 20 | |
| 21 | ## Considerations Before Preparation |
| 22 | |
| 23 | |
| 24 | Most of the work doesn't need any programming knowledge, but, to get immediate |
| 25 | feedback, by running and testing eSpeak, |
| 26 | you should be able to [build](../README.md#building) it. |
| 27 | |
| 28 | You also have to understand the language main concepts, be aware of its features, |
| 29 | and have to have patience and attention to detail. |
| 30 | Wikipedia is a good source of basic phonetic information, e.g. about |
| 31 | [vowels](http://en.wikipedia.org/wiki/Vowel) and |
| 32 | [consonants](https://en.wikipedia.org/wiki/Consonant). |
| 33 | |
| 34 | In many cases it should be fairly easy to add a rough implementation of |
| 35 | a new language, hopefully enough to be intelligible. After that it's a |
| 36 | gradual process of improvement. |
| 37 | |
| 38 | ### Language Tag |
| 39 | |
| 40 | The language is identified using the |
| 41 | [BCP 47](https://en.wikipedia.org/wiki/IETF_language_tag) language tag. |
| 42 | The list of valid tags originate from various standards and have been combined |
| 43 | into the |
| 44 | [IANA Language Subtag Registry](http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry). |
| 45 | |
| 46 | These language tags are used to specify the language, such as: |
| 47 | |
| 48 | * `fr` (French) -- The [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) |
| 49 | 2-letter language code for the language. |
| 50 | |
| 51 | __NOTE:__ BCP 47 uses ISO 639-1 codes for languages that are allocated |
| 52 | 2-letter codes (e.g. using `en` instead of `eng`). |
| 53 | |
| 54 | * `yue` (Cantonese) -- The [ISO 639-3](https://en.wikipedia.org/wiki/ISO_639-3) |
| 55 | 3-letter language codes for the language. |
| 56 | |
| 57 | * `ta-Arab` (Tamil written in the Arabic alphabet) -- The |
| 58 | [ISO 15924](https://en.wikipedia.org/wiki/ISO_15924) 4-letter script code. |
| 59 | |
| 60 | __NOTE:__ Where the script is the primary script for the language, the script |
| 61 | tag should be omitted. |
| 62 | |
| 63 | ### Language Family |
| 64 | |
| 65 | The languages are grouped by the closest language family the language belongs. |
| 66 | These language families are defined in |
| 67 | [ISO 639-5](https://en.wikipedia.org/wiki/ISO_639-5). See also Wikipedia's |
| 68 | [List of language families](https://en.wiktionary.org/wiki/Wiktionary:List_of_families) |
| 69 | for more details. |
| 70 | |
| 71 | For example, the Celtic languages (Welsh, Irish Gaelic, Scottish Gaelic, etc.) |
| 72 | are listed under the `cel` language family code. |
| 73 | |
| 74 | ### Accent (optional) |
| 75 | |
| 76 | If necessary, the language tags are also used to specify the accent or dialect of a language, |
| 77 | such as: |
| 78 | |
| 79 | * `es-419` (Spanish (Latin America)) -- The |
| 80 | [UN M.49](https://en.wikipedia.org/wiki/UN_M.49) 3-number region codes. |
| 81 | |
| 82 | * `fr-CA` (French (Canada)) -- Using the |
| 83 | [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) 2-letter region codes. |
| 84 | |
| 85 | * `en-GB-scotland` (English (Scotland)) -- This is using the BCP 47 variant |
| 86 | tags. |
| 87 | |
| 88 | * `en-GB-x-rp` (English (Received Pronunciation)) -- This is using the |
| 89 | [bcp47-extensions](https://raw.githubusercontent.com/espeak-ng/bcp47-data/master/bcp47-extensions) |
| 90 | language tags for accents that cannot be described using the available |
| 91 | BCP 47 language tags. |
| 92 | |
| 93 | __NOTE:__ If the accent you are trying to describe cannot be specified using |
| 94 | the above system, raise an issue in the |
| 95 | [bcp47-data](https://github.com/rhdunn/bcp47-data) project and a private use |
| 96 | tag will be defined for that accent. |
| 97 | |
| 98 | ## Configuration Files |
| 99 | |
| 100 | To add new language, you have to create or edit following files: |
| 101 | |
| 102 | |path/file |action | |
| 103 | |------------------------------|-----------------------------| |
| 104 | | Makefile.am |[edit](#makefileam-file) | |
| 105 | | espeak-ng-data/lang/roa/fr |[create](#language-file) | |
| 106 | | phsource/phonemes |[edit](#phonemes-file) | |
| 107 | | phsource/ph_french |[create](#phoneme-definition-file) (optional) | |
| 108 | | dictsource/fr_list |[create](#dictionary-files) | |
| 109 | | dictsource/fr_rules |[create](#dictionary-files) | |
| 110 | | dictsource/fr_extra |create (optional) | |
| 111 | |
| 112 | where: |
| 113 | |
| 114 | * __french__ is name of the newly created language |
| 115 | * __fr__ is the code of this language |
| 116 | * __roa__ is the family of this language |
| 117 | |
| 118 | |
| 119 | ### Makefile.am File |
| 120 | |
| 121 | `Makefile.am` is build configuration file. It should be edited if you add |
| 122 | new language text-to-phoneme translation rules or set of sounds (phonemes). |
| 123 | Usually you have to add necessary entries for new language, but may not need if |
| 124 | you add new dialect for existing language. |
| 125 | |
| 126 | Search for configuration of existing languages (e.g. English) |
| 127 | and add similar lines for your language in following sections. |
| 128 | E.g. for French: |
| 129 | |
| 130 | dictionaries: \ |
| 131 | ... |
| 132 | espeak-ng-data/fr_dict \ |
| 133 | ... |
| 134 | |
| 135 | fr: espeak-ng-data/fr_dict |
| 136 | espeak-ng-data/fr_dict: dictsource/fr_list dictsource/fr_rules dictsource/fr_extra dictsource/fr_emoji |
| 137 | ... |
| 138 | |
| 139 | Note, that you don't need to add `fr_extra` or `fr_emoji` reference in the last group, if your language doesn't have this file. |
| 140 | |
| 141 | ### Language File |
| 142 | |
| 143 | E.g. `espeak-ng-data/lang/roa/fr` is the language file for French. |
| 144 | This gives the language name and may set some options. |
| 145 | |
| 146 | Each language needs a language file in `espeak-ng-data/lang` grouped by the |
| 147 | [language family](#language-family). The filename of the default voice for a |
| 148 | language should be the same as the language code (e.g. `fr` for French). |
| 149 | |
| 150 | The simplest voice file would contain just 2 lines to give the language |
| 151 | name (from the |
| 152 | [IANA Language Subtag Registry](https://github.com/rhdunn/bcp47-data/blob/master/language-subtag-registry) |
| 153 | and language code, e.g.: |
| 154 | |
| 155 | name French |
| 156 | language fr |
| 157 | |
| 158 | This language code specifies which phoneme table and dictionary to use |
| 159 | (i.e. `phonemetable fr` and `espeak-ng-data/fr_dict`) to be used. If |
| 160 | needed, these can be overridden by `phonemes` and `dictionary` |
| 161 | attributes in the voice file. For example you may want to start the |
| 162 | implementation of a new language by using the phoneme table of an |
| 163 | existing language. |
| 164 | |
| 165 | Details of the contents of language files are given in [Voices](voices.md). |
| 166 | |
| 167 | ### Phonemes File |
| 168 | |
| 169 | Open file `phsource/phonemes` and add following lines |
| 170 | |
| 171 | 1. Set of standard (already defined) phonemes for languge |
| 172 | |
| 173 | ``` |
| 174 | ... |
| 175 | phonemetable fr base |
| 176 | ... |
| 177 | ``` |
| 178 | where: |
| 179 | _..._ means other existing lines of the configuration file and |
| 180 | _base_ is usually is `base1` or code of other (already defined) language: |
| 181 | |
| 182 | * `base` phoneme table contains only definitions of some "control" phonemes |
| 183 | such as stress marks and pauses defined in top of the `phonemes` file. |
| 184 | |
| 185 | * `base1` includes `base` and also has basic set of vowels and consonants |
| 186 | defined under `phonemetable base1` section in `phonemes` file. |
| 187 | |
| 188 | * `base2` has additional phonemes (mostly diphones) included from `ph_base2` file. |
| 189 | |
| 190 | * Other language e.g. `en` has all phonemes defined in its corresponding phoneme |
| 191 | definition file e.g. `phsourc/ph_english` for English language. |
| 192 | |
| 193 | 2. Optionally, if you have customized phonemes in [Phoneme Definition File](#phoneme-definition-file), |
| 194 | add additional line: to include it: |
| 195 | |
| 196 | ``` |
| 197 | ... |
| 198 | include ph_french |
| 199 | ... |
| 200 | ``` |
| 201 | For example, if `phsource/phonemes` has following lines: |
| 202 | |
| 203 | phonemetable fr base |
| 204 | include ph_french |
| 205 | |
| 206 | it defines a phoneme table `fr` which inherits phoneme definitions from |
| 207 | `base` table and adds new definitions or overrides existing |
| 208 | definitions of `base` phonemes from the `phonemes/ph_french` file. |
| 209 | |
| 210 | ### Phoneme Definition File |
| 211 | |
| 212 | If you decide to customize definitions of phonemes (vowel and consonant |
| 213 | sounds) for the language, then you have to create e.g. `phsource/ph_french` |
| 214 | phoneme definition file for French. |
| 215 | |
| 216 | The phonemes file for the language defines those additional phonemes |
| 217 | which are not inherited (generally the vowels and diphthongs, plus any |
| 218 | additional consonants that are needed), or phonemes whose definitions |
| 219 | differ from the inherited version (eg. the redefinition of a consonant). |
| 220 | |
| 221 | Usually it will contain mostly vowels. Most consonants will be inherited from the |
| 222 | common phoneme definitions in the _master phoneme file_: `phsource/phonemes` as |
| 223 | described in [Phonemes File](#phonemes-file) section above. |
| 224 | |
| 225 | Details of phonemes files are given in [Phoneme Tables](phontab.md). |
| 226 | |
| 227 | ### Building Phonemes |
| 228 | |
| 229 | To build the phoneme files, run: |
| 230 | |
| 231 | espeak-ng --compile-phonemes |
| 232 | |
| 233 | or: |
| 234 | |
| 235 | make phsource/phonemes.stamp |
| 236 | |
| 237 | For many languages, the consonant phonemes which are already available |
| 238 | in eSpeak, together with the available vowel files which can be used to |
| 239 | define vowel phonemes, will be sufficient. At least for an initial |
| 240 | implementation. |
| 241 | |
| 242 | ### Dictionary Files |
| 243 | |
| 244 | There are usually two dictionary files, e.g. for French: |
| 245 | |
| 246 | * `dictsource/fr_list`. This contains pronunciations for numbers, letter and |
| 247 | symbol names, and words with exceptional pronunciations. It also gives |
| 248 | attributes such as "unstressed" and "pause" to some common words. |
| 249 | The `fr_list` file contains: |
| 250 | |
| 251 | * Pronunciations which exceptions to the rules in `fr_rules`, (e.g. foreign |
| 252 | names). |
| 253 | * Pronunciation of letter names, symbol names, and punctuation names. |
| 254 | * Pronunciation of numbers. |
| 255 | * Attributes for words. For example, common function words which should not |
| 256 | be stressed, or conjunctions which should be preceded by a pause. |
| 257 | |
| 258 | * `dictsource/fr_rules`. This contains the spelling-to-phoneme translation |
| 259 | rules. |
| 260 | |
| 261 | Details of the contents of the dictionary files are given in |
| 262 | [Dictionary](dictionary.md). |
| 263 | |
| 264 | The `fr_rules` and `fr_list` files are compiled to produce the |
| 265 | `espeak-ng-data/fr_dict` file, which eSpeak uses when it is speaking. |
| 266 | |
| 267 | Once the language's phonemes have been defined, then pronunciation |
| 268 | dictionary data can be produced in order to translate the language's |
| 269 | source text into phonemes. This consists of two source files: |
| 270 | `fr_rules` (the spelling to phoneme rules) and `fr_list` (an |
| 271 | exceptions list, and attributes of certain words). The corresponding |
| 272 | compiled data file is `espeak-ng-data/fr_dict` which is produced from |
| 273 | the `fr_rules` and `fr_list` sources by the command: |
| 274 | |
| 275 | espeak-ng --compile=fr |
| 276 | |
| 277 | or by: |
| 278 | |
| 279 | make fr |
| 280 | |
| 281 | ### Adding tests |
| 282 | |
| 283 | All languages require automated tests to make sure accidental changes |
| 284 | in program code don't change how the languages sound. |
| 285 | |
| 286 | Tests are run with `make check`. It will print an error if a language |
| 287 | is missing tests. |
| 288 | |
| 289 | Most tests are bash scripts in tests/ and follow the syntax: |
| 290 | <test name> <language code> <expected result> <input> |
| 291 | |
| 292 | Depending on the test, expected result can be a phoneme string, an md5 hash or something else. |
| 293 | |
| 294 | To add a test: |
| 295 | |
| 296 | 1. First add a test line with arbitrary expected result. |
| 297 | Example line in tests/language-phonemes.test: |
| 298 | test_phwav fi this_should_fail "ma na Na pa ba ta da" |
| 299 | |
| 300 | 2. run `make check` to see expected and actual results: |
| 301 | testing fi |
| 302 | 1c1 |
| 303 | < this_should_fail |
| 304 | --- |
| 305 | > 7541590a29e2392b827d9f1563e6579774fb15ea |
| 306 | |
| 307 | 3. change the expected result in the test: |
| 308 | test_phwav fi 7541590a29e2392b827d9f1563e6579774fb15ea "ma na Na pa ba ta da" |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | ## Program Code |
| 314 | |
| 315 | The behaviour of the eSpeak program is controlled by various options |
| 316 | such as: |
| 317 | |
| 318 | * Default rules for which syllable of a word has the main stress. |
| 319 | * Relative lengths and amplitude of vowels in stressed and unstressed syllables. |
| 320 | * Which intonation tunes to use. |
| 321 | * Rules for speaking numbers. |
| 322 | |
| 323 | Most of these options can be set in the voice file in espeak-ng-data/lang folder (see [Voices](voices.md)). |
| 324 | However some advanced options may be needed to add in source code in the function `SelectTranslator()` |
| 325 | of the [tr_languages.c](https://github.com/espeak-ng/espeak-ng/blob/master/src/libespeak-ng/tr_languages.c) |
| 326 | file. |
| 327 | |
| 328 | ## Compiling Rules File for Debugging |
| 329 | |
| 330 | When `espeak-ng` is invoked with `-X` parameter, it shows more detailed trace of |
| 331 | chosen language rules for pronunciation. This trace can show line numbers also, |
| 332 | if language is compiled with `--compile-debug` option. |
| 333 | |
| 334 | To do this, go to `espeak-ng` project root folder, then: |
| 335 | |
| 336 | cd dictsource |
| 337 | espeak-ng --compile-debug=en |
| 338 | |
| 339 | When invoked in following way: |
| 340 | |
| 341 | espeak-ng -ven -X "Test." |
| 342 | |
| 343 | It will show: |
| 344 | |
| 345 | Translate 'test' |
| 346 | 1 5965: t [t] |
| 347 | |
| 348 | 1 2104: e [E] |
| 349 | |
| 350 | 1 5725: s [s] |
| 351 | |
| 352 | 1 5965: t [t] |
| 353 | |
| 354 | t'Est |
| 355 | |
| 356 | ## Improving a Language |
| 357 | |
| 358 | Listen carefully to the eSpeak voice. Try to identify what sounds wrong |
| 359 | and what needs to be improved. |
| 360 | |
| 361 | * Make the spelling-to-phoneme translation rules more accurate, including |
| 362 | the position of stressed syllables within words. Some languages are easier |
| 363 | than others. I expect most are easier than English. |
| 364 | |
| 365 | * Improve the sounds of the phonemes. It may be that a phoneme should sound |
| 366 | different depending on adjacent sounds, or whether it's at the start or the |
| 367 | end of a word, between vowels, in a stressed or unstressed syllable, etc. |
| 368 | This may consist of making small adjustments to vowel and diphthong quality |
| 369 | or length, or adjusting the strength of consonants. Phoneme definitions can |
| 370 | include conditional statements which can be used to change the sound of a |
| 371 | phoneme depending on its environment. Bigger changes may be recording new or |
| 372 | replacement consonant sounds, or may even need program code to implement new |
| 373 | types of sounds. |
| 374 | |
| 375 | * Some common words should be added to the dictionary (the `fr_list` file for |
| 376 | the language) with an "unstressed" attribute `$u` or `$u+` (e.g. in English, |
| 377 | words such as "the", "is", "had", "my", "she", "of", "in", "some"), or should |
| 378 | be preceded by a short pause (such as "and", "but", "which"), or have other |
| 379 | attributes, in order to make the speech flow better. |
| 380 | |
| 381 | * Improve the rhythm of the speech by adjusting the relative lengths of vowels |
| 382 | in different contexts, e.g. stressed/unstressed syllable, or depending on the |
| 383 | following phonemes. This is important for making the speech sound good for the |
| 384 | language. |
| 385 | |
| 386 | * Make new intonation "tunes" for statements or questions (see |
| 387 | [Intonation](intonation.md)). |
| 388 | |
| 389 | For most of the eSpeak languages, I do not speak or understand the language, and I |
| 390 | do not know how it should sound. I can only make improvements as a result of |
| 391 | feedback from speakers of that language. If you want to help to improve a |
| 392 | language, listen carefully and try to identify individual errors, either in |
| 393 | the spelling-to-phoneme translation, the position of stressed syllables within |
| 394 | words, or the sound of phonemes, or problems with rhythm and vowel lengths. |