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

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