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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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(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. hundreds = value / 100;
  396. buf1[0] = 0;
  397. if(hundreds > 0)
  398. {
  399. ph_thousands[0] = 0;
  400. Lookup("_0C",ph_100);
  401. if((hundreds >= 10) && ((langopts.numbers & 0x0800) || (hundreds != 19)))
  402. {
  403. ph_digits[0] = 0;
  404. if(LookupThousands(hundreds / 10, thousandplex+1, ph_10T) == 0)
  405. {
  406. x = 0;
  407. if(langopts.numbers2 & (1 << (thousandplex+1)))
  408. x = 4;
  409. LookupNum2(hundreds/10, x, ph_digits);
  410. }
  411. sprintf(ph_thousands,"%s%s%c",ph_digits,ph_10T,phonPAUSE_NOLINK);
  412. hundreds %= 10;
  413. if(hundreds == 0)
  414. ph_100[0] = 0;
  415. suppress_null = 1;
  416. }
  417. ph_digits[0] = 0;
  418. if(hundreds > 0)
  419. {
  420. suppress_null = 1;
  421. found = 0;
  422. if((value % 1000) == 100)
  423. {
  424. // is there a special pronunciation for exactly 100 ?
  425. found = Lookup("_1C0",ph_digits);
  426. }
  427. if(!found)
  428. {
  429. sprintf(string,"_%dC",hundreds);
  430. found = Lookup(string,ph_digits); // is there a specific pronunciation for n-hundred ?
  431. }
  432. if(found)
  433. {
  434. ph_100[0] = 0;
  435. }
  436. else
  437. {
  438. if((hundreds > 1) || ((langopts.numbers & 0x400) == 0))
  439. {
  440. LookupNum2(hundreds,0,ph_digits);
  441. }
  442. }
  443. }
  444. sprintf(buf1,"%s%s%s",ph_thousands,ph_digits,ph_100);
  445. }
  446. ph_hundred_and[0] = 0;
  447. if((langopts.numbers & 0x40) && ((value % 100) != 0))
  448. {
  449. if((value > 100) || (prev_thousands && (thousandplex==0)))
  450. {
  451. Lookup("_0and",ph_hundred_and);
  452. }
  453. }
  454. buf2[0] = 0;
  455. value = value % 100;
  456. if(value == 0)
  457. {
  458. if(suppress_null == 0)
  459. Lookup("_0",buf2);
  460. }
  461. else
  462. {
  463. x = 0;
  464. if(thousandplex==0)
  465. x = 1; // allow "eins" for 1 rather than "ein"
  466. else
  467. {
  468. if(langopts.numbers2 & (1 << thousandplex))
  469. x = 4; // use variant (feminine) for before thousands and millions
  470. }
  471. if(LookupNum2(value,x,buf2) != 0)
  472. {
  473. if(langopts.numbers & 0x80)
  474. ph_hundred_and[0] = 0; // don't put 'and' after 'hundred' if there's 'and' between tens and units
  475. }
  476. }
  477. sprintf(ph_out,"%s%s%s",buf1,ph_hundred_and,buf2);
  478. return(0);
  479. } // end of LookupNum3
  480. static const char *M_Variant(int value)
  481. {//====================================
  482. // returns M, or perhaps MA for some cases
  483. if(((value % 100)>20) || ((value % 100)<10)) // but not teens, 10 to 19
  484. {
  485. if ((translator->langopts.numbers2 & 0x40) &&
  486. ((value % 10)>=2) &&
  487. ((value % 10)<=4))
  488. {
  489. // for Polish language - two forms of plural!
  490. return("0MA");
  491. }
  492. if((translator->langopts.numbers2 & 0x80) &&
  493. ((value % 10)==1))
  494. {
  495. return("1MA");
  496. }
  497. }
  498. return("0M");
  499. }
  500. int Translator::LookupThousands(int value, int thousandplex, char *ph_out)
  501. {//=======================================================================
  502. int found;
  503. char string[12];
  504. char ph_of[12];
  505. char ph_thousands[40];
  506. ph_of[0] = 0;
  507. // first look fora match with the exact value of thousands
  508. sprintf(string,"_%dM%d",value,thousandplex);
  509. if((found = Lookup(string,ph_thousands)) == 0)
  510. {
  511. if((value % 100) >= 20)
  512. {
  513. Lookup("_0of",ph_of);
  514. }
  515. sprintf(string,"_%s%d",M_Variant(value),thousandplex);
  516. if(Lookup(string,ph_thousands) == 0)
  517. {
  518. // repeat "thousand" if higher order names are not available
  519. sprintf(string,"_%dM1",value);
  520. if((found = Lookup(string,ph_thousands)) == 0)
  521. Lookup("_0M1",ph_thousands);
  522. }
  523. }
  524. sprintf(ph_out,"%s%s",ph_of,ph_thousands);
  525. return(found);
  526. }
  527. int Translator::TranslateNumber_1(char *word, char *ph_out, unsigned int *flags, int wflags)
  528. {//=========================================================================================
  529. // Number translation with various options
  530. // the "word" may be up to 4 digits
  531. // "words" of 3 digits may be preceded by another number "word" for thousands or millions
  532. int n_digits;
  533. int value;
  534. int ix;
  535. unsigned char c;
  536. int suppress_null = 0;
  537. int decimal_point = 0;
  538. int thousandplex = 0;
  539. int thousands_inc = 0;
  540. int prev_thousands = 0;
  541. int this_value;
  542. static int prev_value;
  543. int 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. switch(langopts.numbers & 0x6000)
  669. {
  670. case 0x4000:
  671. // French/Polish decimal fraction
  672. while(word[n_digits] == '0')
  673. {
  674. Lookup("_0",buf1);
  675. strcat(ph_out,buf1);
  676. decimal_count--;
  677. n_digits++;
  678. }
  679. if(decimal_count < 6)
  680. {
  681. LookupNum3(atoi(&word[n_digits]),buf1,0,0,0);
  682. strcat(ph_out,buf1);
  683. n_digits += decimal_count;
  684. }
  685. break;
  686. case 0x2000:
  687. // Italian decimal fractions
  688. if((decimal_count < 4) || ((decimal_count==4) && (word[n_digits] != '0')))
  689. {
  690. LookupNum3(atoi(&word[n_digits]),buf1,0,0,0);
  691. strcat(ph_out,buf1);
  692. if(word[n_digits]=='0')
  693. {
  694. // decimal part has leading zeros, so add a "hundredths" or "thousandths" suffix
  695. sprintf(string,"_0Z%d",decimal_count);
  696. Lookup(string,buf1);
  697. strcat(ph_out,buf1);
  698. }
  699. n_digits += decimal_count;
  700. }
  701. break;
  702. case 0x6000:
  703. // Romanian decimal fractions
  704. if((decimal_count <= 4) && (word[n_digits] != '0'))
  705. {
  706. LookupNum3(atoi(&word[n_digits]),buf1,0,0,0);
  707. strcat(ph_out,buf1);
  708. n_digits += decimal_count;
  709. }
  710. break;
  711. }
  712. }
  713. while(isdigit(c = word[n_digits]) && (strlen(ph_out) < (N_WORD_PHONEMES - 10)))
  714. {
  715. value = word[n_digits++] - '0';
  716. LookupNum2(value, 1, buf1);
  717. strcat(ph_out,buf1);
  718. }
  719. // something after the decimal part ?
  720. if(Lookup("_dpt2",buf1))
  721. strcat(ph_out,buf1);
  722. if(c == langopts.decimal_sep)
  723. {
  724. Lookup("_dpt",buf1);
  725. strcat(ph_out,buf1);
  726. }
  727. else
  728. {
  729. decimal_point = 0;
  730. }
  731. }
  732. if((ph_out[0] != 0) && (ph_out[0] != phonSWITCH))
  733. {
  734. int next_char;
  735. char *p;
  736. p = &word[n_digits+1];
  737. p += utf8_in(&next_char,p,0);
  738. if((langopts.numbers & NUM_NOPAUSE) && (next_char == ' '))
  739. utf8_in(&next_char,p,0);
  740. if(!iswalpha(next_char))
  741. strcat(ph_out,str_pause); // don't add pause for 100s, 6th, etc.
  742. }
  743. *flags = FLAG_FOUND;
  744. prev_value = this_value;
  745. return(1);
  746. } // end of TranslateNumber_1
  747. int Translator::TranslateNumber(char *word1, char *ph_out, unsigned int *flags, int wflags)
  748. {//=======================================================================================
  749. if(option_sayas == SAYAS_DIGITS1)
  750. return(0); // speak digits individually
  751. if((langopts.numbers & 0x3) == 1)
  752. return(TranslateNumber_1(word1,ph_out,flags,wflags));
  753. return(0);
  754. } // end of TranslateNumber