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

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