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

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