| 1 | /* |
| 2 | * Copyright (C) 2005 to 2014 by Jonathan Duddington |
| 3 | * email: [email protected] |
| 4 | * Copyright (C) 2015-2017, 2020 Reece H. Dunn |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, see: <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef ESPEAK_NG_TRANSLATE_H |
| 21 | #define ESPEAK_NG_TRANSLATE_H |
| 22 | |
| 23 | #include <stdbool.h> |
| 24 | |
| 25 | #include "espeak_ng.h" |
| 26 | #include "encoding.h" |
| 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" |
| 30 | { |
| 31 | #endif |
| 32 | |
| 33 | #define L(c1, c2) (c1<<8)+c2 // combine two characters into an integer for translator name |
| 34 | #define L3(c1, c2, c3) (c1<<16)+(c2<<8) + c3 // combine three characters into an integer for translator name |
| 35 | #define L4(c1, c2, c3, c4) (c1<<24)+(c2<<16)+(c3<<8) + c4 // combine four characters into an integer for translator name |
| 36 | |
| 37 | #define CTRL_EMBEDDED 0x01 // control character at the start of an embedded command |
| 38 | #define REPLACED_E 'E' // 'e' replaced by silent e |
| 39 | |
| 40 | #define N_WORD_PHONEMES 200 // max phonemes in a word |
| 41 | #define N_WORD_BYTES 160 // max bytes for the UTF8 characters in a word |
| 42 | #define N_PHONEME_BYTES 160 // max bytes for a phoneme |
| 43 | #define N_CLAUSE_WORDS 300 // max words in a clause |
| 44 | #define N_TR_SOURCE 800 // the source text of a single clause (UTF8 bytes) |
| 45 | |
| 46 | #define N_RULE_GROUP2 120 // max num of two-letter rule chains |
| 47 | #define N_HASH_DICT 1024 |
| 48 | #define N_LETTER_GROUPS 95 // maximum is 127-32 |
| 49 | |
| 50 | // dictionary flags, word 1 |
| 51 | // bits 0-3 stressed syllable, bit 6=unstressed |
| 52 | #define FLAG_SKIPWORDS 0x80 |
| 53 | #define FLAG_PREPAUSE 0x100 |
| 54 | |
| 55 | #define FLAG_STRESS_END 0x200 // full stress if at end of clause |
| 56 | #define FLAG_STRESS_END2 0x400 // full stress if at end of clause, or only followed by unstressed |
| 57 | #define FLAG_UNSTRESS_END 0x800 // reduce stress at end of clause |
| 58 | #define FLAG_SPELLWORD 0x1000 // re-translate the word as individual letters, separated by spaces |
| 59 | #define FLAG_ACCENT_BEFORE 0x1000 // say this accent name before the letter name |
| 60 | #define FLAG_ABBREV 0x2000 // spell as letters, even with a vowel, OR use specified pronunciation rather than split into letters |
| 61 | #define FLAG_DOUBLING 0x4000 // doubles the following consonant |
| 62 | |
| 63 | #define BITNUM_FLAG_ALT 14 // bit number of FLAG_ALT_TRANS - 1 |
| 64 | #define FLAG_ALT_TRANS 0x8000 // language specific |
| 65 | #define FLAG_ALT2_TRANS 0x10000 // language specific |
| 66 | #define FLAG_ALT3_TRANS 0x20000 // language specific |
| 67 | #define FLAG_ALT7_TRANS 0x200000 // language specific |
| 68 | |
| 69 | #define FLAG_COMBINE 0x800000 // combine with the next word |
| 70 | #define FLAG_ALLOW_DOT 0x01000000 // ignore '.' after word (abbreviation) |
| 71 | #define FLAG_NEEDS_DOT 0x02000000 // only if the word is followed by a dot |
| 72 | #define FLAG_WAS_UNPRONOUNCABLE 0x04000000 // the unpronounceable routine was used |
| 73 | #define FLAG_MAX3 0x08000000 // limit to 3 repeats |
| 74 | #define FLAG_PAUSE1 0x10000000 // shorter prepause |
| 75 | #define FLAG_TEXTMODE 0x20000000 // word translates to replacement text, not phonemes |
| 76 | #define BITNUM_FLAG_TEXTMODE 29 |
| 77 | |
| 78 | #define FLAG_FOUND_ATTRIBUTES 0x40000000 // word was found in the dictionary list (has attributes) |
| 79 | #define FLAG_FOUND 0x80000000 // pronunciation was found in the dictionary list |
| 80 | |
| 81 | // dictionary flags, word 2 |
| 82 | #define FLAG_VERBF 0x1 // verb follows |
| 83 | #define FLAG_VERBSF 0x2 // verb follows, may have -s suffix |
| 84 | #define FLAG_NOUNF 0x4 // noun follows |
| 85 | #define FLAG_PASTF 0x8 // past tense follows |
| 86 | #define FLAG_VERB 0x10 // pronunciation for verb |
| 87 | #define FLAG_NOUN 0x20 // pronunciation for noun |
| 88 | #define FLAG_PAST 0x40 // pronunciation for past tense |
| 89 | #define FLAG_VERB_EXT 0x100 // extend the 'verb follows' |
| 90 | #define FLAG_CAPITAL 0x200 // pronunciation if initial letter is upper case |
| 91 | #define FLAG_ALLCAPS 0x400 // only if the word is all capitals |
| 92 | #define FLAG_ACCENT 0x800 // character name is base-character name + accent name |
| 93 | #define FLAG_SENTENCE 0x2000 // only if the clause is a sentence |
| 94 | #define FLAG_ONLY 0x4000 |
| 95 | #define FLAG_ONLY_S 0x8000 |
| 96 | #define FLAG_STEM 0x10000 // must have a suffix |
| 97 | #define FLAG_ATEND 0x20000 // use this pronunciation if at end of clause |
| 98 | #define FLAG_ATSTART 0x40000 // use this pronunciation if at start of clause |
| 99 | #define FLAG_NATIVE 0x80000 // not if we've switched translators |
| 100 | #define FLAG_LOOKUP_SYMBOL 0x40000000 // to indicate called from Lookup() |
| 101 | |
| 102 | #define BITNUM_FLAG_ALLCAPS 0x2a |
| 103 | #define BITNUM_FLAG_HYPHENATED 0x2c |
| 104 | #define BITNUM_FLAG_ONLY 0x2e |
| 105 | #define BITNUM_FLAG_ONLY_S 0x2f |
| 106 | |
| 107 | // wordflags, flags in source word |
| 108 | #define FLAG_ALL_UPPER 0x1 // no lower case letters in the word |
| 109 | #define FLAG_FIRST_UPPER 0x2 // first letter is upper case |
| 110 | #define FLAG_UPPERS 0x3 // FLAG_ALL_UPPER | FLAG_FIRST_UPPER |
| 111 | #define FLAG_HAS_PLURAL 0x4 // upper-case word with s or 's lower-case ending |
| 112 | #define FLAG_PHONEMES 0x8 // word is phonemes |
| 113 | #define FLAG_LAST_WORD 0x10 // last word in clause |
| 114 | #define FLAG_EMBEDDED 0x40 // word is preceded by embedded commands |
| 115 | #define FLAG_HYPHEN 0x80 |
| 116 | #define FLAG_NOSPACE 0x100 // word is not separated from previous word by a space |
| 117 | #define FLAG_FIRST_WORD 0x200 // first word in clause |
| 118 | #define FLAG_FOCUS 0x400 // the focus word of a clause |
| 119 | #define FLAG_EMPHASIZED 0x800 |
| 120 | #define FLAG_EMPHASIZED2 0xc00 // FLAG_FOCUS | FLAG_EMPHASIZED |
| 121 | #define FLAG_DONT_SWITCH_TRANSLATOR 0x1000 |
| 122 | #define FLAG_SUFFIX_REMOVED 0x2000 |
| 123 | #define FLAG_HYPHEN_AFTER 0x4000 |
| 124 | #define FLAG_ORDINAL 0x8000 // passed to TranslateNumber() to indicate an ordinal number |
| 125 | #define FLAG_HAS_DOT 0x10000 // dot after this word |
| 126 | #define FLAG_COMMA_AFTER 0x20000 // comma after this word |
| 127 | #define FLAG_MULTIPLE_SPACES 0x40000 // word is preceded by multiple spaces, newline, or tab |
| 128 | #define FLAG_INDIVIDUAL_DIGITS 0x80000 // speak number as individual digits |
| 129 | #define FLAG_DELETE_WORD 0x100000 // don't speak this word, it has been spoken as part of the previous word |
| 130 | #define FLAG_CHAR_REPLACED 0x200000 // characters have been replaced by .replace in the *_rules |
| 131 | #define FLAG_TRANSLATOR2 0x400000 // retranslating using a different language |
| 132 | #define FLAG_PREFIX_REMOVED 0x800000 // a prefix has been removed from this word |
| 133 | |
| 134 | #define FLAG_SUFFIX_VOWEL 0x08000000 // remember an initial vowel from the suffix |
| 135 | #define FLAG_NO_TRACE 0x10000000 // passed to TranslateRules() to suppress dictionary lookup printout |
| 136 | #define FLAG_NO_PREFIX 0x20000000 |
| 137 | #define FLAG_UNPRON_TEST 0x80000000 // do unpronounability test on the beginning of the word |
| 138 | |
| 139 | // prefix/suffix flags (bits 8 to 14, bits 16 to 22) don't use 0x8000, 0x800000 |
| 140 | #define SUFX_E 0x0100 // e may have been added |
| 141 | #define SUFX_I 0x0200 // y may have been changed to i |
| 142 | #define SUFX_P 0x0400 // prefix |
| 143 | #define SUFX_V 0x0800 // suffix means use the verb form pronunciation |
| 144 | #define SUFX_D 0x1000 // previous letter may have been doubled |
| 145 | #define SUFX_F 0x2000 // verb follows |
| 146 | #define SUFX_Q 0x4000 // don't retranslate |
| 147 | #define SUFX_T 0x10000 // don't affect the stress position in the stem |
| 148 | #define SUFX_B 0x20000 // break, this character breaks the word into stem and suffix (used with SUFX_P) |
| 149 | #define SUFX_A 0x40000 // remember that the suffix starts with a vowel |
| 150 | #define SUFX_M 0x80000 // bit 19, allow multiple suffixes |
| 151 | |
| 152 | #define SUFX_UNPRON 0x8000 // used to return $unpron flag from *_rules |
| 153 | |
| 154 | #define FLAG_ALLOW_TEXTMODE 0x02 // allow dictionary to translate to text rather than phonemes |
| 155 | #define FLAG_SUFX 0x04 |
| 156 | #define FLAG_SUFX_S 0x08 |
| 157 | #define FLAG_SUFX_E_ADDED 0x10 |
| 158 | |
| 159 | // codes in dictionary rules |
| 160 | #define RULE_PRE 1 |
| 161 | #define RULE_POST 2 |
| 162 | #define RULE_PHONEMES 3 |
| 163 | #define RULE_PH_COMMON 4 // At start of rule. Its phoneme string is used by subsequent rules |
| 164 | #define RULE_CONDITION 5 // followed by condition number (byte) |
| 165 | #define RULE_GROUP_START 6 |
| 166 | #define RULE_GROUP_END 7 |
| 167 | #define RULE_PRE_ATSTART 8 // as RULE_PRE but also match with 'start of word' |
| 168 | #define RULE_LINENUM 9 // next 2 bytes give a line number, for debugging purposes |
| 169 | |
| 170 | #define RULE_STRESSED 10 // & |
| 171 | #define RULE_DOUBLE 11 // % |
| 172 | #define RULE_INC_SCORE 12 // + |
| 173 | #define RULE_DEL_FWD 13 // # |
| 174 | #define RULE_ENDING 14 // S |
| 175 | #define RULE_DIGIT 15 // D digit |
| 176 | #define RULE_NONALPHA 16 // Z non-alpha |
| 177 | #define RULE_LETTERGP 17 // A B C H F G Y letter group number |
| 178 | #define RULE_LETTERGP2 18 // L + letter group number |
| 179 | #define RULE_CAPITAL 19 // ! word starts with a capital letter |
| 180 | #define RULE_REPLACEMENTS 20 // section for character replacements |
| 181 | #define RULE_SYLLABLE 21 // @ |
| 182 | #define RULE_SKIPCHARS 23 // J |
| 183 | #define RULE_NO_SUFFIX 24 // N |
| 184 | #define RULE_NOTVOWEL 25 // K |
| 185 | #define RULE_IFVERB 26 // V |
| 186 | #define RULE_DOLLAR 28 // $ commands |
| 187 | #define RULE_NOVOWELS 29 // X no vowels up to word boundary |
| 188 | #define RULE_SPELLING 31 // W while spelling letter-by-letter |
| 189 | #define RULE_LAST_RULE 31 |
| 190 | // Rule codes above 31 are the ASCII code representation of the character |
| 191 | // used to specify the rule. |
| 192 | #define RULE_SPACE 32 // ascii space |
| 193 | #define RULE_DEC_SCORE 60 // < |
| 194 | |
| 195 | #define DOLLAR_UNPR 0x01 |
| 196 | #define DOLLAR_NOPREFIX 0x02 |
| 197 | #define DOLLAR_LIST 0x03 |
| 198 | |
| 199 | #define LETTERGP_A 0 |
| 200 | #define LETTERGP_B 1 |
| 201 | #define LETTERGP_C 2 |
| 202 | #define LETTERGP_H 3 |
| 203 | #define LETTERGP_F 4 |
| 204 | #define LETTERGP_G 5 |
| 205 | #define LETTERGP_Y 6 |
| 206 | #define LETTERGP_VOWEL2 7 |
| 207 | |
| 208 | // Punctuation types returned by ReadClause() |
| 209 | //@{ |
| 210 | |
| 211 | #define CLAUSE_PAUSE 0x00000FFF // pause (x 10mS) |
| 212 | #define CLAUSE_INTONATION_TYPE 0x00007000 // intonation type |
| 213 | #define CLAUSE_OPTIONAL_SPACE_AFTER 0x00008000 // don't need space after the punctuation |
| 214 | #define CLAUSE_TYPE 0x000F0000 // phrase type |
| 215 | #define CLAUSE_PUNCTUATION_IN_WORD 0x00100000 // punctuation character can be inside a word (Armenian) |
| 216 | #define CLAUSE_SPEAK_PUNCTUATION_NAME 0x00200000 // speak the name of the punctuation character |
| 217 | #define CLAUSE_DOT_AFTER_LAST_WORD 0x00400000 // dot after the last word |
| 218 | #define CLAUSE_PAUSE_LONG 0x00800000 // x 320mS to the CLAUSE_PAUSE value |
| 219 | |
| 220 | #define CLAUSE_INTONATION_FULL_STOP 0x00000000 |
| 221 | #define CLAUSE_INTONATION_COMMA 0x00001000 |
| 222 | #define CLAUSE_INTONATION_QUESTION 0x00002000 |
| 223 | #define CLAUSE_INTONATION_EXCLAMATION 0x00003000 |
| 224 | #define CLAUSE_INTONATION_NONE 0x00004000 |
| 225 | |
| 226 | #define CLAUSE_TYPE_NONE 0x00000000 |
| 227 | #define CLAUSE_TYPE_EOF 0x00010000 |
| 228 | #define CLAUSE_TYPE_VOICE_CHANGE 0x00020000 |
| 229 | #define CLAUSE_TYPE_CLAUSE 0x00040000 |
| 230 | #define CLAUSE_TYPE_SENTENCE 0x00080000 |
| 231 | |
| 232 | #define CLAUSE_NONE ( 0 | CLAUSE_INTONATION_NONE | CLAUSE_TYPE_NONE) |
| 233 | #define CLAUSE_PARAGRAPH (70 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_SENTENCE) |
| 234 | #define CLAUSE_EOF (40 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_SENTENCE | CLAUSE_TYPE_EOF) |
| 235 | #define CLAUSE_VOICE ( 0 | CLAUSE_INTONATION_NONE | CLAUSE_TYPE_VOICE_CHANGE) |
| 236 | #define CLAUSE_PERIOD (40 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_SENTENCE) |
| 237 | #define CLAUSE_COMMA (20 | CLAUSE_INTONATION_COMMA | CLAUSE_TYPE_CLAUSE) |
| 238 | #define CLAUSE_SHORTCOMMA ( 4 | CLAUSE_INTONATION_COMMA | CLAUSE_TYPE_CLAUSE) |
| 239 | #define CLAUSE_SHORTFALL ( 4 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_CLAUSE) |
| 240 | #define CLAUSE_QUESTION (40 | CLAUSE_INTONATION_QUESTION | CLAUSE_TYPE_SENTENCE) |
| 241 | #define CLAUSE_EXCLAMATION (45 | CLAUSE_INTONATION_EXCLAMATION | CLAUSE_TYPE_SENTENCE) |
| 242 | #define CLAUSE_COLON (30 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_CLAUSE) |
| 243 | #define CLAUSE_SEMICOLON (30 | CLAUSE_INTONATION_COMMA | CLAUSE_TYPE_CLAUSE) |
| 244 | |
| 245 | //@} |
| 246 | |
| 247 | #define SAYAS_CHARS 0x12 |
| 248 | #define SAYAS_GLYPHS 0x13 |
| 249 | #define SAYAS_SINGLE_CHARS 0x14 |
| 250 | #define SAYAS_KEY 0x24 |
| 251 | #define SAYAS_DIGITS 0x40 // + number of digits |
| 252 | #define SAYAS_DIGITS1 0xc1 |
| 253 | |
| 254 | #define CHAR_EMPHASIS 0x0530 // this is an unused character code |
| 255 | #define CHAR_COMMA_BREAK 0x0557 // unused character code |
| 256 | |
| 257 | // Rule: |
| 258 | // [4] [match] [1 pre] [2 post] [3 phonemes] 0 |
| 259 | // match 1 pre 2 post 0 - use common phoneme string |
| 260 | // match 1 pre 2 post 3 0 - empty phoneme string |
| 261 | |
| 262 | // used to mark words with the source[] buffer |
| 263 | typedef struct { |
| 264 | unsigned int flags; |
| 265 | unsigned short start; |
| 266 | unsigned char pre_pause; |
| 267 | unsigned short sourceix; |
| 268 | unsigned char length; |
| 269 | } WORD_TAB; |
| 270 | |
| 271 | typedef struct { |
| 272 | const char *name; |
| 273 | int offset; |
| 274 | unsigned short range_min, range_max; |
| 275 | int language; |
| 276 | int flags; |
| 277 | } ALPHABET; |
| 278 | |
| 279 | // alphabet flags |
| 280 | #define AL_DONT_NAME 0x01 // don't speak the alphabet name |
| 281 | #define AL_NOT_LETTERS 0x02 // don't use the language for speaking letters |
| 282 | #define AL_WORDS 0x04 // use the language to speak words |
| 283 | #define AL_NOT_CODE 0x08 // don't speak the character code |
| 284 | #define AL_NO_SYMBOL 0x10 // don't repeat "symbol" or "character" |
| 285 | |
| 286 | #define N_LOPTS 18 |
| 287 | #define LOPT_DIERESES 0 |
| 288 | // 1=remove [:] from unstressed syllables, 2= remove from unstressed or non-penultimate syllables |
| 289 | // bit 4=0, if stress < 4, bit 4=1, if not the highest stress in the word |
| 290 | #define LOPT_IT_LENGTHEN 1 |
| 291 | |
| 292 | // 1=german |
| 293 | #define LOPT_PREFIXES 2 |
| 294 | |
| 295 | // non-zero, change voiced/unoiced to match last consonant in a cluster |
| 296 | // bit 0=use regressive voicing |
| 297 | // bit 1=LANG=cz,bg don't propagate over [v] |
| 298 | // bit 2=don't propagate acress word boundaries |
| 299 | // bit 3=LANG=pl, propagate over liquids and nasals |
| 300 | // bit 4=LANG=cz,sk don't propagate to [v] |
| 301 | // bit 8=devoice word-final consonants |
| 302 | #define LOPT_REGRESSIVE_VOICING 3 |
| 303 | |
| 304 | // 0=default, 1=no check, other allow this character as an extra initial letter (default is 's') |
| 305 | #define LOPT_UNPRONOUNCABLE 4 |
| 306 | |
| 307 | // increase this to prevent sonorants being shortened before shortened (eg. unstressed) vowels |
| 308 | #define LOPT_SONORANT_MIN 5 |
| 309 | |
| 310 | // bit 0: don't break vowels at word boundary |
| 311 | #define LOPT_WORD_MERGE 6 |
| 312 | |
| 313 | |
| 314 | // max. amplitude for vowel at the end of a clause |
| 315 | #define LOPT_MAXAMP_EOC 7 |
| 316 | |
| 317 | // bit 0=reduce even if phonemes are specified in the **_list file |
| 318 | // bit 1=don't reduce the strongest vowel in a word which is marked 'unstressed' |
| 319 | #define LOPT_REDUCE 8 |
| 320 | |
| 321 | // LANG=cs,sk combine some prepositions with the following word, if the combination has N or fewer syllables |
| 322 | // bits 0-3 N syllables |
| 323 | // bit 4=only if the second word has $alt attribute |
| 324 | // bit 5=not if the second word is end-of-sentence |
| 325 | #define LOPT_COMBINE_WORDS 9 |
| 326 | |
| 327 | // 1 = stressed syllable is indicated by capitals |
| 328 | #define LOPT_CAPS_IN_WORD 10 |
| 329 | |
| 330 | // Call ApplySpecialAttributes() if $alt or $alt2 is set for a word |
| 331 | // bit 1: stressed syllable: $alt change [e],[o] to [E],[O], $alt2 change [E],[O] to [e],[o] |
| 332 | #define LOPT_ALT 11 |
| 333 | |
| 334 | // pause for bracket (default=4), also see LOPT_BRACKET_PAUSE_ANNOUNCED |
| 335 | #define LOPT_BRACKET_PAUSE 12 |
| 336 | |
| 337 | // bit 1, don't break clause before annoucning . ? ! |
| 338 | #define LOPT_ANNOUNCE_PUNCT 13 |
| 339 | |
| 340 | // recognize long vowels (0 = don't recognize) |
| 341 | #define LOPT_LONG_VOWEL_THRESHOLD 14 |
| 342 | |
| 343 | // bit 0: Don't allow suffices if there is no previous syllable |
| 344 | #define LOPT_SUFFIX 15 |
| 345 | |
| 346 | // bit 0 Apostrophe at start of word is part of the word |
| 347 | // bit 1 Apostrophe at end of word is part of the word |
| 348 | #define LOPT_APOSTROPHE 16 |
| 349 | |
| 350 | // pause when announcing bracket names (default=2), also see LOPT_BRACKET_PAUSE |
| 351 | #define LOPT_BRACKET_PAUSE_ANNOUNCED 17 |
| 352 | |
| 353 | // stress_rule |
| 354 | #define STRESSPOSN_1L 0 // 1st syllable |
| 355 | #define STRESSPOSN_2L 1 // 2nd syllable |
| 356 | #define STRESSPOSN_2R 2 // penultimate |
| 357 | #define STRESSPOSN_1R 3 // final syllable |
| 358 | #define STRESSPOSN_3R 4 // antipenultimate |
| 359 | #define STRESSPOSN_SYLCOUNT 5 // stress depends on syllable count |
| 360 | #define STRESSPOSN_1RH 6 // last heaviest syllable, excluding final syllable |
| 361 | #define STRESSPOSN_1RU 7 // stress on the last syllable, before any explicitly unstressed syllable |
| 362 | #define STRESSPOSN_2LLH 8 // first syllable, unless it is a light syllable followed by a heavy syllable |
| 363 | #define STRESSPOSN_ALL 9 // mark all stressed |
| 364 | #define STRESSPOSN_GREENLANDIC 12 |
| 365 | #define STRESSPOSN_1SL 13 // 1st syllable, unless 1st vowel is short and 2nd is long |
| 366 | #define STRESSPOSN_EU 15 // If more than 2 syllables: primary stress in second syllable and secondary on last. |
| 367 | |
| 368 | typedef struct { |
| 369 | // bits0-2 separate words with (1=pause_vshort, 2=pause_short, 3=pause, 4=pause_long 5=[?] phonemme) |
| 370 | // bit 3=don't use linking phoneme |
| 371 | // bit4=longer pause before STOP, VSTOP,FRIC |
| 372 | // bit5=length of a final vowel doesn't depend on the next phoneme |
| 373 | int word_gap; |
| 374 | int vowel_pause; |
| 375 | int stress_rule; // see #defines for STRESSPOSN_* |
| 376 | |
| 377 | #define S_NO_DIM 0x02 |
| 378 | #define S_FINAL_DIM 0x04 |
| 379 | #define S_FINAL_DIM_ONLY 0x06 |
| 380 | // bit1=don't set diminished stress, |
| 381 | // bit2=mark unstressed final syllables as diminished |
| 382 | |
| 383 | // bit3=set consecutive unstressed syllables in unstressed words to diminished, but not in stressed words |
| 384 | |
| 385 | #define S_FINAL_NO_2 0x10 |
| 386 | // bit4=don't allow secondary stress on last syllable |
| 387 | |
| 388 | #define S_NO_AUTO_2 0x20 |
| 389 | // bit5-don't use automatic secondary stress |
| 390 | |
| 391 | #define S_2_TO_HEAVY 0x40 |
| 392 | // bit6=light syllable followed by heavy, move secondary stress to the heavy syllable. LANG=Finnish |
| 393 | |
| 394 | #define S_FIRST_PRIMARY 0x80 |
| 395 | // bit7=if more than one primary stress, make the subsequent primaries to secondary stress |
| 396 | |
| 397 | #define S_FINAL_VOWEL_UNSTRESSED 0x100 |
| 398 | // bit8=don't apply default stress to a word-final vowel |
| 399 | |
| 400 | #define S_FINAL_SPANISH 0x200 |
| 401 | // bit9=stress last syllable if it doesn't end in vowel or "s" or "n" LANG=Spanish |
| 402 | |
| 403 | #define S_2_SYL_2 0x1000 |
| 404 | // bit12= In a 2-syllable word, if one has primary stress then give the other secondary stress |
| 405 | |
| 406 | #define S_INITIAL_2 0x2000 |
| 407 | // bit13= If there is only one syllable before the primary stress, give it a secondary stress |
| 408 | |
| 409 | #define S_MID_DIM 0x10000 |
| 410 | // bit 16= Set (not first or last) syllables to diminished stress |
| 411 | |
| 412 | #define S_PRIORITY_STRESS 0x20000 |
| 413 | // bit17= "priority" stress reduces other primary stress to "unstressed" not "secondary" |
| 414 | |
| 415 | #define S_EO_CLAUSE1 0x40000 |
| 416 | // bit18= don't lengthen short vowels more than long vowels at end-of-clause |
| 417 | |
| 418 | #define S_FINAL_LONG 0x80000 |
| 419 | // bit19=stress on final syllable if it has a long vowel, but previous syllable has a short vowel |
| 420 | |
| 421 | |
| 422 | #define S_HYPEN_UNSTRESS 0x100000 |
| 423 | // bit20= hyphenated words, 2nd part is unstressed |
| 424 | |
| 425 | #define S_NO_EOC_LENGTHEN 0x200000 |
| 426 | // bit21= don't lengthen vowels at end-of-clause |
| 427 | |
| 428 | // bit15= Give stress to the first unstressed syllable |
| 429 | |
| 430 | int stress_flags; |
| 431 | int unstressed_wd1; // stress for $u word of 1 syllable |
| 432 | int unstressed_wd2; // stress for $u word of >1 syllable |
| 433 | int param[N_LOPTS]; |
| 434 | const unsigned char *length_mods; |
| 435 | const unsigned char *length_mods0; |
| 436 | |
| 437 | #define NUM_DEFAULT 0x00000001 // enable number processing; use if no other NUM_ option is specified |
| 438 | #define NUM_THOUS_SPACE 0x00000004 // thousands separator must be space |
| 439 | #define NUM_DECIMAL_COMMA 0x00000008 // , decimal separator, not . |
| 440 | #define NUM_SWAP_TENS 0x00000010 // use three-and-twenty rather than twenty-three |
| 441 | #define NUM_AND_UNITS 0x00000020 // 'and' between tens and units |
| 442 | #define NUM_HUNDRED_AND 0x00000040 // add "and" after hundred or thousand |
| 443 | #define NUM_SINGLE_AND 0x00000080 // don't have "and" both after hundreds and also between tens and units |
| 444 | #define NUM_SINGLE_STRESS 0x00000100 // only one primary stress in tens+units |
| 445 | #define NUM_SINGLE_VOWEL 0x00000200 // only one vowel between tens and units |
| 446 | #define NUM_OMIT_1_HUNDRED 0x00000400 // omit "one" before "hundred" |
| 447 | #define NUM_1900 0x00000800 // say 19** as nineteen hundred |
| 448 | #define NUM_ALLOW_SPACE 0x00001000 // allow space as thousands separator (in addition to langopts.thousands_sep) |
| 449 | #define NUM_DFRACTION_BITS 0x0000e000 // post-decimal-digits 0=single digits, 1=(LANG=it) 2=(LANG=pl) 3=(LANG=ro) |
| 450 | #define NUM_ORDINAL_DOT 0x00010000 // dot after number indicates ordinal |
| 451 | #define NUM_NOPAUSE 0x00020000 // don't add pause after a number |
| 452 | #define NUM_AND_HUNDRED 0x00040000 // 'and' before hundreds |
| 453 | #define NUM_THOUSAND_AND 0x00080000 // 'and' after thousands if there are no hundreds |
| 454 | #define NUM_VIGESIMAL 0x00100000 // vigesimal number, if tens are not found |
| 455 | #define NUM_OMIT_1_THOUSAND 0x00200000 // omit "one" before "thousand" |
| 456 | #define NUM_ZERO_HUNDRED 0x00400000 // say "zero" before hundred |
| 457 | #define NUM_HUNDRED_AND_DIGIT 0x00800000 // add "and" after hundreds and thousands, only if there are digits and no tens |
| 458 | #define NUM_ROMAN 0x01000000 // recognize roman numbers |
| 459 | #define NUM_ROMAN_CAPITALS 0x02000000 // Roman numbers only if upper case |
| 460 | #define NUM_ROMAN_AFTER 0x04000000 // say "roman" after the number, not before |
| 461 | #define NUM_ROMAN_ORDINAL 0x08000000 // Roman numbers are ordinal numbers |
| 462 | #define NUM_SINGLE_STRESS_L 0x10000000 // only one primary stress in tens+units (on the tens) |
| 463 | |
| 464 | #define NUM_DFRACTION_1 0x00002000 |
| 465 | #define NUM_DFRACTION_2 0x00004000 |
| 466 | #define NUM_DFRACTION_3 0x00006000 |
| 467 | #define NUM_DFRACTION_4 0x00008000 |
| 468 | #define NUM_DFRACTION_5 0x0000a000 |
| 469 | #define NUM_DFRACTION_6 0x0000c000 |
| 470 | #define NUM_DFRACTION_7 0x0000e000 // lang=si, alternative form of number for decimal fraction digits (except the last) |
| 471 | |
| 472 | int numbers; |
| 473 | |
| 474 | #define NUM2_THOUSANDS_VAR_BITS 0x000001c0 // use different forms of thousand, million, etc (M MA MB) |
| 475 | #define NUM2_SWAP_THOUSANDS 0x00000200 // say "thousand" and "million" before its number, not after |
| 476 | #define NUM2_ORDINAL_NO_AND 0x00000800 // don't say 'and' between tens and units for ordinal numbers |
| 477 | #define NUM2_MULTIPLE_ORDINAL 0x00001000 // use ordinal form of hundreds and tens as well as units |
| 478 | #define NUM2_NO_TEEN_ORDINALS 0x00002000 // don't use 11-19 numbers to make ordinals |
| 479 | #define NUM2_MYRIADS 0x00004000 // use myriads (groups of 4 digits) not thousands (groups of 3) |
| 480 | #define NUM2_ENGLISH_NUMERALS 0x00008000 // speak (non-replaced) English numerals in English |
| 481 | #define NUM2_PERCENT_BEFORE 0x00010000 // say "%" before the number |
| 482 | #define NUM2_OMIT_1_HUNDRED_ONLY 0x00020000 // omit "one" before hundred only if there are no previous digits |
| 483 | #define NUM2_ORDINAL_AND_THOUSANDS 0x00040000 // same variant for ordinals and thousands (#o = #a) |
| 484 | #define NUM2_ORDINAL_DROP_VOWEL 0x00080000 // drop final vowel from cardial number before adding ordinal suffix (currently only tens and units) |
| 485 | #define NUM2_ZERO_TENS 0x00100000 // say zero tens |
| 486 | |
| 487 | #define NUM2_THOUSANDPLEX_VAR_THOUSANDS 0x00000002 |
| 488 | #define NUM2_THOUSANDPLEX_VAR_MILLIARDS 0x00000008 |
| 489 | #define NUM2_THOUSANDPLEX_VAR_ALL 0x0000001e |
| 490 | |
| 491 | #define NUM2_THOUSANDS_VAR1 0x00000040 |
| 492 | #define NUM2_THOUSANDS_VAR2 0x00000080 |
| 493 | #define NUM2_THOUSANDS_VAR3 0x000000c0 |
| 494 | #define NUM2_THOUSANDS_VAR4 0x00000100 // plural forms for millions, etc. |
| 495 | #define NUM2_THOUSANDS_VAR5 0x00000140 |
| 496 | |
| 497 | int numbers2; |
| 498 | |
| 499 | // Bit 2^n is set if 10^n separates a number grouping (max n=31). |
| 500 | // 0 1 2 3 |
| 501 | // n = 01234567890123456789012345678901 |
| 502 | #define BREAK_THOUSANDS 0x49249248 // b b b b b b b b b b b // 10,000,000,000,000,000,000,000,000,000,000 |
| 503 | #define BREAK_MYRIADS 0x11111110 // b b b b b b b b // 1000,0000,0000,0000,0000,0000,0000,0000 |
| 504 | #define BREAK_LAKH 0xaaaaaaa8 // b b b b b b b b b b b b b b b b // 10,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000 |
| 505 | #define BREAK_LAKH_BN 0x24924aa8 // b b b b b b b b b b b b // 100,000,000,000,000,000,000,00,00,00,00,000 |
| 506 | #define BREAK_LAKH_DV 0x000014a8 // b b b b b b // 100,00,000,00,00,000 |
| 507 | #define BREAK_LAKH_HI 0x00014aa8 // b b b b b b b b // 100,00,000,00,00,00,00,000 |
| 508 | #define BREAK_LAKH_UR 0x000052a8 // b b b b b b b // 100,00,000,00,00,00,000 |
| 509 | #define BREAK_INDIVIDUAL 0x00000018 // b bb // 100,0,000 |
| 510 | |
| 511 | unsigned break_numbers; // which digits to break the number into thousands, millions, etc (Hindi has 100,000 not 1,000,000) |
| 512 | int max_roman; |
| 513 | int min_roman; |
| 514 | int thousands_sep; |
| 515 | int decimal_sep; |
| 516 | int max_digits; // max number of digits which can be spoken as an integer number (rather than individual digits) |
| 517 | const char *ordinal_indicator; // UTF-8 string |
| 518 | const unsigned char *roman_suffix; // add this (ordinal) suffix to Roman numbers (LANG=an) |
| 519 | |
| 520 | // bit 0, accent name before the letter name, bit 1 "capital" after letter name |
| 521 | int accents; |
| 522 | |
| 523 | int tone_language; // 1=tone language |
| 524 | int intonation_group; |
| 525 | unsigned char tunes[6]; |
| 526 | int long_stop; // extra mS pause for a lengthened stop |
| 527 | char max_initial_consonants; |
| 528 | bool spelling_stress; |
| 529 | char tone_numbers; |
| 530 | char ideographs; // treat as separate words |
| 531 | bool textmode; // the meaning of FLAG_TEXTMODE is reversed (to save data when *_list file is compiled) |
| 532 | char dotless_i; // uses letter U+0131 |
| 533 | int listx; // compile *_listx after *list |
| 534 | const unsigned char *replace_chars; // characters to be substitutes |
| 535 | int our_alphabet; // offset for main alphabet (if not set in letter_bits_offset) |
| 536 | int alt_alphabet; // offset for another language to recognize |
| 537 | int alt_alphabet_lang; // language for the alt_alphabet |
| 538 | int max_lengthmod; |
| 539 | int lengthen_tonic; // lengthen the tonic syllable |
| 540 | int suffix_add_e; // replace a suffix (which has the SUFX_E flag) with this character |
| 541 | bool lowercase_sentence; // when true, a period . causes a sentence stop even if next character is lowercase |
| 542 | } LANGUAGE_OPTIONS; |
| 543 | |
| 544 | typedef struct { |
| 545 | LANGUAGE_OPTIONS langopts; |
| 546 | int translator_name; |
| 547 | int transpose_max; |
| 548 | int transpose_min; |
| 549 | const char *transpose_map; |
| 550 | char dictionary_name[40]; |
| 551 | |
| 552 | char phonemes_repeat[20]; |
| 553 | int phonemes_repeat_count; |
| 554 | int phoneme_tab_ix; |
| 555 | |
| 556 | unsigned char stress_amps[8]; |
| 557 | short stress_lengths[8]; |
| 558 | int dict_condition; // conditional apply some pronunciation rules and dict.lookups |
| 559 | int dict_min_size; |
| 560 | espeak_ng_ENCODING encoding; |
| 561 | const wchar_t *char_plus_apostrophe; // single chars + apostrophe treated as words |
| 562 | const wchar_t *punct_within_word; // allow these punctuation characters within words |
| 563 | const unsigned short *chars_ignore; |
| 564 | |
| 565 | // holds properties of characters: vowel, consonant, etc for pronunciation rules |
| 566 | unsigned char letter_bits[256]; |
| 567 | int letter_bits_offset; |
| 568 | const wchar_t *letter_groups[8]; |
| 569 | |
| 570 | /* index1=option, index2 by 0=. 1=, 2=?, 3=! 4=none */ |
| 571 | #define INTONATION_TYPES 8 |
| 572 | #define PUNCT_INTONATIONS 6 |
| 573 | unsigned char punct_to_tone[INTONATION_TYPES][PUNCT_INTONATIONS]; |
| 574 | |
| 575 | char *data_dictrules; // language_1 translation rules file |
| 576 | char *data_dictlist; // language_2 dictionary lookup file |
| 577 | char *dict_hashtab[N_HASH_DICT]; // hash table to index dictionary lookup file |
| 578 | char *letterGroups[N_LETTER_GROUPS]; |
| 579 | |
| 580 | // groups1 and groups2 are indexes into data_dictrules, set up by InitGroups() |
| 581 | // the two-letter rules for each letter must be consecutive in the language_rules source |
| 582 | |
| 583 | char *groups1[256]; // translation rule lists, index by single letter |
| 584 | char *groups3[128]; // index by offset letter |
| 585 | char *groups2[N_RULE_GROUP2]; // translation rule lists, indexed by two-letter pairs |
| 586 | unsigned int groups2_name[N_RULE_GROUP2]; // the two letter pairs for groups2[] |
| 587 | int n_groups2; // number of groups2[] entries used |
| 588 | |
| 589 | unsigned char groups2_count[256]; // number of 2 letter groups for this initial letter |
| 590 | unsigned char groups2_start[256]; // index into groups2 |
| 591 | const short *frequent_pairs; // list of frequent pairs of letters, for use in compressed *_list |
| 592 | |
| 593 | int expect_verb; |
| 594 | int expect_past; // expect past tense |
| 595 | int expect_verb_s; |
| 596 | int expect_noun; |
| 597 | int prev_last_stress; |
| 598 | char *clause_end; |
| 599 | |
| 600 | int word_vowel_count; // number of vowels so far |
| 601 | int word_stressed_count; // number of vowels so far which could be stressed |
| 602 | |
| 603 | int clause_upper_count; // number of upper case letters in the clause |
| 604 | int clause_lower_count; // number of lower case letters in the clause |
| 605 | |
| 606 | int prepause_timeout; |
| 607 | int end_stressed_vowel; // word ends with stressed vowel |
| 608 | int prev_dict_flags[2]; // dictionary flags from previous word |
| 609 | int clause_terminator; |
| 610 | |
| 611 | } Translator; |
| 612 | |
| 613 | #define OPTION_EMPHASIZE_ALLCAPS 0x100 |
| 614 | #define OPTION_EMPHASIZE_PENULTIMATE 0x200 |
| 615 | extern int option_tone_flags; |
| 616 | extern int option_phonemes; |
| 617 | extern int option_phoneme_events; |
| 618 | extern int option_linelength; // treat lines shorter than this as end-of-clause |
| 619 | extern int option_capitals; |
| 620 | extern int option_punctuation; |
| 621 | extern int option_endpause; |
| 622 | extern int option_ssml; |
| 623 | extern int option_phoneme_input; // allow [[phonemes]] in input text |
| 624 | extern int option_sayas; |
| 625 | extern int option_wordgap; |
| 626 | |
| 627 | extern int count_characters; |
| 628 | extern int count_sentences; |
| 629 | extern int skip_characters; |
| 630 | extern int skip_words; |
| 631 | extern int skip_sentences; |
| 632 | extern bool skipping_text; |
| 633 | extern int end_character_position; |
| 634 | extern int clause_start_char; |
| 635 | extern int clause_start_word; |
| 636 | extern char *namedata; |
| 637 | extern int pre_pause; |
| 638 | |
| 639 | #define N_MARKER_LENGTH 50 // max.length of a mark name |
| 640 | extern char skip_marker[N_MARKER_LENGTH]; |
| 641 | |
| 642 | #define N_PUNCTLIST 60 |
| 643 | extern wchar_t option_punctlist[N_PUNCTLIST]; // which punctuation characters to announce |
| 644 | |
| 645 | extern Translator *translator; |
| 646 | extern Translator *translator2; |
| 647 | extern Translator *translator3; |
| 648 | extern char dictionary_name[40]; |
| 649 | extern espeak_ng_TEXT_DECODER *p_decoder; |
| 650 | extern int dictionary_skipwords; |
| 651 | |
| 652 | #define LEADING_2_BITS 0xC0 // 0b11000000 |
| 653 | #define UTF8_TAIL_BITS 0x80 // 0b10000000 |
| 654 | |
| 655 | int lookupwchar(const unsigned short *list, int c); |
| 656 | char *strchr_w(const char *s, int c); |
| 657 | void InitNamedata(void); |
| 658 | void InitText(int flags); |
| 659 | void InitText2(void); |
| 660 | const ALPHABET *AlphabetFromChar(int c); |
| 661 | |
| 662 | Translator *SelectTranslator(const char *name); |
| 663 | int SetTranslator2(const char *name); |
| 664 | int SetTranslator3(const char *name); |
| 665 | void DeleteTranslator(Translator *tr); |
| 666 | void ProcessLanguageOptions(LANGUAGE_OPTIONS *langopts); |
| 667 | |
| 668 | void print_dictionary_flags(unsigned int *flags, char *buf, int buf_len); |
| 669 | |
| 670 | int TranslateWord(Translator *tr, char *word1, WORD_TAB *wtab, char *word_out); |
| 671 | void TranslateClause(Translator *tr, int *tone, char **voice_change); |
| 672 | void TranslateClauseWithTerminator(Translator *tr, int *tone_out, char **voice_change, int *terminator_out); |
| 673 | |
| 674 | void SetVoiceStack(espeak_VOICE *v, const char *variant_name); |
| 675 | |
| 676 | extern FILE *f_trans; // for logging |
| 677 | |
| 678 | #ifdef __cplusplus |
| 679 | } |
| 680 | #endif |
| 681 | |
| 682 | #endif |