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

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