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 39KB

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