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.

numbers.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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 <stdlib.h>
  23. #include <string.h>
  24. #include <wctype.h>
  25. #include <wchar.h>
  26. #include "speak_lib.h"
  27. #include "speech.h"
  28. #include "phoneme.h"
  29. #include "synthesize.h"
  30. #include "voice.h"
  31. #include "translate.h"
  32. void Translator::LookupLetter(unsigned int letter, int next_byte, char *ph_buf1)
  33. {//=============================================================================
  34. int len;
  35. unsigned char *p;
  36. static char single_letter[10] = {0,0};
  37. char ph_stress[2];
  38. char ph_buf3[30];
  39. if((letter <= 32) || iswspace(letter))
  40. {
  41. // lookup space as _&32 etc.
  42. sprintf(&single_letter[1],"_#%d ",letter);
  43. Lookup(&single_letter[1],ph_buf1);
  44. return;
  45. }
  46. len = utf8_out(letter,&single_letter[2]);
  47. single_letter[len+2] = ' ';
  48. if(next_byte != ' ')
  49. next_byte = RULE_SPELLING;
  50. single_letter[3+len] = next_byte; // follow by space-space if the end of the word, or space-0x31
  51. single_letter[1] = '_';
  52. if(Lookup(&single_letter[1],ph_buf3) == 0)
  53. {
  54. single_letter[1] = ' ';
  55. if(Lookup(&single_letter[2],ph_buf3) == 0)
  56. {
  57. TranslateRules(&single_letter[2], ph_buf3, sizeof(ph_buf3), NULL,0,0);
  58. }
  59. }
  60. if(ph_buf3[0] == 0)
  61. {
  62. ph_buf1[0] = 0;
  63. return;
  64. }
  65. // at a stress marker at the start of the letter name, unless one is already marked
  66. ph_stress[0] = phonSTRESS_P;
  67. ph_stress[1] = 0;
  68. for(p=(unsigned char *)ph_buf3; *p != 0; p++)
  69. {
  70. if(phoneme_tab[*p]->type == phSTRESS)
  71. ph_stress[0] = 0; // stress is already marked
  72. }
  73. sprintf(ph_buf1,"%s%s",ph_stress,ph_buf3);
  74. }
  75. int Translator::TranslateLetter(char *word, char *phonemes, int control)
  76. {//=====================================================================
  77. // get pronunciation for an isolated letter
  78. // return number of bytes used by the letter
  79. // control 2=say-as glyphs, 3-say-as chars
  80. int n_bytes;
  81. int letter;
  82. int len;
  83. char *p2;
  84. char *pbuf;
  85. char capital[20];
  86. char ph_buf[60];
  87. char ph_buf2[60];
  88. char hexbuf[6];
  89. ph_buf[0] = 0;
  90. capital[0] = 0;
  91. n_bytes = utf8_in(&letter,word,0);
  92. if((letter & 0xfff00) == 0x0e000)
  93. {
  94. letter &= 0xff; // uncode private usage area
  95. }
  96. if(control > 2)
  97. {
  98. // include CAPITAL information
  99. if(iswupper(letter))
  100. {
  101. Lookup("_cap",capital);
  102. }
  103. }
  104. letter = towlower2(letter);
  105. LookupLetter(letter, word[n_bytes], ph_buf);
  106. if(ph_buf[0] == phonSWITCH)
  107. {
  108. strcpy(phonemes,ph_buf);
  109. return(0);
  110. }
  111. if(ph_buf[0] == 0)
  112. {
  113. // ?? speak as English ??
  114. sprintf(phonemes,"%c",phonSWITCH);
  115. return(0);
  116. }
  117. if(ph_buf[0] == 0)
  118. {
  119. // character name not found
  120. if(iswalpha(letter))
  121. Lookup("_?A",ph_buf);
  122. if((ph_buf[0]==0) && !iswspace(letter))
  123. Lookup("_??",ph_buf);
  124. if((control==4) && (ph_buf[0] != 0))
  125. {
  126. // speak the hexadecimal number of the character code
  127. sprintf(hexbuf,"%x",letter);
  128. pbuf = ph_buf;
  129. for(p2 = hexbuf; *p2 != 0; p2++)
  130. {
  131. pbuf += strlen(pbuf);
  132. LookupLetter(*p2, 0, pbuf);
  133. }
  134. }
  135. }
  136. len = strlen(phonemes);
  137. sprintf(ph_buf2,"%c%s%s",0xff,capital,ph_buf); // the 0xff marker will be removed or replaced in SetSpellingStress()
  138. if((len + strlen(ph_buf2)) < N_WORD_PHONEMES)
  139. {
  140. strcpy(&phonemes[len],ph_buf2);
  141. }
  142. return(n_bytes);
  143. } // end of TranslateLetter
  144. void Translator::SetSpellingStress(char *phonemes, int control, int n_chars)
  145. {//=========================================================================
  146. // Individual letter names, reduce the stress of some.
  147. int ix;
  148. unsigned int c;
  149. int n_stress=0;
  150. int count;
  151. unsigned char buf[N_WORD_PHONEMES];
  152. for(ix=0; (c = phonemes[ix]) != 0; ix++)
  153. {
  154. if(c == phonSTRESS_P)
  155. {
  156. n_stress++;
  157. }
  158. buf[ix] = c;
  159. }
  160. buf[ix] = 0;
  161. count = 0;
  162. for(ix=0; (c = buf[ix]) != 0; ix++)
  163. {
  164. if((c == phonSTRESS_P) && (n_chars > 1))
  165. {
  166. count++;
  167. if(langopts.spelling_stress == 1)
  168. {
  169. // stress on initial letter when spelling
  170. if(count > 1)
  171. c = phonSTRESS_3;
  172. }
  173. else
  174. {
  175. if(count != n_stress)
  176. {
  177. if(((count % 3) != 0) || (count == n_stress-1))
  178. c = phonSTRESS_3; // reduce to secondary stress
  179. }
  180. }
  181. }
  182. else
  183. if(c == 0xff)
  184. {
  185. if((control < 2) || (ix==0))
  186. continue; // don't insert pauses
  187. if(control == 4)
  188. c = phonPAUSE; // pause after each character
  189. if(((count % 3) == 0) || (control == 4))
  190. c = phonPAUSE_SHORT; // pause following a primary stress
  191. else
  192. continue; // remove marker
  193. }
  194. *phonemes++ = c;
  195. }
  196. if(control >= 2)
  197. *phonemes++ = phonPAUSE_NOLINK;
  198. *phonemes = 0;
  199. } // end of SetSpellingStress
  200. int Translator::TranslateRoman(char *word, char *ph_out)
  201. {//=====================================================
  202. int c;
  203. char *p;
  204. const char *p2;
  205. int acc;
  206. int prev;
  207. int value;
  208. int subtract;
  209. int repeat = 0;
  210. unsigned int flags;
  211. char number_chars[N_WORD_BYTES];
  212. static const char *roman_numbers = "ixcmvld";
  213. static int roman_values[] = {1,10,100,1000,5,50,500};
  214. acc = 0;
  215. prev = 0;
  216. subtract = 0x7fff;
  217. while((c = *word++) != ' ')
  218. {
  219. if((p2 = strchr(roman_numbers,c)) == NULL)
  220. return(0);
  221. value = roman_values[p2 - roman_numbers];
  222. if(value == prev)
  223. {
  224. repeat++;
  225. if(repeat >= 3)
  226. return(0);
  227. }
  228. else
  229. repeat = 0;
  230. if((prev==5) || (prev==50) || (prev==500))
  231. {
  232. if(value >= prev)
  233. return(0);
  234. }
  235. if((prev != 0) && (prev < value))
  236. {
  237. if(((acc % 10) != 0) || ((prev*10) < value))
  238. return(0);
  239. subtract = prev;
  240. value -= subtract;
  241. }
  242. else
  243. if(value >= subtract)
  244. return(0);
  245. else
  246. acc += prev;
  247. prev = value;
  248. }
  249. acc += prev;
  250. if(acc < 2)
  251. return(0);
  252. if(acc > langopts.max_roman)
  253. return(0);
  254. Lookup("_roman",ph_out); // precede by "roman" if _rom is defined in *_list
  255. p = &ph_out[strlen(ph_out)];
  256. sprintf(number_chars," %d ",acc);
  257. TranslateNumber(&number_chars[1],p,&flags,0);
  258. return(1);
  259. } // end of TranslateRoman
  260. int Translator::LookupNum2(int value, int control, char *ph_out)
  261. {//=============================================================
  262. // Lookup a 2 digit number
  263. // control bit 0: use special form of '1'
  264. // control bit 2: use feminine form of '2'
  265. int found;
  266. int ix;
  267. int units;
  268. int used_and=0;
  269. int next_phtype;
  270. char string[12]; // for looking up entries in de_list
  271. char ph_tens[50];
  272. char ph_digits[50];
  273. char ph_and[12];
  274. if((value == 1) && (control & 1))
  275. {
  276. if(Lookup("_1a",ph_out) != 0)
  277. return(0);
  278. }
  279. // is there a special pronunciation for this 2-digit number
  280. found = 0;
  281. if(control & 4)
  282. {
  283. sprintf(string,"_%df",value);
  284. found = Lookup(string,ph_digits);
  285. }
  286. if(found == 0)
  287. {
  288. sprintf(string,"_%d",value);
  289. found = Lookup(string,ph_digits);
  290. }
  291. // no, speak as tens+units
  292. if((control & 2) && (value < 10))
  293. {
  294. // speak leading zero
  295. Lookup("_0",ph_tens);
  296. }
  297. else
  298. {
  299. if(found)
  300. {
  301. strcpy(ph_out,ph_digits);
  302. return(0);
  303. }
  304. if((value % 10) == 0)
  305. {
  306. sprintf(string,"_%d0",value / 10);
  307. found = Lookup(string,ph_tens);
  308. }
  309. if(!found)
  310. {
  311. sprintf(string,"_%dX",value / 10);
  312. Lookup(string,ph_tens);
  313. }
  314. if((value % 10) == 0)
  315. {
  316. strcpy(ph_out,ph_tens);
  317. return(0);
  318. }
  319. found = 0;
  320. units = (value % 10);
  321. if(control & 4)
  322. {
  323. // is there a variant form of this number?
  324. sprintf(string,"_%df",units);
  325. found = Lookup(string,ph_digits);
  326. }
  327. if(found == 0)
  328. {
  329. sprintf(string,"_%d",units);
  330. Lookup(string,ph_digits);
  331. }
  332. }
  333. if(langopts.numbers & 0x30)
  334. {
  335. Lookup("_0and",ph_and);
  336. if(langopts.numbers & 0x10)
  337. sprintf(ph_out,"%s%s%s",ph_digits,ph_and,ph_tens);
  338. else
  339. sprintf(ph_out,"%s%s%s",ph_tens,ph_and,ph_digits);
  340. used_and = 1;
  341. }
  342. else
  343. {
  344. if(langopts.numbers & 0x200)
  345. {
  346. // remove vowel from the end of tens if units starts with a vowel (LANG=Italian)
  347. if((ix = strlen(ph_tens)-1) >= 0)
  348. {
  349. if((next_phtype = phoneme_tab[(unsigned int)(ph_digits[0])]->type) == phSTRESS)
  350. next_phtype = phoneme_tab[(unsigned int)(ph_digits[1])]->type;
  351. if((phoneme_tab[(unsigned int)(ph_tens[ix])]->type == phVOWEL) && (next_phtype == phVOWEL))
  352. ph_tens[ix] = 0;
  353. }
  354. }
  355. sprintf(ph_out,"%s%s",ph_tens,ph_digits);
  356. }
  357. if(langopts.numbers & 0x100)
  358. {
  359. // only one primary stress
  360. found = 0;
  361. for(ix=strlen(ph_out)-1; ix>=0; ix--)
  362. {
  363. if(ph_out[ix] == phonSTRESS_P)
  364. {
  365. if(found)
  366. ph_out[ix] = phonSTRESS_3;
  367. else
  368. found = 1;
  369. }
  370. }
  371. }
  372. return(used_and);
  373. } // end of LookupNum2
  374. int Translator::LookupNum3(int value, char *ph_out, int suppress_null, int thousandplex, int prev_thousands)
  375. {//=========================================================================================================
  376. // Translate a 3 digit number
  377. int found;
  378. int hundreds;
  379. int x;
  380. char string[12]; // for looking up entries in **_list
  381. char buf1[100];
  382. char buf2[100];
  383. char ph_100[20];
  384. char ph_10T[20];
  385. char ph_digits[50];
  386. char ph_thousands[50];
  387. char ph_hundred_and[12];
  388. char ph_thousand_and[12];
  389. hundreds = value / 100;
  390. buf1[0] = 0;
  391. if(hundreds > 0)
  392. {
  393. ph_thousands[0] = 0;
  394. ph_thousand_and[0] = 0;
  395. Lookup("_0C",ph_100);
  396. if((hundreds >= 10) && (((langopts.numbers & 0x0800) == 0) || (hundreds != 19)))
  397. {
  398. ph_digits[0] = 0;
  399. if(LookupThousands(hundreds / 10, thousandplex+1, ph_10T) == 0)
  400. {
  401. x = 0;
  402. if(langopts.numbers2 & (1 << (thousandplex+1)))
  403. x = 4;
  404. LookupNum2(hundreds/10, x, ph_digits);
  405. }
  406. sprintf(ph_thousands,"%s%s%c",ph_digits,ph_10T,phonPAUSE_NOLINK);
  407. hundreds %= 10;
  408. if(hundreds == 0)
  409. ph_100[0] = 0;
  410. suppress_null = 1;
  411. }
  412. ph_digits[0] = 0;
  413. if(hundreds > 0)
  414. {
  415. if((langopts.numbers & 0x100000) && (prev_thousands || (ph_thousands[0] != 0)))
  416. {
  417. Lookup("_0and",ph_thousand_and);
  418. }
  419. suppress_null = 1;
  420. found = 0;
  421. if((value % 1000) == 100)
  422. {
  423. // is there a special pronunciation for exactly 100 ?
  424. found = Lookup("_1C0",ph_digits);
  425. }
  426. if(!found)
  427. {
  428. sprintf(string,"_%dC",hundreds);
  429. found = Lookup(string,ph_digits); // is there a specific pronunciation for n-hundred ?
  430. }
  431. if(found)
  432. {
  433. ph_100[0] = 0;
  434. }
  435. else
  436. {
  437. if((hundreds > 1) || ((langopts.numbers & 0x400) == 0))
  438. {
  439. LookupNum2(hundreds,0,ph_digits);
  440. }
  441. }
  442. }
  443. sprintf(buf1,"%s%s%s%s",ph_thousands,ph_thousand_and,ph_digits,ph_100);
  444. }
  445. ph_hundred_and[0] = 0;
  446. if((langopts.numbers & 0x40) && ((value % 100) != 0))
  447. {
  448. if((value > 100) || (prev_thousands && (thousandplex==0)))
  449. {
  450. Lookup("_0and",ph_hundred_and);
  451. }
  452. }
  453. buf2[0] = 0;
  454. value = value % 100;
  455. if(value == 0)
  456. {
  457. if(suppress_null == 0)
  458. Lookup("_0",buf2);
  459. }
  460. else
  461. {
  462. x = 0;
  463. if(thousandplex==0)
  464. x = 1; // allow "eins" for 1 rather than "ein"
  465. else
  466. {
  467. if(langopts.numbers2 & (1 << thousandplex))
  468. x = 4; // use variant (feminine) for before thousands and millions
  469. }
  470. if(LookupNum2(value,x,buf2) != 0)
  471. {
  472. if(langopts.numbers & 0x80)
  473. ph_hundred_and[0] = 0; // don't put 'and' after 'hundred' if there's 'and' between tens and units
  474. }
  475. }
  476. sprintf(ph_out,"%s%s%s",buf1,ph_hundred_and,buf2);
  477. return(0);
  478. } // end of LookupNum3
  479. static const char *M_Variant(int value)
  480. {//====================================
  481. // returns M, or perhaps MA for some cases
  482. if(((value % 100)>20) || ((value % 100)<10)) // but not teens, 10 to 19
  483. {
  484. if ((translator->langopts.numbers2 & 0x40) &&
  485. ((value % 10)>=2) &&
  486. ((value % 10)<=4))
  487. {
  488. // for Polish language - two forms of plural!
  489. return("0MA");
  490. }
  491. if((translator->langopts.numbers2 & 0x80) &&
  492. ((value % 10)==1))
  493. {
  494. return("1MA");
  495. }
  496. }
  497. return("0M");
  498. }
  499. int Translator::LookupThousands(int value, int thousandplex, char *ph_out)
  500. {//=======================================================================
  501. int found;
  502. char string[12];
  503. char ph_of[12];
  504. char ph_thousands[40];
  505. ph_of[0] = 0;
  506. // first look fora match with the exact value of thousands
  507. sprintf(string,"_%dM%d",value,thousandplex);
  508. if((found = Lookup(string,ph_thousands)) == 0)
  509. {
  510. if((value % 100) >= 20)
  511. {
  512. Lookup("_0of",ph_of);
  513. }
  514. sprintf(string,"_%s%d",M_Variant(value),thousandplex);
  515. if(Lookup(string,ph_thousands) == 0)
  516. {
  517. // repeat "thousand" if higher order names are not available
  518. sprintf(string,"_%dM1",value);
  519. if((found = Lookup(string,ph_thousands)) == 0)
  520. Lookup("_0M1",ph_thousands);
  521. }
  522. }
  523. sprintf(ph_out,"%s%s",ph_of,ph_thousands);
  524. return(found);
  525. }
  526. int Translator::TranslateNumber_1(char *word, char *ph_out, unsigned int *flags, int wflags)
  527. {//=========================================================================================
  528. // Number translation with various options
  529. // the "word" may be up to 4 digits
  530. // "words" of 3 digits may be preceded by another number "word" for thousands or millions
  531. int n_digits;
  532. int value;
  533. int ix;
  534. unsigned char c;
  535. int suppress_null = 0;
  536. int decimal_point = 0;
  537. int thousandplex = 0;
  538. int thousands_inc = 0;
  539. int prev_thousands = 0;
  540. int this_value;
  541. static int prev_value;
  542. int decimal_count;
  543. int max_decimal_count;
  544. char string[12]; // for looking up entries in de_list
  545. char buf1[100];
  546. char ph_append[50];
  547. char ph_buf[200];
  548. char ph_buf2[50];
  549. static const char str_pause[2] = {phonPAUSE_NOLINK,0};
  550. for(ix=0; isdigit(word[ix]); ix++) ;
  551. n_digits = ix;
  552. value = this_value = atoi(word);
  553. ph_append[0] = 0;
  554. ph_buf2[0] = 0;
  555. // is there a previous thousands part (as a previous "word") ?
  556. if((n_digits == 3) && (word[-2] == langopts.thousands_sep) && isdigit(word[-3]))
  557. {
  558. prev_thousands = 1;
  559. }
  560. else
  561. if((langopts.thousands_sep == ' ') || (langopts.numbers & 0x1000))
  562. {
  563. // thousands groups can be separated by spaces
  564. if((n_digits == 3) && isdigit(word[-2]))
  565. {
  566. prev_thousands = 1;
  567. }
  568. }
  569. if((word[0] == '0') && (prev_thousands == 0) && (word[1] != langopts.decimal_sep))
  570. {
  571. if((n_digits == 2) && (word[3] == ':') && isdigit(word[5]) && isspace(word[7]))
  572. {
  573. // looks like a time 02:30, omit the leading zero
  574. }
  575. else
  576. {
  577. return(0); // number string with leading zero, speak as individual digits
  578. }
  579. }
  580. if((langopts.numbers & 0x1000) && (word[n_digits] == ' '))
  581. thousands_inc = 1;
  582. else
  583. if(word[n_digits] == langopts.thousands_sep)
  584. thousands_inc = 2;
  585. if(thousands_inc > 0)
  586. {
  587. // if the following "words" are three-digit groups, count them and add
  588. // a "thousand"/"million" suffix to this one
  589. ix = n_digits + thousands_inc;
  590. while(isdigit(word[ix]) && isdigit(word[ix+1]) && isdigit(word[ix+2]))
  591. {
  592. thousandplex++;
  593. if(word[ix+3] == langopts.thousands_sep)
  594. ix += (3 + thousands_inc);
  595. else
  596. break;
  597. }
  598. }
  599. if((value == 0) && prev_thousands)
  600. {
  601. suppress_null = 1;
  602. }
  603. if((word[n_digits] == langopts.decimal_sep) && isdigit(word[n_digits+1]))
  604. {
  605. // this "word" ends with a decimal point
  606. Lookup("_dpt",ph_append);
  607. decimal_point = 1;
  608. }
  609. else
  610. if(suppress_null == 0)
  611. {
  612. if(thousands_inc > 0)
  613. {
  614. if((thousandplex > 0) && (value < 1000))
  615. {
  616. if(langopts.numbers2 & 0x100)
  617. {
  618. if((thousandplex == 1) && (value >= 100))
  619. {
  620. // special word for 100,000's
  621. char ph_buf3[20];
  622. sprintf(string,"_%dL",value / 100);
  623. if(Lookup(string,ph_buf2) == 0)
  624. {
  625. LookupNum2(value/100,0,ph_buf2);
  626. Lookup("_0L",ph_buf3);
  627. strcat(ph_buf2,ph_buf3);
  628. }
  629. value %= 100;
  630. if(value == 0)
  631. suppress_null = 1;
  632. }
  633. }
  634. if((suppress_null == 0) && (LookupThousands(value,thousandplex,ph_append)))
  635. {
  636. // found an exact match for N thousand
  637. value = 0;
  638. suppress_null = 1;
  639. }
  640. }
  641. }
  642. }
  643. else
  644. if((thousandplex > 1) && prev_thousands && (prev_value > 0))
  645. {
  646. sprintf(string,"_%s%d",M_Variant(value),thousandplex+1);
  647. if(Lookup(string,buf1)==0)
  648. {
  649. // speak this thousandplex if there was no word for the previous thousandplex
  650. sprintf(string,"_0M%d",thousandplex);
  651. Lookup(string,ph_append);
  652. }
  653. }
  654. if((ph_append[0] == 0) && (word[n_digits] == '.') && (thousandplex == 0))
  655. {
  656. Lookup("_.",ph_append);
  657. }
  658. LookupNum3(value, ph_buf, suppress_null, thousandplex, prev_thousands);
  659. sprintf(ph_out,"%s%s%s",ph_buf2,ph_buf,ph_append);
  660. while(decimal_point)
  661. {
  662. n_digits++;
  663. decimal_count = 0;
  664. while(isdigit(word[n_digits+decimal_count]))
  665. decimal_count++;
  666. if(decimal_count > 1)
  667. {
  668. max_decimal_count = 2;
  669. switch(langopts.numbers & 0xe000)
  670. {
  671. case 0x8000:
  672. max_decimal_count = 5;
  673. case 0x4000:
  674. // French/Polish decimal fraction
  675. while(word[n_digits] == '0')
  676. {
  677. Lookup("_0",buf1);
  678. strcat(ph_out,buf1);
  679. decimal_count--;
  680. n_digits++;
  681. }
  682. if(decimal_count <= max_decimal_count)
  683. {
  684. LookupNum3(atoi(&word[n_digits]),buf1,0,0,0);
  685. strcat(ph_out,buf1);
  686. n_digits += decimal_count;
  687. }
  688. break;
  689. case 0x2000:
  690. // Italian decimal fractions
  691. if((decimal_count < 4) || ((decimal_count==4) && (word[n_digits] != '0')))
  692. {
  693. LookupNum3(atoi(&word[n_digits]),buf1,0,0,0);
  694. strcat(ph_out,buf1);
  695. if(word[n_digits]=='0')
  696. {
  697. // decimal part has leading zeros, so add a "hundredths" or "thousandths" suffix
  698. sprintf(string,"_0Z%d",decimal_count);
  699. Lookup(string,buf1);
  700. strcat(ph_out,buf1);
  701. }
  702. n_digits += decimal_count;
  703. }
  704. break;
  705. case 0x6000:
  706. // Romanian decimal fractions
  707. if((decimal_count <= 4) && (word[n_digits] != '0'))
  708. {
  709. LookupNum3(atoi(&word[n_digits]),buf1,0,0,0);
  710. strcat(ph_out,buf1);
  711. n_digits += decimal_count;
  712. }
  713. break;
  714. }
  715. }
  716. while(isdigit(c = word[n_digits]) && (strlen(ph_out) < (N_WORD_PHONEMES - 10)))
  717. {
  718. value = word[n_digits++] - '0';
  719. LookupNum2(value, 1, buf1);
  720. strcat(ph_out,buf1);
  721. }
  722. // something after the decimal part ?
  723. if(Lookup("_dpt2",buf1))
  724. strcat(ph_out,buf1);
  725. if(c == langopts.decimal_sep)
  726. {
  727. Lookup("_dpt",buf1);
  728. strcat(ph_out,buf1);
  729. }
  730. else
  731. {
  732. decimal_point = 0;
  733. }
  734. }
  735. if((ph_out[0] != 0) && (ph_out[0] != phonSWITCH))
  736. {
  737. int next_char;
  738. char *p;
  739. p = &word[n_digits+1];
  740. p += utf8_in(&next_char,p,0);
  741. if((langopts.numbers & NUM_NOPAUSE) && (next_char == ' '))
  742. utf8_in(&next_char,p,0);
  743. if(!iswalpha(next_char))
  744. strcat(ph_out,str_pause); // don't add pause for 100s, 6th, etc.
  745. }
  746. *flags = FLAG_FOUND;
  747. prev_value = this_value;
  748. return(1);
  749. } // end of TranslateNumber_1
  750. int Translator::TranslateNumber(char *word1, char *ph_out, unsigned int *flags, int wflags)
  751. {//=======================================================================================
  752. if(option_sayas == SAYAS_DIGITS1)
  753. return(0); // speak digits individually
  754. if((langopts.numbers & 0x3) == 1)
  755. return(TranslateNumber_1(word1,ph_out,flags,wflags));
  756. return(0);
  757. } // end of TranslateNumber