eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tr_languages.cpp 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <wctype.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <locale.h>
  26. #include <wctype.h>
  27. #include "speak_lib.h"
  28. #include "speech.h"
  29. #include "phoneme.h"
  30. #include "synthesize.h"
  31. #include "translate.h"
  32. #include "tr_languages.h"
  33. #define L_qa 0x716100
  34. #define L_grc 0x677263 // grc Ancient Greek
  35. #define OFFSET_GREEK 0x380
  36. #define OFFSET_CYRILLIC 0x420
  37. #define OFFSET_DEVANAGARI 0x900
  38. static const unsigned int replace_cyrillic_latin[] =
  39. {0x430,'a',
  40. 0x431,'b',
  41. 0x446,'c',
  42. 0x45b,0x107,
  43. 0x447,0x10d,
  44. 0x45f,'d'+(0x17e<<16),
  45. 0x455,'d'+('z'<<16),
  46. 0x434,'d',
  47. 0x452,0x111,
  48. 0x435,'e',
  49. 0x444,'f',
  50. 0x433,'g',
  51. 0x445,'h',
  52. 0x438,'i',
  53. 0x458,'j',
  54. 0x43a,'k',
  55. 0x459,'l'+('j'<<16),
  56. 0x43b,'l',
  57. 0x43c,'m',
  58. 0x45a,'n'+('j'<<16),
  59. 0x43d,'n',
  60. 0x43e,'o',
  61. 0x43f,'p',
  62. 0x440,'r',
  63. 0x441,'s',
  64. 0x448,0x161,
  65. 0x442,'t',
  66. 0x443,'u',
  67. 0x432,'v',
  68. 0x437,'z',
  69. 0x436,0x17e,
  70. 0x453,0x111,
  71. 0x45c,0x107,
  72. 0}; // ѓ ѕ ќ
  73. void SetupTranslator(Translator *tr, int *lengths, int *amps)
  74. {//==========================================================
  75. if(lengths != NULL)
  76. memcpy(tr->stress_lengths,lengths,sizeof(tr->stress_lengths));
  77. if(amps != NULL)
  78. memcpy(tr->stress_amps,amps,sizeof(tr->stress_amps));
  79. }
  80. Translator *SelectTranslator(const char *name)
  81. {//===========================================
  82. int name2 = 0;
  83. Translator *tr;
  84. // convert name string into a word of up to 4 characters, for the switch()
  85. while(*name != 0)
  86. name2 = (name2 << 8) + *name++;
  87. switch(name2)
  88. {
  89. case L('a','f'):
  90. tr = new Translator_Afrikaans();
  91. break;
  92. case L('c','y'): // Welsh
  93. {
  94. static int stress_lengths_cy[8] = {170,230, 190,190, 0, 0, 250,270};
  95. static int stress_amps_cy[8] = {16,15, 18,18, 0,0, 24,22 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  96. tr = new Translator();
  97. SetupTranslator(tr,stress_lengths_cy,stress_amps_cy);
  98. tr->charset_a0 = charsets[14]; // ISO-8859-14
  99. // tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  100. tr->langopts.stress_rule = 2;
  101. // 'diminished' is an unstressed final syllable
  102. tr->langopts.stress_flags = 0x6 | 0x10;
  103. tr->langopts.word_gap = 0;
  104. tr->langopts.vowel_pause = 0;
  105. tr->langopts.unstressed_wd1 = 0;
  106. tr->langopts.unstressed_wd2 = 2;
  107. tr->langopts.param[LOPT_SONORANT_MIN] = 120; // limit the shortening of sonorants before short vowels
  108. tr->langopts.numbers = 0x401;
  109. SetLetterVowel(tr,'w'); // add letter to vowels and remove from consonants
  110. SetLetterVowel(tr,'y');
  111. }
  112. break;
  113. case L('d','e'):
  114. {
  115. static const int stress_lengths_de[8] = {150,130, 190,190, 0, 0, 260,275};
  116. tr = new Translator();
  117. tr->langopts.stress_rule = 0;
  118. tr->langopts.word_gap = 0x2; // don't use linking phonemes
  119. tr->langopts.vowel_pause = 0x30;
  120. tr->langopts.param[LOPT_PREFIXES] = 1;
  121. memcpy(tr->stress_lengths,stress_lengths_de,sizeof(tr->stress_lengths));
  122. tr->langopts.numbers = 0x11c19 + NUM_ROMAN;
  123. SetLetterVowel(tr,'y');
  124. }
  125. break;
  126. case L('e','n'):
  127. tr = new Translator_English();
  128. break;
  129. case L('e','l'): // Greek
  130. case L_grc: // Ancient Greek
  131. {
  132. static int stress_lengths_el[8] = {155, 180, 210, 210, 0, 0, 270, 300};
  133. static int stress_amps_el[8] = {15,12, 20,20, 20,24, 24,22 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  134. // character codes offset by 0x380
  135. static const char el_vowels[] = {0x10,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x35,0x37,0x39,0x3f,0x45,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0};
  136. static const char el_fvowels[] = {0x2d,0x2e,0x2f,0x35,0x37,0x39,0x45,0x4d,0}; // ε η ι υ έ ή ί ύ
  137. static const char el_voiceless[]= {0x38,0x3a,0x3e,0x40,0x42,0x43,0x44,0x46,0x47,0}; // θ κ ξ π ς σ τ φ χ
  138. static const char el_consonants[]={0x32,0x33,0x34,0x36,0x38,0x3a,0x3b,0x3c,0x3d,0x3e,0x40,0x41,0x42,0x43,0x44,0x46,0x47,0x48,0};
  139. static const wchar_t el_char_apostrophe[] = {0x3c3,0}; // σ
  140. tr = new Translator();
  141. SetupTranslator(tr,stress_lengths_el,stress_amps_el);
  142. tr->charset_a0 = charsets[7]; // ISO-8859-7
  143. tr->char_plus_apostrophe = el_char_apostrophe;
  144. tr->letter_bits_offset = OFFSET_GREEK;
  145. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  146. SetLetterBits(tr,LETTERGP_A,el_vowels);
  147. SetLetterBits(tr,LETTERGP_B,el_voiceless);
  148. SetLetterBits(tr,LETTERGP_C,el_consonants);
  149. SetLetterBits(tr,LETTERGP_Y,el_fvowels); // front vowels: ε η ι υ
  150. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  151. tr->langopts.stress_rule = 2;
  152. tr->langopts.stress_flags = 0x6; // mark unstressed final syllables as diminished
  153. tr->langopts.word_gap = 0;
  154. tr->langopts.vowel_pause = 0;
  155. tr->langopts.unstressed_wd1 = 0;
  156. tr->langopts.unstressed_wd2 = 2;
  157. tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
  158. tr->langopts.numbers = 0xb09;
  159. tr->langopts.numbers2 = 0x2; // variant form of numbers before thousands
  160. if(name2 == L_grc)
  161. {
  162. // ancient greek
  163. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1;
  164. }
  165. }
  166. break;
  167. case L('e','o'):
  168. {
  169. static int stress_lengths_eo[8] = {145, 180, 200, 190, 0, 0, 300, 320};
  170. static int stress_amps_eo[] = {16,14, 20,20, 20,24, 24,22 };
  171. static const wchar_t eo_char_apostrophe[2] = {'l',0};
  172. tr = new Translator();
  173. SetupTranslator(tr,stress_lengths_eo,stress_amps_eo);
  174. tr->charset_a0 = charsets[3]; // ISO-8859-3
  175. tr->char_plus_apostrophe = eo_char_apostrophe;
  176. tr->langopts.vowel_pause = 1;
  177. tr->langopts.stress_rule = 2;
  178. tr->langopts.stress_flags = 0x6 | 0x10;
  179. // tr->langopts.stress_flags = 0x1; // don't give full stress to monosyllables
  180. tr->langopts.unstressed_wd1 = 1;
  181. tr->langopts.unstressed_wd2 = 2;
  182. tr->langopts.numbers = 0x1409;
  183. }
  184. break;
  185. case L('e','s'): // Spanish
  186. {
  187. static int stress_lengths_es[8] = {170, 200, 180, 180, 0, 0, 220, 250};
  188. static int stress_amps_es[8] = {16,12, 18,18, 20,22, 22,22 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  189. tr = new Translator();
  190. SetupTranslator(tr,stress_lengths_es,stress_amps_es);
  191. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  192. tr->langopts.stress_rule = 2;
  193. // stress last syllable if it doesn't end in vowel or "s" or "n"
  194. // 'diminished' is an unstressed final syllable
  195. tr->langopts.stress_flags = 0x200 | 0x6 | 0x10;
  196. tr->langopts.word_gap = 0;
  197. tr->langopts.vowel_pause = 0;
  198. tr->langopts.unstressed_wd1 = 0;
  199. tr->langopts.unstressed_wd2 = 2;
  200. tr->langopts.param[LOPT_SONORANT_MIN] = 120; // limit the shortening of sonorants before short vowels
  201. tr->langopts.numbers = 0x529 + NUM_ROMAN;
  202. }
  203. break;
  204. case L('f','i'): // Finnish
  205. {
  206. static int stress_amps_fi[8] = {18,16, 22,22, 20,22, 22,22 };
  207. static int stress_lengths_fi[8] = {150,170, 200,200, 0,0, 210,250};
  208. tr = new Translator();
  209. SetupTranslator(tr,stress_lengths_fi,stress_amps_fi);
  210. tr->langopts.stress_rule = 0;
  211. tr->langopts.stress_flags = 0x56; // move secondary stress from light to a following heavy syllable
  212. tr->langopts.param[LOPT_IT_DOUBLING] = 1;
  213. tr->langopts.long_stop = 140;
  214. tr->langopts.numbers = 0x1009;
  215. SetLetterVowel(tr,'y');
  216. tr->langopts.max_initial_consonants = 2;
  217. tr->langopts.spelling_stress = 1;
  218. tr->punct_to_tone[0][1] = 0; // don't raise pitch for comma
  219. // tr->punct_to_tone[0][2] = 0; // don't raise pitch for question
  220. }
  221. break;
  222. case L('f','r'): // french
  223. {
  224. static int stress_lengths_fr[8] = {190, 170, 190, 200, 0, 0, 235, 235};
  225. static int stress_amps_fr[8] = {16,14, 20,20, 20,24, 24,22 };
  226. tr = new Translator();
  227. SetupTranslator(tr,stress_lengths_fr,stress_amps_fr);
  228. tr->langopts.stress_rule = 3; // stress on final syllable
  229. tr->langopts.stress_flags = 0x0024; // don't use secondary stress
  230. tr->langopts.param[LOPT_IT_LENGTHEN] = 1; // remove lengthen indicator from unstressed syllables
  231. tr->langopts.numbers = 0x1509;
  232. SetLetterVowel(tr,'y');
  233. }
  234. break;
  235. case L('h','i'):
  236. {
  237. static const char dev_consonants2[] = {0x02,0x03,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f};
  238. static int stress_lengths_hi[8] = {190, 190, 210, 210, 0, 0, 230, 250};
  239. static int stress_amps_hi[8] = {17,14, 20,19, 20,24, 24,22 };
  240. tr = new Translator();
  241. SetupTranslator(tr,stress_lengths_hi,stress_amps_hi);
  242. tr->charset_a0 = charsets[19]; // ISCII
  243. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  244. tr->langopts.stress_rule = 6; // stress on last heaviest syllable
  245. tr->langopts.stress_flags = 0x10004; // use 'diminished' for unstressed final syllable
  246. tr->langopts.numbers = 0x811;
  247. tr->langopts.numbers2 = 0x100;
  248. tr->letter_bits_offset = OFFSET_DEVANAGARI;
  249. memset(tr->letter_bits,0,sizeof(tr->letter_bits));
  250. SetLetterBitsRange(tr,LETTERGP_A,0x06,0x14); // vowel letters
  251. SetLetterBitsRange(tr,LETTERGP_B,0x3e,0x4d); // vowel signs + virama
  252. SetLetterBitsRange(tr,LETTERGP_C,0x15,0x39); // the main consonant range
  253. SetLetterBits(tr,LETTERGP_C,dev_consonants2); // additional consonants
  254. tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  255. }
  256. break;
  257. case L('h','r'): // Croatian
  258. case L('b','s'): // Bosnian
  259. case L('s','r'): // Serbian
  260. {
  261. static int stress_amps_hr[8] = {16,16, 20,20, 20,24, 24,22 };
  262. static int stress_lengths_hr[8] = {180,160, 200,200, 0,0, 220,230};
  263. tr = new Translator();
  264. SetupTranslator(tr,stress_lengths_hr,stress_amps_hr);
  265. tr->charset_a0 = charsets[2]; // ISO-8859-2
  266. tr->langopts.stress_rule = 0;
  267. tr->langopts.stress_flags = 0x10;
  268. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x3;
  269. tr->langopts.max_initial_consonants = 5;
  270. tr->langopts.spelling_stress = 1;
  271. tr->langopts.numbers = 0x1c0d + 0x4000 + NUM_ROMAN_UC;
  272. tr->langopts.numbers2 = 0x4a; // variant numbers before thousands,milliards
  273. tr->langopts.replace_chars = replace_cyrillic_latin;
  274. SetLetterVowel(tr,'y');
  275. SetLetterVowel(tr,'r');
  276. }
  277. break;
  278. case L('h','u'): // Hungarian
  279. {
  280. static int stress_amps_hu[8] = {17,17, 19,19, 20,24, 24,22 };
  281. static int stress_lengths_hu[8] = {185,195, 195,190, 0,0, 210,220};
  282. tr = new Translator();
  283. SetupTranslator(tr,stress_lengths_hu,stress_amps_hu);
  284. tr->charset_a0 = charsets[2]; // ISO-8859-2
  285. tr->langopts.vowel_pause = 0x20;
  286. tr->langopts.stress_rule = 0;
  287. tr->langopts.stress_flags = 0x8036;
  288. tr->langopts.unstressed_wd1 = 2;
  289. // tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x4; // don't propagate over word boundaries
  290. tr->langopts.param[LOPT_IT_DOUBLING] = 1;
  291. tr->langopts.param[LOPT_COMBINE_WORDS] = 99; // combine some prepositions with the following word
  292. tr->langopts.numbers = 0x1809 + NUM_ROMAN;
  293. SetLetterVowel(tr,'y');
  294. tr->langopts.spelling_stress = 1;
  295. SetLengthMods(tr,3); // all equal
  296. }
  297. break;
  298. case L('i','s'): // Icelandic
  299. {
  300. static int stress_amps_is[] = {16,16, 20,20, 20,24, 24,22 };
  301. static int stress_lengths_is[8] = {180,160, 200,200, 0,0, 240,250};
  302. static const wchar_t is_lettergroup_B[] = {'c','f','h','k','p','t','x',0xfe,0}; // voiceless conants, including 'þ' ?? 's'
  303. tr = new Translator();
  304. SetupTranslator(tr,stress_lengths_is,stress_amps_is);
  305. tr->langopts.stress_rule = 0;
  306. tr->langopts.stress_flags = 0x10;
  307. tr->langopts.param[LOPT_IT_LENGTHEN] = 0x11; // remove lengthen indicator from unstressed vowels
  308. tr->langopts.param[LOPT_REDUCE] = 2;
  309. ResetLetterBits(tr,0x18);
  310. SetLetterBits(tr,4,"kpst"); // Letter group F
  311. SetLetterBits(tr,3,"jvr"); // Letter group H
  312. tr->letter_groups[1] = is_lettergroup_B;
  313. SetLetterVowel(tr,'y');
  314. tr->langopts.numbers = 0xe9;
  315. tr->langopts.numbers2 = 0x2;
  316. }
  317. break;
  318. case L('i','t'): // Italian
  319. {
  320. static int stress_lengths_it[8] = {150, 140, 180, 180, 0, 0, 270, 320};
  321. static int stress_amps_it[8] = {15,14, 19,19, 20,24, 24,22 };
  322. tr = new Translator();
  323. SetupTranslator(tr,stress_lengths_it,stress_amps_it);
  324. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  325. tr->langopts.stress_rule = 2;
  326. tr->langopts.word_gap = 0;
  327. tr->langopts.vowel_pause = 1;
  328. tr->langopts.unstressed_wd1 = 2;
  329. tr->langopts.unstressed_wd2 = 2;
  330. tr->langopts.param[LOPT_IT_LENGTHEN] = 2; // remove lengthen indicator from unstressed or non-penultimate syllables
  331. tr->langopts.param[LOPT_IT_DOUBLING] = 2; // double the first consonant if the previous word ends in a stressed vowel
  332. tr->langopts.param[LOPT_SONORANT_MIN] = 130; // limit the shortening of sonorants before short vowels
  333. tr->langopts.param[LOPT_REDUCE] = 1; // reduce vowels even if phonemes are specified in it_list
  334. tr->langopts.numbers = 0x2709 + 0x800 + NUM_ROMAN;
  335. }
  336. break;
  337. case L('l','a'): //Latin
  338. {
  339. tr = new Translator();
  340. tr->charset_a0 = charsets[4]; // ISO-8859-4, includes a,e,i,o,u-macron
  341. tr->langopts.stress_rule = 2;
  342. tr->langopts.stress_flags = 0x20;
  343. tr->langopts.unstressed_wd1 = 0;
  344. tr->langopts.unstressed_wd2 = 2;
  345. tr->langopts.param[LOPT_DIERESES] = 1;
  346. tr->langopts.numbers = 0x1 + NUM_ROMAN;
  347. tr->langopts.max_roman = 5000;
  348. }
  349. break;
  350. case L('m','k'): // Macedonian
  351. {
  352. static wchar_t vowels_cyrillic[] = {0x440, // also include 'р' [R]
  353. 0x430,0x435,0x438,0x439,0x43e,0x443,0x44b,0x44d,0x44e,0x44f,0x450,0x451,0x456,0x457,0x45d,0x45e,0};
  354. static int stress_amps_mk[8] = {16,16, 20,20, 20,24, 24,22 };
  355. static int stress_lengths_mk[8] = {180,160, 200,200, 0,0, 220,230};
  356. tr = new Translator();
  357. SetupTranslator(tr,stress_lengths_mk,stress_amps_mk);
  358. tr->charset_a0 = charsets[5]; // ISO-8859-5
  359. tr->letter_groups[0] = vowels_cyrillic;
  360. tr->langopts.stress_rule = 4; // antipenultimate
  361. tr->langopts.numbers = 0x0c29 + 0x4000;
  362. tr->langopts.numbers2 = 0x8a; // variant numbers before thousands,milliards
  363. }
  364. break;
  365. case L('n','l'): // Dutch
  366. {
  367. static const int stress_lengths_nl[8] = {160,135, 210,210, 0, 0, 260,280};
  368. tr = new Translator();
  369. tr->langopts.stress_rule = 0;
  370. tr->langopts.word_gap = 0;
  371. tr->langopts.vowel_pause = 1;
  372. tr->langopts.param[LOPT_DIERESES] = 1;
  373. tr->langopts.param[LOPT_PREFIXES] = 1;
  374. SetLetterVowel(tr,'y');
  375. tr->langopts.numbers = 0x11419;
  376. memcpy(tr->stress_lengths,stress_lengths_nl,sizeof(tr->stress_lengths));
  377. }
  378. break;
  379. case L('n','o'): // Norwegian
  380. {
  381. static int stress_amps_no[] = {16,16, 20,20, 20,24, 24,22 };
  382. static int stress_lengths_no[8] = {160,140, 200,190, 0,0, 220,240};
  383. tr = new Translator();
  384. SetupTranslator(tr,stress_lengths_no,stress_amps_no);
  385. tr->langopts.stress_rule = 0;
  386. SetLetterVowel(tr,'y');
  387. tr->langopts.numbers = 0x11049;
  388. }
  389. break;
  390. case L('p','l'): // Polish
  391. {
  392. static int stress_lengths_pl[8] = {160, 180, 175, 175, 0, 0, 260, 290};
  393. static int stress_amps_pl[8] = {17,14, 19,19, 20,24, 24,22 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  394. tr = new Translator();
  395. SetupTranslator(tr,stress_lengths_pl,stress_amps_pl);
  396. tr->charset_a0 = charsets[2]; // ISO-8859-2
  397. tr->langopts.stress_rule = 2;
  398. tr->langopts.stress_flags = 0x6; // mark unstressed final syllables as diminished
  399. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x8;
  400. tr->langopts.max_initial_consonants = 7; // for example: wchrzczony :)
  401. tr->langopts.numbers=0x1809 + 0x4000;
  402. tr->langopts.numbers2=0x40;
  403. tr->langopts.param[LOPT_COMBINE_WORDS] = 2 + 0x100; // combine 'nie' (marked with $alt2) with some 1-syllable words (marked with $alt)
  404. SetLetterVowel(tr,'y');
  405. }
  406. break;
  407. case L('p','t'): // Portuguese
  408. {
  409. static int stress_lengths_pt[8] = {180, 125, 210, 210, 0, 0, 270, 295};
  410. static int stress_amps_pt[8] = {16,13, 19,19, 20,24, 24,22 }; // 'diminished' is used to mark a quieter, final unstressed syllable
  411. tr = new Translator();
  412. SetupTranslator(tr,stress_lengths_pt,stress_amps_pt);
  413. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  414. // tr->langopts.vowel_pause = 1;
  415. tr->langopts.stress_rule = 3; // stress on final syllable
  416. tr->langopts.stress_flags = 0x6 | 0x10 | 0x20000;
  417. tr->langopts.numbers = 0xa69 + 0x2000 + NUM_ROMAN;
  418. tr->punct_to_tone[0][3] = 2; // use exclamation intonation
  419. SetLetterVowel(tr,'y');
  420. }
  421. break;
  422. case L('r','o'): // Romanian
  423. {
  424. static int stress_lengths_ro[8] = {170, 170, 180, 180, 0, 0, 240, 260};
  425. static int stress_amps_ro[8] = {15,13, 18,18, 20,22, 22,22 };
  426. tr = new Translator();
  427. SetupTranslator(tr,stress_lengths_ro,stress_amps_ro);
  428. tr->langopts.stress_rule = 2;
  429. tr->langopts.stress_flags = 0x100 + 0x6;
  430. tr->charset_a0 = charsets[2]; // ISO-8859-2
  431. tr->langopts.numbers = 0x1829+0x6000 + NUM_ROMAN;
  432. tr->langopts.numbers2 = 0x1e; // variant numbers before all thousandplex
  433. }
  434. break;
  435. case L('r','u'): // Russian
  436. tr = new Translator_Russian();
  437. break;
  438. case L('s','k'): // Slovak
  439. case L('c','s'): // Czech
  440. {
  441. static int stress_amps_sk[8] = {16,16, 20,20, 20,24, 24,22 };
  442. static int stress_lengths_sk[8] = {190,190, 210,210, 0,0, 210,210};
  443. static char *sk_voiced = "bdgjlmnrvwzaeiouy";
  444. tr = new Translator();
  445. SetupTranslator(tr,stress_lengths_sk,stress_amps_sk);
  446. tr->charset_a0 = charsets[2]; // ISO-8859-2
  447. tr->langopts.stress_rule = 0;
  448. tr->langopts.stress_flags = 0x16;
  449. tr->langopts.param[LOPT_REGRESSIVE_VOICING] = 0x3;
  450. tr->langopts.max_initial_consonants = 5;
  451. tr->langopts.spelling_stress = 1;
  452. tr->langopts.param[LOPT_COMBINE_WORDS] = 4; // combine some prepositions with the following word
  453. tr->langopts.numbers = 0x1c01 + 0x4000;
  454. tr->langopts.numbers2 = 0x40;
  455. tr->langopts.thousands_sep = 0; //no thousands separator
  456. tr->langopts.decimal_sep = ',';
  457. if(name2 == L('c','s'))
  458. {
  459. tr->langopts.numbers2 = 0x8; // variant numbers before milliards
  460. }
  461. SetLetterVowel(tr,'y');
  462. SetLetterVowel(tr,'r');
  463. ResetLetterBits(tr,0x2);
  464. SetLetterBits(tr,5,sk_voiced);
  465. }
  466. break;
  467. case L('s','v'): // Swedish
  468. {
  469. static int stress_amps_sv[] = {16,16, 20,20, 20,24, 24,22 };
  470. static int stress_lengths_sv[8] = {160,135, 220,220, 0,0, 250,280};
  471. tr = new Translator();
  472. SetupTranslator(tr,stress_lengths_sv,stress_amps_sv);
  473. tr->langopts.stress_rule = 0;
  474. SetLetterVowel(tr,'y');
  475. // SetLetterBits(tr,6,"eiyäö"); // soft vowels NOTE accented letters don't work in SetLetterBits
  476. tr->langopts.numbers = 0x1109;
  477. }
  478. break;
  479. case L('s','w'): // Swahili
  480. {
  481. static int stress_lengths_sw[8] = {160, 170, 200, 200, 0, 0, 320, 340};
  482. static int stress_amps_sw[] = {16,12, 19,19, 20,24, 24,22 };
  483. tr = new Translator();
  484. SetupTranslator(tr,stress_lengths_sw,stress_amps_sw);
  485. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  486. tr->langopts.vowel_pause = 1;
  487. tr->langopts.stress_rule = 2;
  488. tr->langopts.stress_flags = 0x6 | 0x10;
  489. tr->langopts.numbers = 0x8e1;
  490. tr->langopts.numbers2 = 0x100;
  491. }
  492. break;
  493. case L('t','r'): // Turkish
  494. {
  495. static int stress_amps_tr[8] = {16,16, 20,20, 20,24, 24,22 };
  496. static int stress_lengths_tr[8] = {180,150, 200,180, 0,0, 230,270};
  497. tr = new Translator();
  498. SetupTranslator(tr,stress_lengths_tr,stress_amps_tr);
  499. tr->charset_a0 = charsets[9]; // ISO-8859-9 - Latin5
  500. tr->langopts.stress_rule = 3; // stress on the last syllable
  501. tr->langopts.numbers = 0x1009;
  502. tr->langopts.max_initial_consonants = 2;
  503. }
  504. break;
  505. case L('v','i'): // Vietnamese
  506. {
  507. static int stress_lengths_vi[8] = {150, 150, 180, 180, 210, 220, 220, 280};
  508. static int stress_amps_vi[] = {16,16, 16,16, 24,24, 24,22 };
  509. static wchar_t vowels_vi[] = {
  510. 0x61, 0xe0, 0xe1, 0x1ea3, 0xe3, 0x1ea1, // a
  511. 0x103, 0x1eb1, 0x1eaf, 0x1eb3, 0x1eb5, 0x1eb7, // ă
  512. 0xe2, 0x1ea7, 0x1ea5, 0x1ea9, 0x1eab, 0x1ead, // â
  513. 0x65, 0xe8, 0xe9, 0x1ebb, 0x1ebd, 0x1eb9, // e
  514. 0xea, 0x1ec1, 0x1ebf, 0x1ec3, 0x1ec5, 0x1ec7, // i
  515. 0x69, 0xec, 0xed, 0x1ec9, 0x129, 0x1ecb, // i
  516. 0x6f, 0xf2, 0xf3, 0x1ecf, 0xf5, 0x1ecd, // o
  517. 0xf4, 0x1ed3, 0x1ed1, 0x1ed5, 0x1ed7, 0x1ed9, // ô
  518. 0x1a1, 0x1edd, 0x1edb, 0x1edf, 0x1ee1, 0x1ee3, // ơ
  519. 0x75, 0xf9, 0xfa, 0x1ee7, 0x169, 0x1ee5, // u
  520. 0x1b0, 0x1eeb, 0x1ee9, 0x1eed, 0x1eef, 0x1ef1, // ư
  521. 0x79, 0x1ef3, 0xfd, 0x1ef7, 0x1ef9, 0x1e, 0 }; // y
  522. tr = new Translator();
  523. SetupTranslator(tr,stress_lengths_vi,stress_amps_vi);
  524. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  525. tr->langopts.stress_rule = 0;
  526. tr->langopts.word_gap = 0x4; // length of a final vowel is less dependent on the next consonant
  527. tr->langopts.vowel_pause = 4;
  528. tr->letter_groups[0] = vowels_vi;
  529. // tr->langopts.param[LOPT_UNPRONOUNCABLE] = 1; // disable check for unpronouncable words
  530. tr->langopts.intonation = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  531. tr->langopts.unstressed_wd1 = 2;
  532. }
  533. break;
  534. case L('z','h'):
  535. case L_qa + 'a': // Test qaa
  536. {
  537. static int stress_lengths_qaa[8] = {200,200, 248,248, 248,0, 248,250};
  538. static int stress_amps_qaa[] = {16,16, 20,20, 24,24, 24,22 };
  539. tr = new Translator();
  540. SetupTranslator(tr,stress_lengths_qaa,stress_amps_qaa);
  541. tr->langopts.stress_rule = 0;
  542. tr->langopts.vowel_pause = 0;
  543. tr->langopts.intonation = 1; // Tone language, use CalcPitches_Tone() rather than CalcPitches()
  544. tr->langopts.length_mods0 = tr->langopts.length_mods; // don't lengthen vowels in the last syllable
  545. tr->langopts.tone_numbers = 9;
  546. tr->langopts.ideographs = 1;
  547. tr->langopts.word_gap = 0x5; // length of a final vowel is less dependent on the next consonant, don't merge consonant with next word
  548. }
  549. break;
  550. default:
  551. tr = new Translator();
  552. break;
  553. }
  554. tr->translator_name = name2;
  555. if(tr->langopts.numbers & 0x8)
  556. {
  557. // use . and ; for thousands and decimal separators
  558. tr->langopts.thousands_sep = '.';
  559. tr->langopts.decimal_sep = ',';
  560. }
  561. if(tr->langopts.numbers & 0x4)
  562. {
  563. tr->langopts.thousands_sep = 0; // don't allow thousands separator, except space
  564. }
  565. return(tr);
  566. } // end of SelectTranslator
  567. //**********************************************************************************************************
  568. Translator_Russian::Translator_Russian() : Translator()
  569. {//===================================
  570. static int stress_amps_ru[] = {16,16, 18,18, 20,24, 24,22 };
  571. static int stress_lengths_ru[8] = {150,140, 220,220, 0,0, 260,280};
  572. // character codes offset by 0x420
  573. static const char ru_vowels[] = {0x10,0x15,0x31,0x18,0x1e,0x23,0x2b,0x2d,0x2e,0x2f,0};
  574. static const char ru_consonants[] = {0x11,0x12,0x13,0x14,0x16,0x17,0x19,0x1a,0x1b,0x1c,0x1d,0x1f,0x20,0x21,0x22,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2c,0};
  575. static const char ru_soft[] = {0x2c,0x19,0x27,0x29,0}; // letter group B [k ts; s;]
  576. static const char ru_hard[] = {0x2a,0x16,0x26,0x28,0}; // letter group H [S Z ts]
  577. static const char ru_nothard[] = {0x11,0x12,0x13,0x14,0x17,0x19,0x1a,0x1b,0x1c,0x1d,0x1f,0x20,0x21,0x22,0x24,0x25,0x27,0x29,0x2c,0};
  578. static const char ru_voiced[] = {0x11,0x12,0x13,0x14,0x16,0x17,0}; // letter group G (voiced obstruents)
  579. static const char ru_ivowels[] = {0x2c,0x15,0x31,0x18,0x2e,0x2f,0}; // letter group Y (iotated vowels & soft-sign)
  580. SetupTranslator(this,stress_lengths_ru,stress_amps_ru);
  581. charset_a0 = charsets[18]; // KOI8-R
  582. transpose_offset = 0x42f; // convert cyrillic from unicode into range 0x01 to 0x22
  583. transpose_min = 0x430;
  584. transpose_max = 0x451;
  585. letter_bits_offset = OFFSET_CYRILLIC;
  586. memset(letter_bits,0,sizeof(letter_bits));
  587. SetLetterBits(this,0,ru_vowels);
  588. SetLetterBits(this,1,ru_soft);
  589. SetLetterBits(this,2,ru_consonants);
  590. SetLetterBits(this,3,ru_hard);
  591. SetLetterBits(this,4,ru_nothard);
  592. SetLetterBits(this,5,ru_voiced);
  593. SetLetterBits(this,6,ru_ivowels);
  594. SetLetterBits(this,7,ru_vowels);
  595. langopts.param[LOPT_UNPRONOUNCABLE] = 0x432; // [v] don't count this character at start of word
  596. langopts.param[LOPT_REGRESSIVE_VOICING] = 1;
  597. langopts.param[LOPT_REDUCE] = 2;
  598. langopts.stress_rule = 5;
  599. langopts.stress_flags = 0x0020; // waas 0x1010
  600. langopts.numbers = 0x0409;
  601. langopts.numbers2 = 0xc2; // variant numbers before thousands
  602. langopts.phoneme_change = 1;
  603. langopts.testing = 2;
  604. } // end of Translator_Russian
  605. #define PH(c1,c2) (c2<<8)+c1 // combine two characters into an integer for phoneme name
  606. #define PY(c1,c2,c3) (c3<<16)+(c2<<8)+c1
  607. /*
  608. typedef struct {
  609. int flags;
  610. unsigned char stress; // stress level of this vowel
  611. unsigned char stress_highest; // the highest stress level of a vowel in this word
  612. unsigned char n_vowels; // number of vowels in the word
  613. unsigned char vowel_this; // syllable number of this vowel (counting from 1)
  614. unsigned char vowel_stressed; // syllable number of the highest stressed vowel
  615. } CHANGEPH;
  616. */
  617. #define RUSSIAN2
  618. #ifdef RUSSIAN2
  619. int Translator_Russian::ChangePhonemes(PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch)
  620. {//==============================================================================================================
  621. // Called for each phoneme in the phoneme list, to allow a language to make changes
  622. // ph The current phoneme
  623. int variant;
  624. int vowelix;
  625. PHONEME_TAB *prev, *next;
  626. if(ch->flags & 8)
  627. return(0); // full phoneme translation has already been given
  628. // Russian vowel softening and reduction rules
  629. if(ph->type == phVOWEL)
  630. {
  631. int prestressed = ch->vowel_stressed==ch->vowel_this+1; // the next vowel after this has the main stress
  632. #define N_VOWELS_RU 11
  633. static unsigned int vowels_ru[N_VOWELS_RU] = {'a','V','O','I',PH('I','#'),PH('E','#'),PH('E','2'),
  634. PH('V','#'),PH('I','3'),PH('I','2'),PH('E','3')};
  635. static unsigned int vowel_replace[N_VOWELS_RU][6] = {
  636. // stressed, soft, soft-stressed, j+stressed, j+soft, j+soft-stressed
  637. /*0*/ {'A', 'I', PH('j','a'), 'a', 'a', 'a'}, // a Uses 3,4,5 columns.
  638. /*1*/ {'A', 'V', PH('j','a'), 'a', 'V', 'a'}, // V Uses 3,4,5 columns.
  639. /*2*/ {'o', '8', '8', 'o', '8', '8'}, // O
  640. /*3*/ {'i', 'I', 'i', 'a', 'I', 'a'}, // I Uses 3,4,5 columns.
  641. /*4*/ {'i', PH('I','#'), 'i', 'i', PH('I','#'), 'i'}, // I#
  642. /*5*/ {'E', PH('E','#'), 'E', 'e', PH('E','#'), 'e'}, // E#
  643. /*6*/ {'E', PH('E','2'), 'E', 'e', PH('E','2'), 'e'}, // E2 Uses 3,4,5 columns.
  644. /*7*/ {PH('j','a'), 'V', PH('j','a'), 'A', 'V', 'A'}, // V#
  645. /*8*/ {PH('j','a'), 'I', PH('j','a'), 'e', 'I', 'e'}, // I3 Uses 3,4,5 columns.
  646. /*9*/ {'e', 'I', 'e', 'e', 'I', 'e'}, // I2
  647. /*10*/ {'e', PH('E', '2'), 'e', 'e', PH('E','2'), 'e'} // E3
  648. };
  649. prev = phoneme_tab[phlist[index-1].phcode];
  650. next = phoneme_tab[phlist[index+1].phcode];
  651. // lookup the vowel name to get an index into the vowel_replace[] table
  652. for(vowelix=0; vowelix<N_VOWELS_RU; vowelix++)
  653. {
  654. if(vowels_ru[vowelix] == ph->mnemonic)
  655. break;
  656. }
  657. if(vowelix == N_VOWELS_RU)
  658. return(0);
  659. if(prestressed)
  660. {
  661. if((vowelix==6)&&(prev->mnemonic=='j'))
  662. vowelix=8;
  663. if(vowelix==1)
  664. vowelix=0;
  665. if(vowelix==4)
  666. vowelix=3;
  667. if(vowelix==6)
  668. vowelix=5;
  669. if(vowelix==7)
  670. vowelix=8;
  671. if(vowelix==10)
  672. vowelix=9;
  673. }
  674. // do we need a variant of this vowel, depending on the stress and adjacent phonemes ?
  675. variant = -1;
  676. int stressed = ch->flags & 2;
  677. int soft=prev->phflags & phPALATAL;
  678. if (soft && stressed)
  679. variant = 2; else
  680. if (stressed)
  681. variant = 0; else
  682. if (soft)
  683. variant = 1;
  684. if(variant >= 0)
  685. {
  686. if(prev->mnemonic == 'j')
  687. variant += 3;
  688. phlist[index].phcode = PhonemeCode(vowel_replace[vowelix][variant]);
  689. }
  690. else
  691. {
  692. phlist[index].phcode = PhonemeCode(vowels_ru[vowelix]);
  693. }
  694. }
  695. return(0);
  696. }
  697. #else
  698. int Translator_Russian::ChangePhonemes(PHONEME_LIST2 *phlist, int n_ph, int index, PHONEME_TAB *ph, CHANGEPH *ch)
  699. {//===============================================================================================================
  700. // Called for each phoneme in the phoneme list, to allow a language to make changes
  701. // flags: bit 0=1 last phoneme in a word
  702. // bit 1=1 this is the highest stressed vowel in the current word
  703. // bit 2=1 after the highest stressed vowel in the current word
  704. // bit 3=1 the phonemes were specified explicitly, or found from an entry in the xx_list dictionary
  705. // ph The current phoneme
  706. int variant;
  707. int vowelix;
  708. PHONEME_TAB *prev, *next;
  709. if(ch->flags & 8)
  710. return(0); // full phoneme translation has already been given
  711. // Russian vowel softening and reduction rules
  712. if(ph->type == phVOWEL)
  713. {
  714. #define N_VOWELS_RU 7
  715. static unsigned char vowels_ru[N_VOWELS_RU] = {'a','A','o','E','i','u','y'};
  716. // each line gives: soft, reduced, soft-reduced, post-tonic
  717. static unsigned short vowel_replace[N_VOWELS_RU][4] = {
  718. {'&', 'V', 'I', 'V'}, // a
  719. {'&', 'V', 'I', 'V'}, // A
  720. {'8', 'V', 'I', 'V'}, // o
  721. {'e', 'I', 'I', 'I'}, // E
  722. {'i', 'I', 'I', 'I'}, // i
  723. {'u'+('"'<<8), 'U', 'U', 'U'}, // u
  724. {'y', 'Y', 'Y', 'Y'}}; // y
  725. prev = phoneme_tab[phlist[index-1].phcode];
  726. next = phoneme_tab[phlist[index+1].phcode];
  727. if(prev->mnemonic == 'j')
  728. return(0);
  729. // lookup the vowel name to get an index into the vowel_replace[] table
  730. for(vowelix=0; vowelix<N_VOWELS_RU; vowelix++)
  731. {
  732. if(vowels_ru[vowelix] == ph->mnemonic)
  733. break;
  734. }
  735. if(vowelix == N_VOWELS_RU)
  736. return(0);
  737. // do we need a variant of this vowel, depending on the stress and adjacent phonemes ?
  738. variant = -1;
  739. if(ch->flags & 2)
  740. {
  741. // a stressed vowel
  742. if((prev->phflags & phPALATAL) && ((next->phflags & phPALATAL) || phoneme_tab[phlist[index+2].phcode]->mnemonic == ';'))
  743. {
  744. // between two palatal consonants, use the soft variant
  745. variant = 0;
  746. }
  747. }
  748. else
  749. {
  750. // an unstressed vowel
  751. if(prev->phflags & phPALATAL)
  752. {
  753. variant = 2; // unstressed soft
  754. }
  755. else
  756. if((ph->mnemonic == 'o') && ((prev->phflags & phPLACE) == phPLACE_pla))
  757. {
  758. variant = 2; // unstressed soft ([o] vowel following: ш ж
  759. }
  760. else
  761. if(ch->flags & 4)
  762. {
  763. variant = 3; // post tonic
  764. }
  765. else
  766. {
  767. variant = 1; // unstressed
  768. }
  769. }
  770. if(variant >= 0)
  771. {
  772. phlist[index].phcode = PhonemeCode(vowel_replace[vowelix][variant]);
  773. }
  774. }
  775. return(0);
  776. }
  777. #endif
  778. //**********************************************************************************************************
  779. Translator_Afrikaans::Translator_Afrikaans() : Translator()
  780. {//=========================================
  781. // Initialise options for this language
  782. static const int stress_lengths2[8] = {170,140, 220,220, 0, 0, 250,270};
  783. langopts.stress_rule = 0;
  784. langopts.word_gap = 0;
  785. langopts.vowel_pause = 0x30;
  786. langopts.param[LOPT_DIERESES] = 1;
  787. langopts.param[LOPT_PREFIXES] = 1;
  788. SetLetterVowel(this,'y'); // add 'y' to vowels
  789. langopts.numbers = 0x0d1 + NUM_ROMAN;
  790. memcpy(stress_lengths,stress_lengths2,sizeof(stress_lengths));
  791. }
  792. int Translator_Afrikaans::TranslateChar(char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert)
  793. {//===============================================================================================================
  794. // look for 'n and replace by a special character (unicode: schwa)
  795. if(!iswalpha(prev_in))
  796. {
  797. if((c == '\'') && (next_in == 'n'))
  798. {
  799. // n preceded by either apostrophe or U2019 "right single quotation mark"
  800. ptr[0] = ' '; // delete the n
  801. return(0x0259); // replace ' by unicode schwa character
  802. }
  803. }
  804. return(c);
  805. }