| 1 | # Text to Phoneme Translation |
| 2 | |
| 3 | - [Translation Files](#translation-files) |
| 4 | - [Phoneme names](#phoneme-names) |
| 5 | - [Pronunciation Rules](#pronunciation-rules) |
| 6 | - [Rule Groups](#rule-groups) |
| 7 | - [Letter Groups](#letter-groups) |
| 8 | - [Rules](#rules) |
| 9 | - [Special Characters in \<phoneme string\>](#special-characters-in-phoneme-string) |
| 10 | - [Special Characters in Both \<pre\> and \<post\> ](#special-characters-in-both-pre-and-post) |
| 11 | - [Special Characters Only in \<pre\> ](#special-characters-only-in-pre) |
| 12 | - [Special Characters Only in \<post\> ](#special-characters-only-in-post) |
| 13 | - [Pronunciation Dictionary List](#pronunciation-dictionary-list) |
| 14 | - [Multiple Words](#multiple-words) |
| 15 | - [Special Characters in \<phoneme string\>](#special-characters-in-phoneme-string-1) |
| 16 | - [Flags](#flags) |
| 17 | - [Translating a Word to Another Word](#translating-a-word-to-another-word) |
| 18 | - [Conditional Rules](#conditional-rules) |
| 19 | - [Numbers and Character Names](#numbers-and-character-names) |
| 20 | - [Letter Names](#letter-names) |
| 21 | - [Numbers](#numbers) |
| 22 | - [Character Substitution](#character-substitution) |
| 23 | - [(Re)definition of character groups](#redefinition-of-character-groups) |
| 24 | |
| 25 | ---------- |
| 26 | |
| 27 | ## Translation Files |
| 28 | |
| 29 | There is a separate set of pronunciation files for each language, their names |
| 30 | starting with the language name. |
| 31 | |
| 32 | There are two separate methods for translating words into phonemes: |
| 33 | |
| 34 | * Pronunciation Rules. These are an attempt to define the pronunciation rules |
| 35 | for the language. The source file is: `<language>_rules` (e.g. `en_rules`). |
| 36 | |
| 37 | * Lookup Dictionary. A list of individual words and their pronunciations and/or |
| 38 | various other properties. The source files are: `<language>_list` (e.g. |
| 39 | `en_list`) and optionally `<language>_extra` (e.g. `en_extra`). |
| 40 | |
| 41 | These files are compiled into the file `<language>_dict` in the espeak-ng-data |
| 42 | directory (e.g. `espeak-ng-data/en_dict`). |
| 43 | |
| 44 | ## Phoneme names |
| 45 | |
| 46 | Each of the language's phonemes is represented by a mnemonic of 1, 2, 3, |
| 47 | or 4 characters. Together with a number of utility codes (eg. stress |
| 48 | marks and pauses), these are defined in the phoneme data file. |
| 49 | |
| 50 | The utility 'phonemes' are: |
| 51 | |
| 52 | | Symbol | Description | |
| 53 | |--------|-------------| |
| 54 | | `'` | primary stress | |
| 55 | | `,` | secondary stress | |
| 56 | | `%` | unstressed syllable | |
| 57 | | `=` | put the primary stress on the preceding syllable | |
| 58 | | `_:` | short pause | |
| 59 | | `_` | a shorter pause | |
| 60 | | <code>|</code> | use to separate two adjacent characters, to prevent them from being considered as a single multi-character phoneme | |
| 61 | | <code>||</code> | indicates a word boundary within a phonetic string | |
| 62 | |
| 63 | It is not necessary to specify the stress of every syllable. Stress |
| 64 | markers are only needed in order to change the effect of the language's |
| 65 | default stress rule. |
| 66 | |
| 67 | The phonemes which are used to represent a language's sounds are based |
| 68 | loosely on the [Kirshenbaum (ASCII-IPA)](phonemes/kirshenbaum.md) |
| 69 | representation of the International Phonetic Alphabet. |
| 70 | |
| 71 | Full list of commonly used phonemes can be found in the `phsource/phonemes` |
| 72 | file. |
| 73 | |
| 74 | ## Pronunciation Rules |
| 75 | |
| 76 | The rules in the `<language>_rules` file specify the phonemes which are |
| 77 | used to pronounce each letter, or sequence of letters. Some rules only |
| 78 | apply when the letter or letters are preceded by, or followed by, other |
| 79 | specified letters. |
| 80 | |
| 81 | To find the pronunciation of a word, the rules are searched and any |
| 82 | which match the letters at the in the word are given a score depending |
| 83 | on how many letters are matched. The pronunciation from the best |
| 84 | matching rule is chosen. The pointer into the source word is then |
| 85 | advanced past those letters which have been matched and the process is |
| 86 | repeated until all the letters of the word have been processed. |
| 87 | |
| 88 | ### Rule Groups |
| 89 | |
| 90 | The rules are organized in groups, each starting with a `.group` line: |
| 91 | |
| 92 | * `.group <character>` |
| 93 | A group for each letter or character. |
| 94 | |
| 95 | * `.group <2 characters>` |
| 96 | Optional groups for some common 2 letter combinations. This is only needed, |
| 97 | for efficiency, in cases where there are many rules for a particular letter. |
| 98 | They would not be needed for a language which has regular spelling rules. The |
| 99 | first character can only be an ascii character (less than 0x80). |
| 100 | |
| 101 | **notes about rule groups** |
| 102 | |
| 103 | When matching a word, firstly the 2-letter group for the two letters at |
| 104 | the current position in the word (if such a group exists) is searched, |
| 105 | and then the single-letter group. The highest scoring rule in either of |
| 106 | those two groups is used. |
| 107 | |
| 108 | * `.group` |
| 109 | A group for other characters which don't have their own group. |
| 110 | |
| 111 | * `.replace` |
| 112 | See section [Character Substitution](#character-substitution). |
| 113 | |
| 114 | ### Letter groups |
| 115 | |
| 116 | Specific group of rules is declaration of letter sequences with some common |
| 117 | feature of letters for particular language. It may be used as a placeholder |
| 118 | of prefixes/infixes of words (in prerules) or infixed/postfixes in (postrules). |
| 119 | |
| 120 | * `.L<nn>` |
| 121 | Defines a group of letter sequences, any of which can match with `Lnn` in a |
| 122 | pre or post rule (see below). nn is a 2 digit decimal number in the range 01 |
| 123 | to 94. e.g.: |
| 124 | `.L01 b bl br pl pr` |
| 125 | |
| 126 | **notes about letter groups** |
| 127 | |
| 128 | There can be up to 200 items in one letter group. |
| 129 | |
| 130 | When matching a word, firstly the group containing most letters is checked at |
| 131 | the current position in the word (if such a group exists), then shorter ones |
| 132 | till to the single-letter groups. The highest scoring rule of matching group is used. |
| 133 | |
| 134 | `~` Letter in letter group means, that there can be no letter in this group |
| 135 | in the pre- or post- rule. |
| 136 | |
| 137 | _Example with prerule group:_ |
| 138 | |
| 139 | ``` |
| 140 | .L01 ~ b c |
| 141 | .group a |
| 142 | L01) a i // A |
| 143 | ``` |
| 144 | following rules will match for words: |
| 145 | |
| 146 | |Word |Phonetic spelling| |
| 147 | |-----|-----------------| |
| 148 | |base |bice | |
| 149 | |case |cice | |
| 150 | |ace |ice | |
| 151 | |
| 152 | _Example with postrule group:_ |
| 153 | |
| 154 | ``` |
| 155 | .L01 ~ b c |
| 156 | .group a |
| 157 | a (L01 u |
| 158 | ``` |
| 159 | |Word |Phonetic spelling| |
| 160 | |-----|-----------------| |
| 161 | |tab |tub | |
| 162 | |mac |muc | |
| 163 | |tea |teu | |
| 164 | |
| 165 | ### Rules |
| 166 | |
| 167 | Each rule is on separate line, and has the syntax: |
| 168 | |
| 169 | [<pre>)] <match> [(<post>] <phoneme string> |
| 170 | |
| 171 | * characters in `<pre>)` group are already spelled and "consumed" |
| 172 | * characters in `<match>` group are ones which will be spelled and "consumed" |
| 173 | by best matching rule |
| 174 | * characters in `(<post>` group will not be spelled and produced, but can be |
| 175 | used as reference to choose matching rule |
| 176 | |
| 177 | Note that `<match>` group can be longer than name of character group, but cannot |
| 178 | be shorter. |
| 179 | |
| 180 | Example: |
| 181 | |
| 182 | .group o |
| 183 | o 0 // "o" is pronounced as [0], one letter consumed |
| 184 | oo u: // but "oo" is pronounced as [u:], two letters consumed |
| 185 | b) oo (k U // pronounced as [U], two letters consumed |
| 186 | |
| 187 | |
| 188 | `oo` is pronounced as `[u:]`, but when also preceded by `b` and followed |
| 189 | by `k`, it is pronounced `[U]`. If |
| 190 | |
| 191 | In the case of a single-letter group, the first character of `<match>` |
| 192 | much be the group letter. In the case of a 2-letter group, the first two |
| 193 | characters of `<match>` must be the group letters. The second and third |
| 194 | rules above may be in either .group o or .group oo |
| 195 | |
| 196 | Alphabetic characters in the `<pre>`, `<match>`, and `<post>` parts must |
| 197 | be lower case, and matching is case-insensitive. Some upper case letters |
| 198 | are used in `<pre>` and `<post>` with special meanings. |
| 199 | |
| 200 | ### Special characters in \<phoneme string\>: |
| 201 | |
| 202 | * `_^_<language code>` |
| 203 | Translate using a different language. |
| 204 | |
| 205 | If this rule is selected when translating a word, then the translation is |
| 206 | aborted and the word is re-translated using the specified different language. |
| 207 | `<language code>` may be upper or lower case. This can be used to recognise |
| 208 | certain letter combinations as being foreign words and to use the foreign |
| 209 | pronunciation for them. e.g.: |
| 210 | |
| 211 | th (_ _^_EN |
| 212 | |
| 213 | indicates that a word which ends in `th` is translated using the English |
| 214 | translation rules and spoken with English phonemes. |
| 215 | |
| 216 | ### Special Characters in both \<pre\> and \<post\> |
| 217 | |
| 218 | | Symbol | Description | |
| 219 | |-------------|-------------| |
| 220 | | `_` | Beginning or end of a word (or a hyphen). | |
| 221 | | `-` | Hyphen. | |
| 222 | | `A` | Any vowel[<sup>1</sup>](#redefinition-of-character-groups). | |
| 223 | | `C` | Any consonant [<sup>1</sup>](#redefinition-of-character-groups). | |
| 224 | | `B H F G Y` | These may indicate other sets of characters[<sup>1</sup>](#redefinition-of-character-groups). | |
| 225 | | `L<nn>` | Any of the sequence of characters defined as a letter grup. | |
| 226 | | `D` | Any digit. | |
| 227 | | `K` | Not a vowel (i.e. a consonant or word boundary or non-alphabetic character). | |
| 228 | | `X` | There is no vowel until the word boundary. | |
| 229 | | `Z` | A non-alphabetic character. | |
| 230 | | `%` | Doubled (placed before a character in \<pre\> and after it in \<post\>. | |
| 231 | | `/` | The following character is treated literally. | |
| 232 | | `\xxx` | Character is written as by 3 digit octal value of `xxx`| |
| 233 | | `@` | One syllable (i.e. at least one vowel or diphthong) | |
| 234 | |
| 235 | |
| 236 | |
| 237 | Examples of rules: |
| 238 | ``` |
| 239 | _) a A // "a" at the start of a word |
| 240 | a (CC A // "a" followed by two consonants |
| 241 | a (C% A // "a" followed by a double consonant (the same letter twice) |
| 242 | a (/% A // "a" followed by a percent sign |
| 243 | %C) a A // "a" preceded by a double consonants |
| 244 | @@) bi bI // "bi" preceded by at least two syllables |
| 245 | @@a) bi bI // "bi" preceded by at least 2 syllables and following 'a' |
| 246 | |
| 247 | @) ly (_S2 lI // "ly", at end of a word with at least one other |
| 248 | // syllable, is a suffix pronounced [lI]. Remove |
| 249 | // it and retranslate the word. |
| 250 | |
| 251 | _) un (@P2 %Vn // "un" at the start of a word is an unstressed |
| 252 | // prefix pronounced [Vn] |
| 253 | ``` |
| 254 | |
| 255 | Note, that: |
| 256 | |
| 257 | 1. Matching characters in the \<pre\> part do not affect the syllable counting. |
| 258 | 1. Word end mark can't be used with syllable mark. E.g. `_@)` or `@_` will not work, |
| 259 | but you can use `@) ... (+` or `... (@+` to make rule with only one syllable prevail |
| 260 | rule with more syllables. |
| 261 | |
| 262 | ### Special characters only in \<pre\>: |
| 263 | |
| 264 | | Symbol | Description | |
| 265 | |--------|-------------| |
| 266 | | `&` | A syllable which may be stressed (i.e. is not defined as unstressed). | |
| 267 | | `V` | Matches only if a previous word has indicated that a verb form is expected. | |
| 268 | | `xxJ` | Skip letters until `xx`. Simple `xx` means start of current word. `xx_yy` means `xx` as end of previous and `yy` as start of current word. If necessary, more than one `J` can be used, and `Lxx` group as letter mark. | |
| 269 | |
| 270 | e.g. |
| 271 | |
| 272 | get_J) a i // for `get ada` will say `get adi` |
| 273 | setJ) a o // for `set ada` will say `set oda` |
| 274 | ge_tJ) a i: // for `ge tada` will say `get adi:` |
| 275 | |
| 276 | |
| 277 | ### Special characters only in \<post\>: |
| 278 | |
| 279 | | Symbol | Description | |
| 280 | |-------------|-------------| |
| 281 | | `+` | Force an increase in the score in this rule by 20 points (may be repeated for more effect). | |
| 282 | | `<` | Force a decrease in the score in this rule by 20 points (may be repeated for more effect). | |
| 283 | | `Jxx` | Skip letters until `xx`. Simple `xx` means end of current word. `xx_yy` means `xx` as end of current and `yy` as start of next word. If necessary, more than one `J` can be used, and `Lxx` group as letter mark. | |
| 284 | | `S<number>` | This number of matching characters are a standard suffix, remove them and retranslate the word. | |
| 285 | | `P<number>` | This number of matching characters are a standard prefix, remove them and retranslate the word. | |
| 286 | | `Lnn` | `nn` is a 2-digit decimal number in the range 01 to 20 Matches with any of the letter sequences which have been defined for letter group `nn` | |
| 287 | | `N` | Only use this rule if the word is not a retranslation after removing a suffix. | |
| 288 | | `#` | (English specific) change the next "e" into a special character "E" | |
| 289 | | `$noprefix` | Only use this rule if the word is not a retranslation after removing a prefix. | |
| 290 | | `$w_alt` | Only use this rule if the word is `$w_alt2` found in the `*_list` file with the `$w_alt3`, `$alt`, `$alt2` or `$alt3` attribute respectively. | |
| 291 | | `$p_alt` | Only use this rule if the part-word, `$p_alt2` up to and including the pre and `$p_alt3` match parts of this rule, is found in the `*_list` file with the `$alt`, `$alt2` or `$alt3` attribute respectively. | |
| 292 | |
| 293 | e.g. |
| 294 | |
| 295 | _) un (i ju: // ... except in words starting "uni" |
| 296 | _) un (inP2 ,Vn // ... but it is for words starting "unin" |
| 297 | a (J_get u // for `ada get` will say `uda get` |
| 298 | a (Jset e // for `ada set` will say `ade set` |
| 299 | a (Jg_et u: // for `adag et` will say `u:dag et` |
| 300 | |
| 301 | `S` and `P` must be at the end of the \<post\> string. |
| 302 | |
| 303 | `S<number>` may be followed by additional letters (e.g. `S2ei`). Some of |
| 304 | these are probably specific to English, but similar functions could be |
| 305 | made for other languages. |
| 306 | |
| 307 | `P<number>` may be followed by additional letters (e.g. `P3v`). |
| 308 | |
| 309 | | Symbol | Description | |
| 310 | |--------|-------------| |
| 311 | | `q` | Query the `*_list` file to find stress position or other attributes for the stem, but don't re-translate the word with the suffix removed. | |
| 312 | | `t` | Determine the stress pattern of the word *before* adding the suffix. | |
| 313 | | `d` | The previous letter may have been doubled when the suffix was added. | |
| 314 | | `e` | `e` may have been removed. | |
| 315 | | `i` | `y` may have been changed to `i`. | |
| 316 | | `v` | The suffix means the verb form of pronunciation should be used. | |
| 317 | | `f` | The suffix means the next word is likely to be a verb. | |
| 318 | | `m` | After this suffix has been removed, additional suffixes may be removed. | |
| 319 | | `t` | Determine the stress pattern of the word **before** adding the prefix. | |
| 320 | |
| 321 | ## Pronunciation Dictionary List |
| 322 | |
| 323 | The `<language>_list` file contains a list of words whose pronunciations are |
| 324 | given explicitly, rather than determined by the Pronunciation Rules. The |
| 325 | `<language>_extra` file, if present, is also used and it's contents are taken |
| 326 | as coming after those in `<language>_list`. |
| 327 | |
| 328 | Also the list can be used to specify the stress pattern, or other |
| 329 | properties, of a word. |
| 330 | |
| 331 | If the Pronunciation rules are applied to a word and indicate a standard |
| 332 | prefix or suffix, then the word is again looked up in Pronunciation |
| 333 | Dictionary List after the prefix or suffix has been removed. |
| 334 | |
| 335 | Lines in the dictionary list have the form: |
| 336 | |
| 337 | <word> [<phoneme string>] [<flags>] |
| 338 | |
| 339 | e.g. |
| 340 | |
| 341 | book bUk |
| 342 | |
| 343 | Rather than a full pronunciation, just the stress may be given, to |
| 344 | change where it would be otherwise placed by the Pronunciation Rules: |
| 345 | |
| 346 | berlin $2 // stress on second syllable |
| 347 | absolutely $3 // stress on third syllable |
| 348 | for $u // an unstressed word |
| 349 | |
| 350 | ### Multiple Words |
| 351 | |
| 352 | A pronunciation may also be specified for a group of words, when these |
| 353 | appear together. Up to four words may be given, enclosed in brackets. |
| 354 | This may be used for change the pronunciation or stress pattern when |
| 355 | these words occur together, |
| 356 | |
| 357 | (de jure) deI||dZ'U@rI2 // note || used as a word break in the phoneme string |
| 358 | |
| 359 | or to run them together, pronounced as a single word |
| 360 | |
| 361 | (of a) @v@ |
| 362 | |
| 363 | or to give them a flag when they occur together |
| 364 | |
| 365 | (such as) sVtS||a2z $pause // precede with a pause |
| 366 | |
| 367 | Hyphenated words in the `<language>_list` file must also be enclosed within |
| 368 | brackets, because the two parts are considered as separate words. |
| 369 | |
| 370 | ### Special characters in \<phoneme string\>: |
| 371 | |
| 372 | | Symbol | Description | |
| 373 | |----------------------|-------------| |
| 374 | | `_^_<language code>` | Translate using a different language. See explanation above. | |
| 375 | |
| 376 | ### Flags |
| 377 | |
| 378 | A word (or group of words) may be given one or more flags, either |
| 379 | instead of, or as well as, the phonetic translation. |
| 380 | |
| 381 | | Symbol | Description | |
| 382 | |----------------------|-------------| |
| 383 | | `$1` | Primary stress on the 1st syllable. | |
| 384 | | `$2` | Primary stress on the 2nd syllable. | |
| 385 | | `$3` | Primary stress on the 3rd syllable. | |
| 386 | | `$4` | Primary stress on the 4th syllable. | |
| 387 | | `$5` | Primary stress on the 5th syllable. | |
| 388 | | `$6` | Primary stress on the 6th syllable. | |
| 389 | | `$7` | Primary stress on the 7th syllable. | |
| 390 | | `$u` | The word is unstressed. In the case of a multi-syllable word, a slight stress is applied according to the default stress rules. | |
| 391 | | `$u1` | The word is unstressed, with a slight stress on its 1st syllable. | |
| 392 | | `$u2` | The word is unstressed, with a slight stress on its 2nd syllable. | |
| 393 | | `$u3` | The word is unstressed, with a slight stress on its 3rd syllable. | |
| 394 | | `$u+ $u1+ $u2+ $u3+` | As above, but the word has full stress if it's at the end of a clause. | |
| 395 | | `$pause` | Ensure a short pause before this word (eg. for conjunctions such as "and", some prepositions, etc). Does not apply for 1st, 2nd or last word of a sentence. | |
| 396 | | `$brk` | Ensure a very short pause before this word, shorter than $pause (eg. for some prepositions, etc). Does not apply for the last word of a sentence. | |
| 397 | | `$only` | The rule does not apply if a prefix or suffix has already been removed. | |
| 398 | | `$onlys` | As `$only`, except that a standard plural ending is allowed. | |
| 399 | | `$stem` | The rule only applies if a suffix has already been removed (i.e. word had to have suffix before). | |
| 400 | | `$strend` | Word is fully stressed if it's at the end of a clause. | |
| 401 | | `$strend2` | As $strend, but the word is also stressed if followed only by unstressed word(s). | |
| 402 | | `$unstressend` | Word is unstressed if it's at the end of a clause. | |
| 403 | | `$abbrev` | This has two meanings. If there is no phoneme string: Speak the word as individual letters, even if it contains a vowel (eg. "abc" should be spoken as "a" "b" "c"). If there is a phoneme string: This word is capitalized because it is an abbreviation and capitalization does not indicate emphasis (if the "emphasize all-caps" is on). | |
| 404 | | `$double` | Cause a doubling of the initial consonant of the following word (used e.g. for Italian and Finnish). | |
| 405 | | `$alt $alt2 .. $alt7`| These 7 groups are language specific. Their use should be described in the language's `*_list` file. `$alt` and `$alt1` are synonyms.| |
| 406 | | `$combine` | This word is treated as though it is combined with the following word with a hyphen. This may be subject to further conditions for certain languages. | |
| 407 | | `$dot` | Ignore a `.` after this word even when followed by a capital letter (e.g. `Mr.` and `Dr.`). | |
| 408 | | `$hasdot` | Use this pronunciation if the word is followed by a dot. (This attribute also implies `$dot`). | |
| 409 | | `$max3` | Limit to 3 repetitions in pronunciation.| |
| 410 | | `$text` | Word translates to replacement text, not phonemes.| |
| 411 | | `$verbf` | The following word is probably a verb. | |
| 412 | | `$verbsf` | The following word is probably a verb if it has an "s" suffix. | |
| 413 | | `$nounf` | The following word is probably a noun. | |
| 414 | | `$pastf` | The following word is probably past tense. | |
| 415 | | `$verb` | Use this pronunciation if it's a verb, i.e. previously processed word had `$verbf` or `$verbsf` set.| |
| 416 | | `$noun` | Use this pronunciation if it's a noun, i.e. previously processed word had `$nounf` set.| |
| 417 | | `$past` | Use this pronunciation if it's past tense, i.e. previously processed word had `$pastf` set.| |
| 418 | | `$verbextend` | Extend the influence of `$verbf` and `$verbsf` until a word with $verb or $nounf is encountered. | |
| 419 | | `$capital` | Use this pronunciation if the word has initial capital letter (eg. polish v Polish). | |
| 420 | | `$allcaps` | Use this pronunciation if the word is all capitals. | |
| 421 | | `$accent` | Used for the pronunciation of a single alphabetic character. The character name is spoken as the base-letter name plus the accent (diacritic) name. e.g. It can be used to specify that "â" is spoken as "a" "circumflex". | |
| 422 | | `$accent_before` | used with accent names, say this accent name before the letter name. | |
| 423 | | `$atstart` | Use this pronunciation if it's at the start of a clause. | |
| 424 | | `$atend` | Use this pronunciation if it's at the end of a clause. | |
| 425 | | `$sentence` | The rule only applies if the clause includes end-of-sentence (i.e. terminator is {. ? !} not {, ; :}). For example, `$atend $sentence` means that the rule only applies at the end of a sentence. | |
| 426 | | `$native` | Not used, if switched to other translation. | |
| 427 | |
| 428 | The last group are probably English specific, but something similar may |
| 429 | be useful in other languages. They are a crude attempt to improve the |
| 430 | accuracy of pairs like ob'ject (verb) v 'object (noun) and read |
| 431 | (present) v read (past). |
| 432 | |
| 433 | The dictionary list is searched from bottom to top. The first match that |
| 434 | satisfies any conditions is used (i.e. the one lowest down the list). So |
| 435 | if we have: |
| 436 | |
| 437 | to t@ // unstressed version |
| 438 | to tu: $atend // stressed version |
| 439 | |
| 440 | then if `to` is at the end of the clause, we get `[tu:]`, if not then we |
| 441 | get `[t@]`. |
| 442 | |
| 443 | ### Translating a Word to Another Word |
| 444 | |
| 445 | Rather than specifying the pronunciation of a word by a phoneme string, |
| 446 | you can specify another "sounds like" word. |
| 447 | |
| 448 | Use the attribute `$text` e.g. |
| 449 | |
| 450 | cough coff $text |
| 451 | |
| 452 | Alternatively, use the command `$textmode` on a line by itself to turn this on |
| 453 | for all subsequent entries in the file, until it's turned off by |
| 454 | `$phonememode`. e.g. |
| 455 | |
| 456 | $textmode |
| 457 | cough coff |
| 458 | through threw |
| 459 | $phonememode |
| 460 | |
| 461 | This feature cannot be used for the special entries in the `*_list` files which |
| 462 | start with an underscore, such as numbers. |
| 463 | |
| 464 | Currently `textmode` entries are only recognized for complete words, and |
| 465 | not for stems from which a prefix or suffix has been removed (e.g. |
| 466 | the word "coughs" would not match the example above). |
| 467 | |
| 468 | ## Conditional Rules |
| 469 | |
| 470 | Rules in a `*_rules` file and entries in a `*_list` file can be made |
| 471 | conditional. They apply only to some voices. This can be useful to |
| 472 | specify different pronunciations for different variants of a language |
| 473 | (dialects or accents). |
| 474 | |
| 475 | Conditional rules have `?` and a condition number at the start if |
| 476 | the line in the `*_rules` or `*_list` file. This means that the rule |
| 477 | only applies of that condition number is specified in a `dictrules` |
| 478 | line in the [voice file](voices.md#dictrules). |
| 479 | |
| 480 | If the rule starts with `?!` then the rule only applies if the |
| 481 | condition number is `not` specified in the voice file. e.g. |
| 482 | |
| 483 | ?3 can't kant // only use this if the voice has: dictrules 3 |
| 484 | ?!3 rather rA:D3 // only use if the voice doesn't have: dictrules 3 |
| 485 | |
| 486 | ## Numbers and Character Names |
| 487 | |
| 488 | ### Letter names |
| 489 | |
| 490 | The names of individual letters can be given either in the `*_rules` or |
| 491 | `*_list` file. Sometimes an individual letter is also used as a word in |
| 492 | the language and its pronunciation as a word differs from its letter name. |
| 493 | If so, it should be listed in the `*_list` file, preceded by an underscore, |
| 494 | to give the letter name (as distinct from its pronunciation as a word). |
| 495 | e.g. in English: |
| 496 | |
| 497 | _a eI |
| 498 | |
| 499 | ### Numbers |
| 500 | |
| 501 | The operation the `TranslateNumber()` function is controlled by the |
| 502 | language's `langopts.numbers` option. This constructs spoken |
| 503 | numbers from fragments according to various options which can be set for |
| 504 | each language. The number fragments are given in the `*_list` file. |
| 505 | |
| 506 | | Symbol | Description | |
| 507 | |---------------|-------------| |
| 508 | | `_0` to `_9` | The numbers 0 to 9. | |
| 509 | | `_13` etc. | Any pronunciations which are needed for specific numbers in the range `_10` to `_99`. | |
| 510 | | `_2X` `_3X` | Twenty, thirty, etc., used to make numbers 10 to 99. | |
| 511 | | `_0C` | The word for `hundred`. | |
| 512 | | `_1C` `_2C` | Special pronunciation for one hundred, two hundred, etc., if needed. | |
| 513 | | `_1C0` | Special pronunciation (if needed) for 100 exactly. | |
| 514 | | `_0M1` | The word for `thousand`. | |
| 515 | | `_1M1` `_2M1` | Special pronunciation for `1` thousand, `2` thousand, etc, if needed. | |
| 516 | | `_0M2` | The word for `million`. | |
| 517 | | `_0M3` | The word for 1,000,000,000. | |
| 518 | | `_0MX` | The word for `10^3X` of number<sup>[1](#footnote1)</sup>. | |
| 519 | | `_0and` | Word for `and` when speaking numbers (e.g. `two hundred and twenty`). | |
| 520 | | `_dpt` | Word spoken for the decimal point/comma. | |
| 521 | | `_dpt2` | Word spoken (if any) at the end of all the digits after a decimal point. | |
| 522 | |
| 523 | |
| 524 | **notes about ordinal numbers** |
| 525 | To enable ordinal numbers: |
| 526 | 1. set `langopts.numbers` | NUM_ORDINAL_DOT in tr_languages.c |
| 527 | 2. for each number symbol explained above, add a line with suffix o. |
| 528 | For example: `_1o` for first, `_51o` for fifty first and so on. |
| 529 | |
| 530 | |
| 531 | ## Character Substitution |
| 532 | |
| 533 | Character substitutions can be specified by using a `.replace` section |
| 534 | at the start of the `*_rules` file. In each line multiple _source_ characters |
| 535 | can be replaced by one or two characters. This substitution is done to a word |
| 536 | _before_ word is searched in `*_list` or `*_listx` file and translated using |
| 537 | the spelling-to-phoneme rules. Only the lower-case version of the characters |
| 538 | needs to be specified. e.g.: |
| 539 | |
| 540 | .replace |
| 541 | ô ő // (Hungarian) allow the use of o-circumflex instead of o-double-accute |
| 542 | û ű |
| 543 | cx ĉ // (Esperanto) allow "cx" as an alternative to c-circumflex |
| 544 | fi fi // replace a single character ligature by two characters |
| 545 | |
| 546 | ## (Re)definition of character groups |
| 547 | |
| 548 | The set of these vowel characters in `A` group and consonants in `C` group may be |
| 549 | redefined for a particular language. Other sets of letters indicated by `B`, `E`, `F` and `G` |
| 550 | usually have specific meaning for each particular language. |
| 551 | |
| 552 | (Re)definition of letter groups is done in [tr_languages.c](../src/libespeak-ng/tr_languages.c) |
| 553 | file by calling `SetLetterBits()` function from (usually) `NewTranslator()` function. |
| 554 | Note, that letters should be stored as array of chars, thus multibyte |
| 555 | unicode letters should be transposed using `transpose_min` and `transpose_max` parameters |
| 556 | of particular `Translator` structure, or using `SetLetterBitsUTF8()` function. |
| 557 | |
| 558 | ---- |
| 559 | |
| 560 | <a name="footnote1"></a>1. Default length, to switch between named orders and just spelled digits in number, is 14 digits and is set in `tr->langopts.max_digits` field of `NewTranslator` function of [tr_languages.c](../src/libespeak-ng/tr_languages.c) file. To change it, update `SelectTranslator` function for particular language. |