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.

translate.c 51KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  1. /*
  2. * Copyright (C) 2005 to 2014 by Jonathan Duddington
  3. * email: [email protected]
  4. * Copyright (C) 2015-2017 Reece H. Dunn
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see: <http://www.gnu.org/licenses/>.
  18. */
  19. #include "config.h"
  20. #include <ctype.h>
  21. #include <stdbool.h>
  22. #include <stdint.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <wchar.h>
  27. #include <wctype.h>
  28. #include <espeak-ng/espeak_ng.h>
  29. #include <espeak-ng/speak_lib.h>
  30. #include <espeak-ng/encoding.h>
  31. #include "translate.h"
  32. #include "common.h"
  33. #include "dictionary.h" // for TranslateRules, LookupDictList, Cha...
  34. #include "phoneme.h" // for phonSWITCH, PHONEME_TAB, phonPAUSE_...
  35. #include "phonemelist.h" // for MakePhonemeList
  36. #include "readclause.h" // for towlower2, Eof, ReadClause, is_str_...
  37. #include "synthdata.h" // for SelectPhonemeTable, LookupPhonemeTable
  38. #include "synthesize.h" // for PHONEME_LIST2, N_PHONEME_LIST, PHON...
  39. #include "ucd/ucd.h" // for ucd_toupper
  40. #include "voice.h" // for voice, voice_t
  41. #include "speech.h" // for MAKE_MEM_UNDEFINED
  42. #include "translateword.h"
  43. Translator *translator = NULL; // the main translator
  44. Translator *translator2 = NULL; // secondary translator for certain words
  45. static char translator2_language[20] = { 0 };
  46. Translator *translator3 = NULL; // tertiary translator for certain words
  47. static char translator3_language[20] = { 0 };
  48. FILE *f_trans = NULL; // phoneme output text
  49. int option_tone_flags = 0; // bit 8=emphasize allcaps, bit 9=emphasize penultimate stress
  50. int option_phonemes = 0;
  51. int option_phoneme_events = 0;
  52. int option_endpause = 0; // suppress pause after end of text
  53. int option_capitals = 0;
  54. int option_punctuation = 0;
  55. int option_sayas = 0;
  56. static int option_sayas2 = 0; // used in translate_clause()
  57. static int option_emphasis = 0; // 0=normal, 1=normal, 2=weak, 3=moderate, 4=strong
  58. int option_ssml = 0;
  59. int option_phoneme_input = 0; // allow [[phonemes]] in input
  60. int option_wordgap = 0;
  61. static int count_sayas_digits;
  62. int skip_sentences;
  63. int skip_words;
  64. int skip_characters;
  65. char skip_marker[N_MARKER_LENGTH];
  66. bool skipping_text; // waiting until word count, sentence count, or named marker is reached
  67. int end_character_position;
  68. int count_sentences;
  69. int count_words;
  70. int clause_start_char;
  71. int clause_start_word;
  72. bool new_sentence;
  73. static int word_emphasis = 0; // set if emphasis level 3 or 4
  74. static int embedded_flag = 0; // there are embedded commands to be applied to the next phoneme, used in TranslateWord2()
  75. static int max_clause_pause = 0;
  76. static bool any_stressed_words;
  77. int pre_pause;
  78. ALPHABET *current_alphabet;
  79. char word_phonemes[N_WORD_PHONEMES]; // a word translated into phoneme codes
  80. int n_ph_list2;
  81. PHONEME_LIST2 ph_list2[N_PHONEME_LIST]; // first stage of text->phonemes
  82. wchar_t option_punctlist[N_PUNCTLIST] = { 0 };
  83. // these are overridden by defaults set in the "speak" file
  84. int option_linelength = 0;
  85. #define N_EMBEDDED_LIST 250
  86. static int embedded_ix;
  87. static int embedded_read;
  88. unsigned int embedded_list[N_EMBEDDED_LIST];
  89. // the source text of a single clause (UTF8 bytes)
  90. static char source[N_TR_SOURCE+40]; // extra space for embedded command & voice change info at end
  91. int n_replace_phonemes;
  92. REPLACE_PHONEMES replace_phonemes[N_REPLACE_PHONEMES];
  93. // other characters which break a word, but don't produce a pause
  94. static const unsigned short breaks[] = { '_', 0 };
  95. void DeleteTranslator(Translator *tr)
  96. {
  97. if (!tr) return;
  98. if (tr->data_dictlist != NULL)
  99. free(tr->data_dictlist);
  100. free(tr);
  101. }
  102. int lookupwchar(const unsigned short *list, int c)
  103. {
  104. // Is the character c in the list ?
  105. int ix;
  106. for (ix = 0; list[ix] != 0; ix++) {
  107. if (list[ix] == c)
  108. return ix+1;
  109. }
  110. return 0;
  111. }
  112. char *strchr_w(const char *s, int c)
  113. {
  114. // return NULL for any non-ascii character
  115. if (c >= 0x80)
  116. return NULL;
  117. return strchr((char *)s, c); // (char *) is needed for Borland compiler
  118. }
  119. int TranslateWord(Translator *tr, char *word_start, WORD_TAB *wtab, char *word_out)
  120. {
  121. char words_phonemes[N_WORD_PHONEMES]; // a word translated into phoneme codes
  122. char *phonemes = words_phonemes;
  123. int available = N_WORD_PHONEMES;
  124. bool first_word = true;
  125. int flags = TranslateWord3(tr, word_start, wtab, word_out, &any_stressed_words, current_alphabet, word_phonemes, sizeof(word_phonemes));
  126. if (flags & FLAG_TEXTMODE && word_out) {
  127. // Ensure that start of word rules match with the replaced text,
  128. // so that emoji and other characters are pronounced correctly.
  129. char word[N_WORD_BYTES+1];
  130. word[0] = 0;
  131. word[1] = ' ';
  132. strcpy(word+2, word_out);
  133. word_out = word+2;
  134. while (*word_out && available > 1) {
  135. int c;
  136. utf8_in(&c, word_out);
  137. if (iswupper(c)) {
  138. wtab->flags |= FLAG_FIRST_UPPER;
  139. utf8_out(tolower(c), word_out);
  140. } else {
  141. wtab->flags &= ~FLAG_FIRST_UPPER;
  142. }
  143. TranslateWord3(tr, word_out, wtab, NULL, &any_stressed_words, current_alphabet, word_phonemes, sizeof(word_phonemes));
  144. int n;
  145. if (first_word) {
  146. n = snprintf(phonemes, available, "%s", word_phonemes);
  147. first_word = false;
  148. } else {
  149. n = snprintf(phonemes, available, "%c%s", phonEND_WORD, word_phonemes);
  150. }
  151. available -= n;
  152. phonemes += n;
  153. // skip to the next word in a multi-word replacement. Always skip at least one word.
  154. for (dictionary_skipwords++; dictionary_skipwords > 0; dictionary_skipwords--) {
  155. while (!isspace(*word_out)) ++word_out;
  156. while (isspace(*word_out)) ++word_out;
  157. }
  158. }
  159. // If the list file contains a text replacement to another
  160. // entry in the list file, e.g.:
  161. // ripost riposte $text
  162. // riposte rI#p0st
  163. // calling it from a prefix or suffix rule such as 'riposted'
  164. // causes word_out[0] to be NULL, as TranslateWord3 has the
  165. // information needed to perform the mapping. In this case,
  166. // no phonemes have been written in this loop and the phonemes
  167. // have been calculated, so don't override them.
  168. if (phonemes != words_phonemes) {
  169. snprintf(word_phonemes, sizeof(word_phonemes), "%s", words_phonemes);
  170. }
  171. }
  172. return flags;
  173. }
  174. static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode)
  175. {
  176. p->phcode = phcode;
  177. p->stresslevel = 0;
  178. p->tone_ph = 0;
  179. p->synthflags = embedded_flag;
  180. p->sourceix = 0;
  181. embedded_flag = 0;
  182. }
  183. static int CountSyllables(unsigned char *phonemes)
  184. {
  185. int count = 0;
  186. int phon;
  187. while ((phon = *phonemes++) != 0) {
  188. if (phoneme_tab[phon]->type == phVOWEL)
  189. count++;
  190. }
  191. return count;
  192. }
  193. static void Word_EmbeddedCmd()
  194. {
  195. // Process embedded commands for emphasis, sayas, and break
  196. int embedded_cmd;
  197. int value;
  198. do {
  199. embedded_cmd = embedded_list[embedded_read++];
  200. value = embedded_cmd >> 8;
  201. switch (embedded_cmd & 0x1f)
  202. {
  203. case EMBED_Y:
  204. option_sayas = value;
  205. break;
  206. case EMBED_F:
  207. option_emphasis = value;
  208. break;
  209. case EMBED_B:
  210. // break command
  211. if (value == 0)
  212. pre_pause = 0; // break=none
  213. else
  214. pre_pause += value;
  215. break;
  216. }
  217. } while (((embedded_cmd & 0x80) == 0) && (embedded_read < embedded_ix));
  218. }
  219. static int SetAlternateTranslator(const char *new_language, Translator **translator, char translator_language[20])
  220. {
  221. // Set alternate translator to a second language
  222. int new_phoneme_tab;
  223. if ((new_phoneme_tab = SelectPhonemeTableName(new_language)) >= 0) {
  224. if ((*translator != NULL) && (strcmp(new_language, translator_language) != 0)) {
  225. // we already have an alternative translator, but not for the required language, delete it
  226. DeleteTranslator(*translator);
  227. *translator = NULL;
  228. }
  229. if (*translator == NULL) {
  230. *translator = SelectTranslator(new_language);
  231. strcpy(translator_language, new_language);
  232. if (LoadDictionary(*translator, (*translator)->dictionary_name, 0) != 0) {
  233. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  234. new_phoneme_tab = -1;
  235. translator_language[0] = 0;
  236. }
  237. (*translator)->phoneme_tab_ix = new_phoneme_tab;
  238. }
  239. }
  240. if (*translator != NULL)
  241. (*translator)->phonemes_repeat[0] = 0;
  242. return new_phoneme_tab;
  243. }
  244. int SetTranslator2(const char *new_language)
  245. {
  246. return SetAlternateTranslator(new_language, &translator2, translator2_language);
  247. }
  248. int SetTranslator3(const char *new_language)
  249. {
  250. return SetAlternateTranslator(new_language, &translator3, translator3_language);
  251. }
  252. static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pause)
  253. {
  254. int flags = 0;
  255. int stress;
  256. int next_stress;
  257. int next_tone = 0;
  258. unsigned char *p;
  259. int srcix;
  260. int found_dict_flag;
  261. unsigned char ph_code;
  262. PHONEME_LIST2 *plist2;
  263. PHONEME_TAB *ph;
  264. int max_stress;
  265. int max_stress_ix = 0;
  266. int prev_vowel = -1;
  267. int pitch_raised = 0;
  268. int switch_phonemes = -1;
  269. bool first_phoneme = true;
  270. int source_ix;
  271. int len;
  272. int ix;
  273. int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
  274. const char *new_language;
  275. int bad_phoneme;
  276. int word_flags;
  277. int word_copy_len;
  278. char word_copy[N_WORD_BYTES+1];
  279. char word_replaced[N_WORD_BYTES+1];
  280. char old_dictionary_name[40];
  281. len = wtab->length;
  282. if (len > 31) len = 31;
  283. source_ix = (wtab->sourceix & 0x7ff) | (len << 11); // bits 0-10 sourceix, bits 11-15 word length
  284. word_flags = wtab[0].flags;
  285. if (word_flags & FLAG_EMBEDDED) {
  286. wtab[0].flags &= ~FLAG_EMBEDDED; // clear it in case we call TranslateWord2() again for the same word
  287. embedded_flag = SFLAG_EMBEDDED;
  288. Word_EmbeddedCmd();
  289. }
  290. if (n_ph_list2 >= N_PHONEME_LIST-2) {
  291. // No room, can't translate anything
  292. return 0;
  293. }
  294. if ((word[0] == 0) || (word_flags & FLAG_DELETE_WORD)) {
  295. // nothing to translate. Add a dummy phoneme to carry any embedded commands
  296. if (embedded_flag) {
  297. ph_list2[n_ph_list2].phcode = phonEND_WORD;
  298. ph_list2[n_ph_list2].stresslevel = 0;
  299. ph_list2[n_ph_list2].wordstress = 0;
  300. ph_list2[n_ph_list2].tone_ph = 0;
  301. ph_list2[n_ph_list2].synthflags = embedded_flag;
  302. ph_list2[n_ph_list2].sourceix = 0;
  303. n_ph_list2++;
  304. embedded_flag = 0;
  305. }
  306. word_phonemes[0] = 0;
  307. return 0;
  308. }
  309. if (n_ph_list2 >= N_PHONEME_LIST-7-2) {
  310. // We may require up to 7 phonemes, plus the 2 phonemes from the caller, can't translate safely
  311. return 0;
  312. }
  313. // after a $pause word attribute, ignore a $pause attribute on the next two words
  314. if (tr->prepause_timeout > 0)
  315. tr->prepause_timeout--;
  316. if ((option_sayas & 0xf0) == 0x10) {
  317. if (!(word_flags & FLAG_FIRST_WORD)) {
  318. // SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
  319. pre_pause += 4;
  320. }
  321. }
  322. if (word_flags & FLAG_FIRST_UPPER) {
  323. if ((option_capitals > 2) && (embedded_ix < N_EMBEDDED_LIST-6)) {
  324. // indicate capital letter by raising pitch
  325. if (embedded_flag)
  326. embedded_list[embedded_ix-1] &= ~0x80; // already embedded command before this word, remove terminator
  327. if ((pitch_raised = option_capitals) == 3)
  328. pitch_raised = 20; // default pitch raise for capitals
  329. embedded_list[embedded_ix++] = EMBED_P+0x40+0x80 + (pitch_raised << 8); // raise pitch
  330. embedded_flag = SFLAG_EMBEDDED;
  331. }
  332. }
  333. p = (unsigned char *)word_phonemes;
  334. if (word_flags & FLAG_PHONEMES) {
  335. // The input is in phoneme mnemonics, not language text
  336. int c1;
  337. char lang_name[12];
  338. if (memcmp(word, "_^_", 3) == 0) {
  339. // switch languages
  340. word += 3;
  341. for (ix = 0;;) {
  342. c1 = *word++;
  343. if ((c1 == ' ') || (c1 == 0))
  344. break;
  345. lang_name[ix++] = tolower(c1);
  346. }
  347. lang_name[ix] = 0;
  348. if ((ix = LookupPhonemeTable(lang_name)) > 0) {
  349. SelectPhonemeTable(ix);
  350. word_phonemes[0] = phonSWITCH;
  351. word_phonemes[1] = ix;
  352. word_phonemes[2] = 0;
  353. }
  354. } else
  355. EncodePhonemes(word, word_phonemes, &bad_phoneme);
  356. flags = FLAG_FOUND;
  357. } else {
  358. int c2;
  359. ix = 0;
  360. while (((c2 = word_copy[ix] = word[ix]) != ' ') && (c2 != 0) && (ix < N_WORD_BYTES)) ix++;
  361. word_copy_len = ix;
  362. word_replaced[2] = 0;
  363. flags = TranslateWord(translator, word, wtab, &word_replaced[2]);
  364. if (flags & FLAG_SPELLWORD) {
  365. // re-translate the word as individual letters, separated by spaces
  366. memcpy(word, word_copy, word_copy_len);
  367. return flags;
  368. }
  369. if ((flags & FLAG_COMBINE) && !(wtab[1].flags & FLAG_PHONEMES)) {
  370. char *p2;
  371. bool ok = true;
  372. unsigned int flags2[2];
  373. int c_word2;
  374. char ph_buf[N_WORD_PHONEMES];
  375. flags2[0] = 0;
  376. sylimit = tr->langopts.param[LOPT_COMBINE_WORDS];
  377. // LANG=cs,sk
  378. // combine a preposition with the following word
  379. p2 = word;
  380. while (*p2 != ' ') p2++;
  381. utf8_in(&c_word2, p2+1); // first character of the next word;
  382. if (!iswalpha(c_word2))
  383. ok = false;
  384. if (ok == true) {
  385. strcpy(ph_buf, word_phonemes);
  386. flags2[0] = TranslateWord(translator, p2+1, wtab+1, NULL);
  387. if ((flags2[0] & FLAG_WAS_UNPRONOUNCABLE) || (word_phonemes[0] == phonSWITCH))
  388. ok = false;
  389. if (sylimit & 0x100) {
  390. // only if the second word has $alt attribute
  391. if ((flags2[0] & FLAG_ALT_TRANS) == 0)
  392. ok = false;
  393. }
  394. if ((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD)) {
  395. // not if the next word is end-of-sentence
  396. ok = false;
  397. }
  398. if (ok == false)
  399. strcpy(word_phonemes, ph_buf);
  400. }
  401. if (ok) {
  402. *p2 = '-'; // replace next space by hyphen
  403. wtab[0].flags &= ~FLAG_ALL_UPPER; // prevent it being considered an abbreviation
  404. flags = TranslateWord(translator, word, wtab, NULL); // translate the combined word
  405. if ((sylimit > 0) && (CountSyllables(p) > (sylimit & 0x1f))) {
  406. // revert to separate words
  407. *p2 = ' ';
  408. flags = TranslateWord(translator, word, wtab, NULL);
  409. } else {
  410. if (flags == 0)
  411. flags = flags2[0]; // no flags for the combined word, so use flags from the second word eg. lang-hu "nem december 7-e"
  412. flags |= FLAG_SKIPWORDS;
  413. dictionary_skipwords = 1;
  414. }
  415. }
  416. }
  417. if (p[0] == phonSWITCH) {
  418. int switch_attempt;
  419. strcpy(old_dictionary_name, dictionary_name);
  420. for (switch_attempt = 0; switch_attempt < 2; switch_attempt++) {
  421. // this word uses a different language
  422. memcpy(word, word_copy, word_copy_len);
  423. new_language = (char *)(&p[1]);
  424. if (new_language[0] == 0)
  425. new_language = ESPEAKNG_DEFAULT_VOICE;
  426. switch_phonemes = SetTranslator2(new_language);
  427. if (switch_phonemes >= 0) {
  428. // re-translate the word using the new translator
  429. wtab[0].flags |= FLAG_TRANSLATOR2;
  430. if (word_replaced[2] != 0) {
  431. word_replaced[0] = 0; // byte before the start of the word
  432. word_replaced[1] = ' ';
  433. flags = TranslateWord(translator2, &word_replaced[1], wtab, NULL);
  434. } else
  435. flags = TranslateWord(translator2, word, wtab, &word_replaced[2]);
  436. }
  437. if (p[0] != phonSWITCH)
  438. break;
  439. }
  440. if (p[0] == phonSWITCH)
  441. return FLAG_SPELLWORD;
  442. if (switch_phonemes < 0) {
  443. // language code is not recognised or 2nd translator won't translate it
  444. p[0] = phonSCHWA; // just say something
  445. p[1] = phonSCHWA;
  446. p[2] = 0;
  447. }
  448. if (switch_phonemes == -1) {
  449. strcpy(dictionary_name, old_dictionary_name);
  450. SelectPhonemeTable(voice->phoneme_tab_ix);
  451. // leave switch_phonemes set, but use the original phoneme table number.
  452. // This will suppress LOPT_REGRESSIVE_VOICING
  453. switch_phonemes = voice->phoneme_tab_ix; // original phoneme table
  454. }
  455. }
  456. if (!(word_flags & FLAG_HYPHEN)) {
  457. if (flags & FLAG_PAUSE1) {
  458. if (pre_pause < 1)
  459. pre_pause = 1;
  460. }
  461. if ((flags & FLAG_PREPAUSE) && !(word_flags & (FLAG_LAST_WORD | FLAG_FIRST_WORD)) && !(wtab[-1].flags & FLAG_FIRST_WORD) && (tr->prepause_timeout == 0)) {
  462. // the word is marked in the dictionary list with $pause
  463. if (pre_pause < 4) pre_pause = 4;
  464. tr->prepause_timeout = 3;
  465. }
  466. }
  467. if ((option_emphasis >= 3) && (pre_pause < 1))
  468. pre_pause = 1;
  469. }
  470. stress = 0;
  471. next_stress = 1;
  472. srcix = 0;
  473. max_stress = -1;
  474. found_dict_flag = 0;
  475. if ((flags & FLAG_FOUND) && !(flags & FLAG_TEXTMODE))
  476. found_dict_flag = SFLAG_DICTIONARY;
  477. // Each iteration may require up to 1 phoneme
  478. // and after this loop we may require up to 7 phonemes
  479. // and our caller requires 2 phonemes
  480. while ((pre_pause > 0) && (n_ph_list2 < N_PHONEME_LIST-7-2)) {
  481. // add pause phonemes here. Either because of punctuation (brackets or quotes) in the
  482. // text, or because the word is marked in the dictionary lookup as a conjunction
  483. if (pre_pause > 1) {
  484. SetPlist2(&ph_list2[n_ph_list2++], phonPAUSE);
  485. pre_pause -= 2;
  486. } else {
  487. SetPlist2(&ph_list2[n_ph_list2++], phonPAUSE_NOLINK);
  488. pre_pause--;
  489. }
  490. tr->end_stressed_vowel = 0; // forget about the previous word
  491. tr->prev_dict_flags[0] = 0;
  492. tr->prev_dict_flags[1] = 0;
  493. }
  494. plist2 = &ph_list2[n_ph_list2];
  495. // From here we may require up to 4+1+3 phonemes
  496. // This may require up to 4 phonemes
  497. if ((option_capitals == 1) && (word_flags & FLAG_FIRST_UPPER)) {
  498. SetPlist2(&ph_list2[n_ph_list2++], phonPAUSE_SHORT);
  499. SetPlist2(&ph_list2[n_ph_list2++], phonCAPITAL);
  500. if ((word_flags & FLAG_ALL_UPPER) && IsAlpha(word[1])) {
  501. // word > 1 letter and all capitals
  502. SetPlist2(&ph_list2[n_ph_list2++], phonPAUSE_SHORT);
  503. SetPlist2(&ph_list2[n_ph_list2++], phonCAPITAL);
  504. }
  505. }
  506. // This may require up to 1 phoneme
  507. if (switch_phonemes >= 0) {
  508. if ((p[0] == phonPAUSE) && (p[1] == phonSWITCH)) {
  509. // the new word starts with a phoneme table switch, so there's no need to switch before it.
  510. if (ph_list2[n_ph_list2-1].phcode == phonSWITCH) {
  511. // previous phoneme is also a phonSWITCH, delete it
  512. n_ph_list2--;
  513. }
  514. } else {
  515. // this word uses a different phoneme table
  516. if (ph_list2[n_ph_list2-1].phcode == phonSWITCH) {
  517. // previous phoneme is also a phonSWITCH, just change its phoneme table number
  518. n_ph_list2--;
  519. } else
  520. SetPlist2(&ph_list2[n_ph_list2], phonSWITCH);
  521. ph_list2[n_ph_list2++].tone_ph = switch_phonemes; // temporary phoneme table number
  522. }
  523. }
  524. // remove initial pause from a word if it follows a hyphen
  525. if ((word_flags & FLAG_HYPHEN) && (phoneme_tab[*p]->type == phPAUSE))
  526. p++;
  527. if ((p[0] == 0) && (embedded_flag)) {
  528. // no phonemes. Insert a very short pause to carry an embedded command
  529. p[0] = phonPAUSE_VSHORT;
  530. p[1] = 0;
  531. }
  532. // Each iteration may require up to 1 phoneme
  533. // and after this loop we may require up to 3 phonemes
  534. // and our caller requires 2 phonemes
  535. while (((ph_code = *p++) != 0) && (n_ph_list2 < N_PHONEME_LIST-3-2)) {
  536. if (ph_code == 255)
  537. continue; // unknown phoneme
  538. // Add the phonemes to the first stage phoneme list (ph_list2)
  539. ph = phoneme_tab[ph_code];
  540. if (ph == NULL) {
  541. printf("Invalid phoneme code %d\n", ph_code);
  542. continue;
  543. }
  544. if (ph_code == phonSWITCH) {
  545. ph_list2[n_ph_list2].phcode = ph_code;
  546. ph_list2[n_ph_list2].stresslevel = 0;
  547. ph_list2[n_ph_list2].sourceix = 0;
  548. ph_list2[n_ph_list2].synthflags = 0;
  549. ph_list2[n_ph_list2++].tone_ph = *p;
  550. SelectPhonemeTable(*p);
  551. p++;
  552. } else if (ph->type == phSTRESS) {
  553. // don't add stress phonemes codes to the list, but give their stress
  554. // value to the next vowel phoneme
  555. // std_length is used to hold stress number or (if >10) a tone number for a tone language
  556. if (ph->program == 0)
  557. next_stress = ph->std_length;
  558. else {
  559. // for tone languages, the tone number for a syllable follows the vowel
  560. if (prev_vowel >= 0)
  561. ph_list2[prev_vowel].tone_ph = ph_code;
  562. else
  563. next_tone = ph_code; // no previous vowel, apply to the next vowel
  564. }
  565. } else if (ph_code == phonSYLLABIC) {
  566. // mark the previous phoneme as a syllabic consonant
  567. prev_vowel = n_ph_list2-1;
  568. ph_list2[prev_vowel].synthflags |= SFLAG_SYLLABLE;
  569. ph_list2[prev_vowel].stresslevel = next_stress;
  570. } else if (ph_code == phonLENGTHEN)
  571. ph_list2[n_ph_list2-1].synthflags |= SFLAG_LENGTHEN;
  572. else if (ph_code == phonEND_WORD) {
  573. // a || symbol in a phoneme string was used to indicate a word boundary
  574. // Don't add this phoneme to the list, but make sure the next phoneme has
  575. // a newword indication
  576. srcix = source_ix+1;
  577. } else if (ph_code == phonX1) {
  578. // a language specific action
  579. if (tr->langopts.param[LOPT_IT_DOUBLING])
  580. flags |= FLAG_DOUBLING;
  581. } else {
  582. ph_list2[n_ph_list2].phcode = ph_code;
  583. ph_list2[n_ph_list2].tone_ph = 0;
  584. ph_list2[n_ph_list2].synthflags = embedded_flag | found_dict_flag;
  585. embedded_flag = 0;
  586. ph_list2[n_ph_list2].sourceix = srcix;
  587. srcix = 0;
  588. if (ph->type == phVOWEL) {
  589. stress = next_stress;
  590. next_stress = 1; // default is 'unstressed'
  591. if (stress >= 4)
  592. any_stressed_words = true;
  593. if ((prev_vowel >= 0) && (n_ph_list2-1) != prev_vowel)
  594. ph_list2[n_ph_list2-1].stresslevel = stress; // set stress for previous consonant
  595. ph_list2[n_ph_list2].synthflags |= SFLAG_SYLLABLE;
  596. prev_vowel = n_ph_list2;
  597. if (stress > max_stress) {
  598. max_stress = stress;
  599. max_stress_ix = n_ph_list2;
  600. }
  601. if (next_tone != 0) {
  602. ph_list2[n_ph_list2].tone_ph = next_tone;
  603. next_tone = 0;
  604. }
  605. } else {
  606. if (first_phoneme && tr->langopts.param[LOPT_IT_DOUBLING]) {
  607. if (((tr->prev_dict_flags[0] & FLAG_DOUBLING) && (tr->langopts.param[LOPT_IT_DOUBLING] & 1)) ||
  608. (tr->end_stressed_vowel && (tr->langopts.param[LOPT_IT_DOUBLING] & 2))) {
  609. // italian, double the initial consonant if the previous word ends with a
  610. // stressed vowel, or is marked with a flag
  611. ph_list2[n_ph_list2].synthflags |= SFLAG_LENGTHEN;
  612. }
  613. }
  614. }
  615. ph_list2[n_ph_list2].stresslevel = stress;
  616. n_ph_list2++;
  617. first_phoneme = false;
  618. }
  619. }
  620. // From here, we may require up to 3 phonemes
  621. // This may require up to 1 phoneme
  622. if (word_flags & FLAG_COMMA_AFTER)
  623. SetPlist2(&ph_list2[n_ph_list2++], phonPAUSE_CLAUSE);
  624. // don't set new-word if there is a hyphen before it
  625. if ((word_flags & FLAG_HYPHEN) == 0)
  626. plist2->sourceix = source_ix;
  627. tr->end_stressed_vowel = 0;
  628. if ((stress >= 4) && (phoneme_tab[ph_list2[n_ph_list2-1].phcode]->type == phVOWEL))
  629. tr->end_stressed_vowel = 1; // word ends with a stressed vowel
  630. // This may require up to 1 phoneme
  631. if (switch_phonemes >= 0) {
  632. // this word uses a different phoneme table, now switch back
  633. strcpy(dictionary_name, old_dictionary_name);
  634. SelectPhonemeTable(voice->phoneme_tab_ix);
  635. SetPlist2(&ph_list2[n_ph_list2], phonSWITCH);
  636. ph_list2[n_ph_list2++].tone_ph = voice->phoneme_tab_ix; // original phoneme table number
  637. }
  638. // This may require up to 1 phoneme
  639. if (pitch_raised > 0) {
  640. embedded_list[embedded_ix++] = EMBED_P+0x60+0x80 + (pitch_raised << 8); // lower pitch
  641. SetPlist2(&ph_list2[n_ph_list2], phonPAUSE_SHORT);
  642. ph_list2[n_ph_list2++].synthflags = SFLAG_EMBEDDED;
  643. }
  644. if (flags & FLAG_STRESS_END2) {
  645. // this's word's stress could be increased later
  646. ph_list2[max_stress_ix].synthflags |= SFLAG_PROMOTE_STRESS;
  647. }
  648. tr->prev_dict_flags[0] = flags;
  649. return flags;
  650. }
  651. static int EmbeddedCommand(unsigned int *source_index_out)
  652. {
  653. // An embedded command to change the pitch, volume, etc.
  654. // returns number of commands added to embedded_list
  655. // pitch,speed,amplitude,expression,reverb,tone,voice,sayas
  656. const char *commands = "PSARHTIVYMUBF";
  657. int value = -1;
  658. int sign = 0;
  659. unsigned char c;
  660. char *p;
  661. int cmd;
  662. int source_index = *source_index_out;
  663. c = source[source_index];
  664. if (c == '+') {
  665. sign = 0x40;
  666. source_index++;
  667. } else if (c == '-') {
  668. sign = 0x60;
  669. source_index++;
  670. }
  671. if (IsDigit09(source[source_index])) {
  672. value = atoi(&source[source_index]);
  673. while (IsDigit09(source[source_index]))
  674. source_index++;
  675. }
  676. c = source[source_index++];
  677. if (embedded_ix >= (N_EMBEDDED_LIST - 2))
  678. return 0; // list is full
  679. if ((p = strchr_w(commands, c)) == NULL)
  680. return 0;
  681. cmd = (p - commands)+1;
  682. if (value == -1) {
  683. value = embedded_default[cmd];
  684. sign = 0;
  685. }
  686. if (cmd == EMBED_Y) {
  687. option_sayas2 = value;
  688. count_sayas_digits = 0;
  689. }
  690. if (cmd == EMBED_F) {
  691. if (value >= 3)
  692. word_emphasis = FLAG_EMPHASIZED;
  693. else
  694. word_emphasis = 0;
  695. }
  696. embedded_list[embedded_ix++] = cmd + sign + (value << 8);
  697. *source_index_out = source_index;
  698. return 1;
  699. }
  700. static const char *FindReplacementChars(Translator *tr, const char **pfrom, unsigned int c, const char *next, int *ignore_next_n)
  701. {
  702. const char *from = *pfrom;
  703. while ( !is_str_totally_null(from, 4) ) {
  704. unsigned int fc = 0; // from character
  705. unsigned int nc = c; // next character
  706. const char *match_next = next;
  707. *pfrom = from;
  708. from += utf8_in((int *)&fc, from);
  709. if (nc == fc) {
  710. if (*from == 0) return from + 1;
  711. bool matched = true;
  712. int nmatched = 0;
  713. while (*from != 0) {
  714. from += utf8_in((int *)&fc, from);
  715. match_next += utf8_in((int *)&nc, match_next);
  716. nc = towlower2(nc, tr);
  717. if (nc != fc)
  718. matched = false;
  719. else
  720. nmatched++;
  721. }
  722. if (*from == 0 && matched) {
  723. *ignore_next_n = nmatched;
  724. return from + 1;
  725. }
  726. }
  727. // replacement 'from' string (skip the remaining part, if any)
  728. while (*from != '\0') from++;
  729. from++;
  730. // replacement 'to' string
  731. while (*from != '\0') from++;
  732. from++;
  733. }
  734. return NULL;
  735. }
  736. // handle .replace rule in xx_rules file
  737. static int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, const char *next, int *insert, int *wordflags)
  738. {
  739. unsigned int new_c, c2 = ' ', c_lower;
  740. int upper_case = 0;
  741. static int ignore_next_n = 0;
  742. if (ignore_next_n > 0) {
  743. ignore_next_n--;
  744. return 8;
  745. }
  746. if (c == 0) return 0;
  747. const char *from = (const char *)tr->langopts.replace_chars;
  748. if (from == NULL)
  749. return c;
  750. // there is a list of character codes to be substituted with alternative codes
  751. if (iswupper(c_lower = c)) {
  752. c_lower = towlower2(c, tr);
  753. upper_case = 1;
  754. }
  755. const char *to = FindReplacementChars(tr, &from, c_lower, next, &ignore_next_n);
  756. if (to == NULL)
  757. return c; // no substitution
  758. if (option_phonemes & espeakPHONEMES_TRACE)
  759. fprintf(f_trans, "Replace: %s > %s\n", from, to);
  760. to += utf8_in((int *)&new_c, to);
  761. if (*to != 0) {
  762. // there is a second character to be inserted
  763. // don't convert the case of the second character unless the next letter is also upper case
  764. to += utf8_in((int *)&c2, to);
  765. if (upper_case && iswupper(next_in))
  766. c2 = ucd_toupper(c2);
  767. *insert = c2;
  768. }
  769. if (upper_case)
  770. new_c = ucd_toupper(new_c);
  771. *wordflags |= FLAG_CHAR_REPLACED;
  772. return new_c;
  773. }
  774. static int TranslateChar(Translator *tr, char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert, int *wordflags)
  775. {
  776. // To allow language specific examination and replacement of characters
  777. int code;
  778. int initial;
  779. int medial;
  780. int final;
  781. int next2;
  782. static const unsigned char hangul_compatibility[0x34] = {
  783. 0, 0x00, 0x01, 0xaa, 0x02, 0xac, 0xad, 0x03,
  784. 0x04, 0x05, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb4,
  785. 0xb6, 0x06, 0x07, 0x08, 0xb9, 0x09, 0x0a, 0xbc,
  786. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x61,
  787. 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  788. 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71,
  789. 0x72, 0x73, 0x74, 0x75
  790. };
  791. // check for Korean Hangul letters
  792. if (((code = c - 0xac00) >= 0) && (c <= 0xd7af)) {
  793. // break a syllable hangul into 2 or 3 individual jamo
  794. initial = (code/28)/21;
  795. medial = (code/28) % 21;
  796. final = code % 28;
  797. if (initial == 11) {
  798. // null initial
  799. c = medial + 0x1161;
  800. if (final > 0)
  801. *insert = final + 0x11a7;
  802. } else {
  803. // extract the initial and insert the remainder with a null initial
  804. c = initial + 0x1100;
  805. *insert = (11*28*21) + (medial*28) + final + 0xac00;
  806. }
  807. return c;
  808. } else if (((code = c - 0x3130) >= 0) && (code < 0x34)) {
  809. // Hangul compatibility jamo
  810. return hangul_compatibility[code] + 0x1100;
  811. }
  812. switch (tr->translator_name)
  813. {
  814. case L('a', 'f'):
  815. case L('n', 'l'):
  816. // look for 'n and replace by a special character (unicode: schwa)
  817. if ((c == '\'') && !iswalpha(prev_in)) {
  818. utf8_in(&next2, &ptr[1]);
  819. if (IsSpace(next2)) {
  820. if ((next_in == 'n') && (tr->translator_name == L('a', 'f'))) {
  821. // n preceded by either apostrophe or U2019 "right single quotation mark"
  822. ptr[0] = ' '; // delete the n
  823. return 0x0259; // replace ' by unicode schwa character
  824. }
  825. if ((next_in == 'n') || (next_in == 't')) {
  826. // Dutch, [@n] and [@t]
  827. return 0x0259; // replace ' by unicode schwa character
  828. }
  829. }
  830. }
  831. break;
  832. }
  833. // handle .replace rule in xx_rules file
  834. return SubstituteChar(tr, c, next_in, ptr, insert, wordflags);
  835. }
  836. static const char *UCase_ga[] = { "bp", "bhf", "dt", "gc", "hA", "mb", "nd", "ng", "ts", "tA", "nA", NULL };
  837. static int UpperCaseInWord(Translator *tr, char *word, int c)
  838. {
  839. int ix;
  840. int len;
  841. const char *p;
  842. if (tr->translator_name == L('g', 'a')) {
  843. // Irish
  844. for (ix = 0;; ix++) {
  845. if ((p = UCase_ga[ix]) == NULL)
  846. break;
  847. len = strlen(p);
  848. if ((word[-len] == ' ') && (memcmp(&word[-len+1], p, len-1) == 0)) {
  849. if ((c == p[len-1]) || ((p[len-1] == 'A') && IsVowel(tr, c)))
  850. return 1;
  851. }
  852. }
  853. }
  854. return 0;
  855. }
  856. void TranslateClause(Translator *tr, int *tone_out, char **voice_change)
  857. {
  858. int ix;
  859. int c;
  860. int cc = 0;
  861. unsigned int source_index = 0;
  862. unsigned int prev_source_index = 0;
  863. int source_index_word = 0;
  864. int prev_in;
  865. int prev_out = ' ';
  866. int prev_out2;
  867. int prev_in_save = 0;
  868. int next_in;
  869. int next_in_nbytes;
  870. int char_inserted = 0;
  871. int clause_pause;
  872. int pre_pause_add = 0;
  873. int all_upper_case = FLAG_ALL_UPPER;
  874. int alpha_count = 0;
  875. bool finished = false;
  876. bool single_quoted = false;
  877. bool phoneme_mode = false;
  878. int dict_flags = 0; // returned from dictionary lookup
  879. int word_flags; // set here
  880. int next_word_flags;
  881. bool new_sentence2;
  882. int embedded_count = 0;
  883. int letter_count = 0;
  884. bool space_inserted = false;
  885. bool syllable_marked = false;
  886. bool decimal_sep_count = false;
  887. char *word;
  888. char *p;
  889. int j, k;
  890. int n_digits;
  891. int charix_top = 0;
  892. short charix[N_TR_SOURCE+4];
  893. WORD_TAB words[N_CLAUSE_WORDS];
  894. static char voice_change_name[40];
  895. int word_count = 0; // index into words
  896. char sbuf[N_TR_SOURCE];
  897. int terminator;
  898. int tone;
  899. if (tr == NULL)
  900. return;
  901. MAKE_MEM_UNDEFINED(&voice_change_name, sizeof(voice_change_name));
  902. embedded_ix = 0;
  903. embedded_read = 0;
  904. pre_pause = 0;
  905. any_stressed_words = false;
  906. if ((clause_start_char = count_characters) < 0)
  907. clause_start_char = 0;
  908. clause_start_word = count_words + 1;
  909. for (ix = 0; ix < N_TR_SOURCE; ix++)
  910. charix[ix] = 0;
  911. MAKE_MEM_UNDEFINED(&source, sizeof(source));
  912. terminator = ReadClause(tr, source, charix, &charix_top, N_TR_SOURCE, &tone, voice_change_name);
  913. if (tone_out != NULL) {
  914. if (tone == 0)
  915. *tone_out = (terminator & CLAUSE_INTONATION_TYPE) >> 12; // tone type not overridden in ReadClause, use default
  916. else
  917. *tone_out = tone; // override tone type
  918. }
  919. charix[charix_top+1] = 0;
  920. charix[charix_top+2] = 0x7fff;
  921. charix[charix_top+3] = 0;
  922. clause_pause = (terminator & CLAUSE_PAUSE) * 10; // mS
  923. if (terminator & CLAUSE_PAUSE_LONG)
  924. clause_pause = clause_pause * 32; // pause value is *320mS not *10mS
  925. for (p = source; *p != 0; p++) {
  926. if (!isspace2(*p))
  927. break;
  928. }
  929. if (*p == 0) {
  930. // No characters except spaces. This is not a sentence.
  931. // Don't add this pause, just make up the previous pause to this value;
  932. clause_pause -= max_clause_pause;
  933. if (clause_pause < 0)
  934. clause_pause = 0;
  935. if (new_sentence)
  936. terminator |= CLAUSE_TYPE_SENTENCE; // carry forward an end-of-sentence indicator
  937. max_clause_pause += clause_pause;
  938. new_sentence2 = false;
  939. } else {
  940. max_clause_pause = clause_pause;
  941. new_sentence2 = new_sentence;
  942. }
  943. tr->clause_terminator = terminator;
  944. if (new_sentence2) {
  945. count_sentences++;
  946. if (skip_sentences > 0) {
  947. skip_sentences--;
  948. if (skip_sentences == 0)
  949. skipping_text = false;
  950. }
  951. }
  952. MAKE_MEM_UNDEFINED(&ph_list2, sizeof(ph_list2));
  953. memset(&ph_list2[0], 0, sizeof(ph_list2[0]));
  954. ph_list2[0].phcode = phonPAUSE_SHORT;
  955. n_ph_list2 = 1;
  956. tr->prev_last_stress = 0;
  957. tr->prepause_timeout = 0;
  958. tr->expect_verb = 0;
  959. tr->expect_noun = 0;
  960. tr->expect_past = 0;
  961. tr->expect_verb_s = 0;
  962. tr->phonemes_repeat_count = 0;
  963. tr->end_stressed_vowel = 0;
  964. tr->prev_dict_flags[0] = 0;
  965. tr->prev_dict_flags[1] = 0;
  966. word_count = 0;
  967. word_flags = 0;
  968. next_word_flags = 0;
  969. sbuf[0] = 0;
  970. sbuf[1] = ' ';
  971. sbuf[2] = ' ';
  972. ix = 3;
  973. prev_in = ' ';
  974. words[0].start = ix;
  975. words[0].flags = 0;
  976. for (j = 0; charix[j] <= 0; j++) ;
  977. words[0].sourceix = charix[j];
  978. k = 0;
  979. while (charix[j] != 0) {
  980. // count the number of characters (excluding multibyte continuation bytes)
  981. if (charix[j++] != -1)
  982. k++;
  983. }
  984. words[0].length = k;
  985. while (!finished && (ix < (int)sizeof(sbuf) - 1)) {
  986. prev_out2 = prev_out;
  987. utf8_in2(&prev_out, &sbuf[ix-1], 1);
  988. if (tr->langopts.tone_numbers && IsDigit09(prev_out) && IsAlpha(prev_out2)) {
  989. // tone numbers can be part of a word, consider them as alphabetic
  990. prev_out = 'a';
  991. }
  992. if (prev_in_save != 0) {
  993. prev_in = prev_in_save;
  994. prev_in_save = 0;
  995. } else if (source_index > 0)
  996. utf8_in2(&prev_in, &source[source_index-1], 1);
  997. prev_source_index = source_index;
  998. if (char_inserted) {
  999. c = char_inserted;
  1000. char_inserted = 0;
  1001. } else {
  1002. source_index += utf8_in(&cc, &source[source_index]);
  1003. c = cc;
  1004. }
  1005. if (c == 0) {
  1006. finished = true;
  1007. c = ' ';
  1008. next_in = ' ';
  1009. next_in_nbytes = 0;
  1010. }
  1011. else
  1012. next_in_nbytes = utf8_in(&next_in, &source[source_index]);
  1013. if (c == CTRL_EMBEDDED) {
  1014. // start of embedded command in the text
  1015. int srcix = source_index-1;
  1016. if (prev_in != ' ') {
  1017. c = ' ';
  1018. prev_in_save = c;
  1019. source_index--;
  1020. } else {
  1021. embedded_count += EmbeddedCommand(&source_index);
  1022. prev_in_save = prev_in;
  1023. // replace the embedded command by spaces
  1024. memset(&source[srcix], ' ', source_index-srcix);
  1025. source_index = srcix;
  1026. continue;
  1027. }
  1028. }
  1029. if ((option_sayas2 == SAYAS_KEY) && (c != ' ')) {
  1030. if ((prev_in == ' ') && (next_in == ' '))
  1031. option_sayas2 = SAYAS_SINGLE_CHARS; // single character, speak its name
  1032. c = towlower2(c, tr);
  1033. }
  1034. if (phoneme_mode) {
  1035. all_upper_case = FLAG_PHONEMES;
  1036. if ((c == ']') && (next_in == ']')) {
  1037. phoneme_mode = false;
  1038. source_index++;
  1039. c = ' ';
  1040. }
  1041. } else if ((option_sayas2 & 0xf0) == SAYAS_DIGITS) {
  1042. if (iswdigit(c)) {
  1043. count_sayas_digits++;
  1044. if (count_sayas_digits > (option_sayas2 & 0xf)) {
  1045. // break after the specified number of digits
  1046. c = ' ';
  1047. space_inserted = true;
  1048. count_sayas_digits = 0;
  1049. }
  1050. } else {
  1051. count_sayas_digits = 0;
  1052. if (iswdigit(prev_out)) {
  1053. c = ' ';
  1054. space_inserted = true;
  1055. }
  1056. }
  1057. } else if ((option_sayas2 & 0x10) == 0) {
  1058. // speak as words
  1059. if ((c == 0x92) || (c == 0xb4) || (c == 0x2019) || (c == 0x2032))
  1060. c = '\''; // 'microsoft' quote or sexed closing single quote, or prime - possibly used as apostrophe
  1061. if (((c == 0x2018) || (c == '?')) && IsAlpha(prev_out) && IsAlpha(next_in)) {
  1062. // ? between two letters may be a smart-quote replaced by ?
  1063. c = '\'';
  1064. }
  1065. if (c == CHAR_EMPHASIS) {
  1066. // this character is a marker that the previous word is the focus of the clause
  1067. c = ' ';
  1068. word_flags |= FLAG_FOCUS;
  1069. }
  1070. if (c == CHAR_COMMA_BREAK) {
  1071. c = ' ';
  1072. word_flags |= FLAG_COMMA_AFTER;
  1073. }
  1074. // language specific character translations
  1075. c = TranslateChar(tr, &source[source_index], prev_in, c, next_in, &char_inserted, &word_flags);
  1076. if (c == 8)
  1077. continue; // ignore this character
  1078. if (char_inserted)
  1079. next_in = char_inserted;
  1080. // allow certain punctuation within a word (usually only apostrophe)
  1081. if (!IsAlpha(c) && !IsSpace(c) && (wcschr(tr->punct_within_word, c) == 0)) {
  1082. if (IsAlpha(prev_out)) {
  1083. if (tr->langopts.tone_numbers && IsDigit09(c) && !IsDigit09(next_in)) {
  1084. // allow a tone number as part of the word
  1085. } else {
  1086. c = ' '; // ensure we have an end-of-word terminator
  1087. space_inserted = true;
  1088. }
  1089. }
  1090. }
  1091. if (iswdigit(prev_out)) {
  1092. if (!iswdigit(c) && (c != '.') && (c != ',') && (c != ' ')) {
  1093. c = ' '; // terminate digit string with a space
  1094. space_inserted = true;
  1095. }
  1096. } else { // Prev output is not digit
  1097. if (prev_in == ',') {
  1098. // Workaround for several consecutive commas —
  1099. // replace current character with space
  1100. if (c == ',')
  1101. c = ' ';
  1102. } else {
  1103. decimal_sep_count = false;
  1104. }
  1105. }
  1106. if (c == '[') {
  1107. if ((next_in == '\002') || ((next_in == '[') && option_phoneme_input)) {
  1108. // "[\002" is used internally to start phoneme mode
  1109. phoneme_mode = true;
  1110. source_index++;
  1111. continue;
  1112. }
  1113. }
  1114. if (IsAlpha(c)) {
  1115. alpha_count++;
  1116. if (!IsAlpha(prev_out) || (tr->langopts.ideographs && ((c > 0x3040) || (prev_out > 0x3040)))) {
  1117. if (wcschr(tr->punct_within_word, prev_out) == 0)
  1118. letter_count = 0; // don't reset count for an apostrophy within a word
  1119. if ((prev_out != ' ') && (wcschr(tr->punct_within_word, prev_out) == 0)) {
  1120. // start of word, insert space if not one there already
  1121. c = ' ';
  1122. space_inserted = true;
  1123. if (!IsBracket(prev_out)) // ?? perhaps only set FLAG_NOSPACE for . - / (hyphenated words, URLs, etc)
  1124. next_word_flags |= FLAG_NOSPACE;
  1125. } else {
  1126. if (iswupper(c))
  1127. word_flags |= FLAG_FIRST_UPPER;
  1128. if ((prev_out == ' ') && iswdigit(sbuf[ix-2]) && !iswdigit(prev_in)) {
  1129. // word, following a number, but with a space between
  1130. // Add an extra space, to distinguish "2 a" from "2a"
  1131. sbuf[ix++] = ' ';
  1132. words[word_count].start++;
  1133. }
  1134. }
  1135. }
  1136. if (c != ' ') {
  1137. letter_count++;
  1138. if (tr->letter_bits_offset > 0) {
  1139. if (((c < 0x250) && (prev_out >= tr->letter_bits_offset)) ||
  1140. ((c >= tr->letter_bits_offset) && (letter_count > 1) && (prev_out < 0x250))) {
  1141. // Don't mix native and Latin characters in the same word
  1142. // Break into separate words
  1143. if (IsAlpha(prev_out)) {
  1144. c = ' ';
  1145. space_inserted = true;
  1146. word_flags |= FLAG_HYPHEN_AFTER;
  1147. next_word_flags |= FLAG_HYPHEN;
  1148. }
  1149. }
  1150. }
  1151. }
  1152. if (iswupper(c)) {
  1153. c = towlower2(c, tr);
  1154. if (tr->langopts.param[LOPT_CAPS_IN_WORD]) {
  1155. if (syllable_marked == false) {
  1156. char_inserted = c;
  1157. c = 0x2c8; // stress marker
  1158. syllable_marked = true;
  1159. }
  1160. } else {
  1161. if (iswlower(prev_in)) {
  1162. // lower case followed by upper case, possibly CamelCase
  1163. if (UpperCaseInWord(tr, &sbuf[ix], c) == 0) { // start a new word
  1164. c = ' ';
  1165. space_inserted = true;
  1166. prev_in_save = c;
  1167. }
  1168. } else if ((c != ' ') && iswupper(prev_in) && iswlower(next_in)) {
  1169. int next2_in;
  1170. utf8_in(&next2_in, &source[source_index + next_in_nbytes]);
  1171. if ((tr->translator_name == L('n', 'l')) && (letter_count == 2) && (c == 'j') && (prev_in == 'I')) {
  1172. // Dutch words may capitalise initial IJ, don't split
  1173. } else if (IsAlpha(next2_in)) {
  1174. // changing from upper to lower case, start new word at the last uppercase, if 3 or more letters
  1175. c = ' ';
  1176. space_inserted = true;
  1177. prev_in_save = c;
  1178. next_word_flags |= FLAG_NOSPACE;
  1179. }
  1180. }
  1181. }
  1182. } else {
  1183. if ((all_upper_case) && (letter_count > 2)) {
  1184. // Flag as plural only English
  1185. if (tr->translator_name == L('e', 'n') && (c == 's') && (next_in == ' ')) {
  1186. c = ' ';
  1187. all_upper_case |= FLAG_HAS_PLURAL;
  1188. if (sbuf[ix-1] == '\'')
  1189. sbuf[ix-1] = ' ';
  1190. } else
  1191. all_upper_case = 0; // current word contains lower case letters, not "'s"
  1192. } else
  1193. all_upper_case = 0;
  1194. }
  1195. } else if (c == '-') {
  1196. if (!IsSpace(prev_in) && IsAlpha(next_in)) {
  1197. if (prev_out != ' ') {
  1198. // previous 'word' not yet ended (not alpha or numeric), start new word now.
  1199. c = ' ';
  1200. space_inserted = true;
  1201. } else {
  1202. // '-' between two letters is a hyphen, treat as a space
  1203. word_flags |= FLAG_HYPHEN;
  1204. if (word_count > 0)
  1205. words[word_count-1].flags |= FLAG_HYPHEN_AFTER;
  1206. c = ' ';
  1207. }
  1208. } else if ((prev_in == ' ') && (next_in == ' ')) {
  1209. // ' - ' dash between two spaces, treat as pause
  1210. c = ' ';
  1211. pre_pause_add = 4;
  1212. } else if (next_in == '-') {
  1213. // double hyphen, treat as pause
  1214. source_index++;
  1215. c = ' ';
  1216. pre_pause_add = 4;
  1217. } else if ((prev_out == ' ') && IsAlpha(prev_out2) && !IsAlpha(prev_in)) {
  1218. // insert extra space between a word + space + hyphen, to distinguish 'a -2' from 'a-2'
  1219. sbuf[ix++] = ' ';
  1220. words[word_count].start++;
  1221. }
  1222. } else if (c == '.') {
  1223. if (prev_out == '.') {
  1224. // multiple dots, separate by spaces. Note >3 dots has been replaced by elipsis
  1225. c = ' ';
  1226. space_inserted = true;
  1227. } else if ((word_count > 0) && !(words[word_count-1].flags & FLAG_NOSPACE) && IsAlpha(prev_in)) {
  1228. // dot after a word, with space following, probably an abbreviation
  1229. words[word_count-1].flags |= FLAG_HAS_DOT;
  1230. if (IsSpace(next_in) || (next_in == '-'))
  1231. c = ' '; // remove the dot if it's followed by a space or hyphen, so that it's not pronounced
  1232. }
  1233. } else if (c == '\'') {
  1234. if (((prev_in == '.' && next_in == 's') || iswalnum(prev_in)) && IsAlpha(next_in)) {
  1235. // between two letters, or in an abbreviation (eg. u.s.a.'s). Consider the apostrophe as part of the word
  1236. single_quoted = false;
  1237. } else if ((tr->langopts.param[LOPT_APOSTROPHE] & 1) && IsAlpha(next_in))
  1238. single_quoted = false; // apostrophe at start of word is part of the word
  1239. else if ((tr->langopts.param[LOPT_APOSTROPHE] & 2) && IsAlpha(prev_in))
  1240. single_quoted = false; // apostrophe at end of word is part of the word
  1241. else if ((wcschr(tr->char_plus_apostrophe, prev_in) != 0) && (prev_out2 == ' ')) {
  1242. // consider single character plus apostrophe as a word
  1243. single_quoted = false;
  1244. if (next_in == ' ')
  1245. source_index++; // skip following space
  1246. } else {
  1247. if ((prev_out == 's') && (single_quoted == false)) {
  1248. // looks like apostrophe after an 's'
  1249. c = ' ';
  1250. } else {
  1251. if (IsSpace(prev_out))
  1252. single_quoted = true;
  1253. else
  1254. single_quoted = false;
  1255. pre_pause_add = 4; // single quote
  1256. c = ' ';
  1257. }
  1258. }
  1259. } else if (lookupwchar(breaks, c) != 0)
  1260. c = ' '; // various characters to treat as space
  1261. else if (iswdigit(c)) {
  1262. if (tr->langopts.tone_numbers && IsAlpha(prev_out) && !IsDigit(next_in)) {
  1263. } else if ((prev_out != ' ') && !iswdigit(prev_out)) {
  1264. if ((prev_out != tr->langopts.decimal_sep) || ((decimal_sep_count == true) && (tr->langopts.decimal_sep == ','))) {
  1265. c = ' ';
  1266. space_inserted = true;
  1267. } else
  1268. decimal_sep_count = true;
  1269. } else if ((prev_out == ' ') && IsAlpha(prev_out2) && !IsAlpha(prev_in)) {
  1270. // insert extra space between a word and a number, to distinguish 'a 2' from 'a2'
  1271. sbuf[ix++] = ' ';
  1272. words[word_count].start++;
  1273. }
  1274. }
  1275. }
  1276. if (IsSpace(c)) {
  1277. if (prev_out == ' ') {
  1278. word_flags |= FLAG_MULTIPLE_SPACES;
  1279. continue; // multiple spaces
  1280. }
  1281. if ((cc == 0x09) || (cc == 0x0a))
  1282. next_word_flags |= FLAG_MULTIPLE_SPACES; // tab or newline, not a simple space
  1283. if (space_inserted) {
  1284. // count the number of characters since the start of the word
  1285. j = 0;
  1286. k = source_index - 1;
  1287. while ((k >= source_index_word) && (charix[k] != 0)) {
  1288. if (charix[k] > 0) // don't count initial bytes of multi-byte character
  1289. j++;
  1290. k--;
  1291. }
  1292. words[word_count].length = j;
  1293. }
  1294. source_index_word = source_index;
  1295. // end of 'word'
  1296. sbuf[ix++] = ' ';
  1297. if ((word_count < N_CLAUSE_WORDS-1) && (ix > words[word_count].start)) {
  1298. if (embedded_count > 0) {
  1299. // there are embedded commands before this word
  1300. embedded_list[embedded_ix-1] |= 0x80; // terminate list of commands for this word
  1301. words[word_count].flags |= FLAG_EMBEDDED;
  1302. embedded_count = 0;
  1303. }
  1304. if (alpha_count == 0) {
  1305. all_upper_case &= ~FLAG_ALL_UPPER;
  1306. }
  1307. words[word_count].pre_pause = pre_pause;
  1308. words[word_count].flags |= (all_upper_case | word_flags | word_emphasis);
  1309. if (pre_pause > 0) {
  1310. // insert an extra space before the word, to prevent influence from previous word across the pause
  1311. for (j = ix; j > words[word_count].start; j--)
  1312. sbuf[j] = sbuf[j-1];
  1313. sbuf[j] = ' ';
  1314. words[word_count].start++;
  1315. ix++;
  1316. }
  1317. word_count++;
  1318. words[word_count].start = ix;
  1319. words[word_count].flags = 0;
  1320. for (j = source_index; j < charix_top && charix[j] <= 0; j++) // skip blanks
  1321. ;
  1322. words[word_count].sourceix = charix[j];
  1323. k = 0;
  1324. while (charix[j] != 0) {
  1325. // count the number of characters (excluding multibyte continuation bytes)
  1326. if (charix[j++] != -1)
  1327. k++;
  1328. }
  1329. words[word_count].length = k;
  1330. word_flags = next_word_flags;
  1331. next_word_flags = 0;
  1332. pre_pause = 0;
  1333. all_upper_case = FLAG_ALL_UPPER;
  1334. alpha_count = 0;
  1335. syllable_marked = false;
  1336. }
  1337. if (space_inserted) {
  1338. source_index = prev_source_index; // rewind to the previous character
  1339. char_inserted = 0;
  1340. space_inserted = false;
  1341. }
  1342. } else {
  1343. if ((ix < (N_TR_SOURCE - 4)))
  1344. ix += utf8_out(c, &sbuf[ix]);
  1345. }
  1346. if (pre_pause_add > pre_pause)
  1347. pre_pause = pre_pause_add;
  1348. pre_pause_add = 0;
  1349. }
  1350. if ((word_count == 0) && (embedded_count > 0)) {
  1351. // add a null 'word' to carry the embedded command flag
  1352. embedded_list[embedded_ix-1] |= 0x80;
  1353. words[word_count].flags |= FLAG_EMBEDDED;
  1354. word_count = 1;
  1355. }
  1356. tr->clause_end = &sbuf[ix-1];
  1357. sbuf[ix] = 0;
  1358. words[0].pre_pause = 0; // don't add extra pause at beginning of clause
  1359. words[word_count].pre_pause = 8;
  1360. if (word_count > 0) {
  1361. ix = word_count-1;
  1362. while ((ix > 0) && (IsBracket(sbuf[words[ix].start])))
  1363. ix--; // the last word is a bracket, mark the previous word as last
  1364. words[ix].flags |= FLAG_LAST_WORD;
  1365. // FLAG_NOSPACE check to avoid recognizing .mr -mr
  1366. if ((terminator & CLAUSE_DOT_AFTER_LAST_WORD) && !(words[word_count-1].flags & FLAG_NOSPACE))
  1367. words[word_count-1].flags |= FLAG_HAS_DOT;
  1368. }
  1369. words[0].flags |= FLAG_FIRST_WORD;
  1370. // Each TranslateWord2 may require up to 7 phonemes
  1371. // and after this loop we require 2 phonemes
  1372. for (ix = 0; ix < word_count && (n_ph_list2 < N_PHONEME_LIST-7-2); ix++) {
  1373. int nx;
  1374. int c_temp;
  1375. char *pn;
  1376. char *pw;
  1377. int nw;
  1378. char number_buf[150];
  1379. WORD_TAB num_wtab[50]; // copy of 'words', when splitting numbers into parts
  1380. // start speaking at a specified word position in the text?
  1381. count_words++;
  1382. if (skip_words > 0) {
  1383. skip_words--;
  1384. if (skip_words == 0)
  1385. skipping_text = false;
  1386. }
  1387. if (skipping_text)
  1388. continue;
  1389. current_alphabet = NULL;
  1390. // digits should have been converted to Latin alphabet ('0' to '9')
  1391. word = pw = &sbuf[words[ix].start];
  1392. if (iswdigit(word[0]) && (tr->langopts.break_numbers != BREAK_THOUSANDS)) {
  1393. // Languages with 100000 numbers. Remove thousands separators so that we can insert them again later
  1394. pn = number_buf;
  1395. while (pn < &number_buf[sizeof(number_buf)-20]) {
  1396. if (iswdigit(*pw))
  1397. *pn++ = *pw++;
  1398. else if ((*pw == tr->langopts.thousands_sep) && (pw[1] == ' ')
  1399. && iswdigit(pw[2]) && (pw[3] != ' ') && (pw[4] != ' ')) { // don't allow only 1 or 2 digits in the final part
  1400. pw += 2;
  1401. ix++; // skip "word"
  1402. } else {
  1403. nx = pw - word;
  1404. memset(word, ' ', nx);
  1405. nx = pn - number_buf;
  1406. memcpy(word, number_buf, nx);
  1407. break;
  1408. }
  1409. }
  1410. pw = word;
  1411. }
  1412. for (n_digits = 0; iswdigit(word[n_digits]); n_digits++) // count consecutive digits
  1413. ;
  1414. if (n_digits > 4 && n_digits <= 32) {
  1415. // word is entirely digits, insert commas and break into 3 digit "words"
  1416. number_buf[0] = ' ';
  1417. number_buf[1] = ' ';
  1418. number_buf[2] = ' ';
  1419. pn = &number_buf[3];
  1420. nx = n_digits;
  1421. nw = 0;
  1422. if ((n_digits > tr->langopts.max_digits) || (word[0] == '0'))
  1423. words[ix].flags |= FLAG_INDIVIDUAL_DIGITS;
  1424. while (pn < &number_buf[sizeof(number_buf)-20]) {
  1425. if (!IsDigit09(c = *pw++) && (c != tr->langopts.decimal_sep))
  1426. break;
  1427. *pn++ = c;
  1428. nx--;
  1429. if ((nx > 0) && (tr->langopts.break_numbers & (1U << nx))) {
  1430. memcpy(&num_wtab[nw++], &words[ix], sizeof(WORD_TAB)); // copy the 'words' entry for each word of numbers
  1431. if (tr->langopts.thousands_sep != ' ')
  1432. *pn++ = tr->langopts.thousands_sep;
  1433. *pn++ = ' ';
  1434. if ((words[ix].flags & FLAG_INDIVIDUAL_DIGITS) == 0) {
  1435. if (tr->langopts.break_numbers & (1 << (nx-1))) {
  1436. // the next group only has 1 digits, make it three
  1437. *pn++ = '0';
  1438. *pn++ = '0';
  1439. }
  1440. if (tr->langopts.break_numbers & (1 << (nx-2))) {
  1441. // the next group only has 2 digits (eg. Indian languages), make it three
  1442. *pn++ = '0';
  1443. }
  1444. }
  1445. }
  1446. }
  1447. pw--;
  1448. memcpy(&num_wtab[nw], &words[ix], sizeof(WORD_TAB)*2); // the original number word, and the word after it
  1449. for (j = 1; j <= nw; j++)
  1450. num_wtab[j].flags &= ~(FLAG_MULTIPLE_SPACES | FLAG_EMBEDDED); // don't use these flags for subsequent parts when splitting a number
  1451. // include the next few characters, in case there are an ordinal indicator or other suffix
  1452. memcpy(pn, pw, 16);
  1453. pn[16] = 0;
  1454. nw = 0;
  1455. for (pw = &number_buf[3]; pw < pn;) {
  1456. // keep wflags for each part, for FLAG_HYPHEN_AFTER
  1457. dict_flags = TranslateWord2(tr, pw, &num_wtab[nw++], words[ix].pre_pause);
  1458. while (*pw++ != ' ')
  1459. ;
  1460. words[ix].pre_pause = 0;
  1461. }
  1462. } else {
  1463. pre_pause = 0;
  1464. dict_flags = TranslateWord2(tr, word, &words[ix], words[ix].pre_pause);
  1465. if (pre_pause > words[ix+1].pre_pause) {
  1466. words[ix+1].pre_pause = pre_pause;
  1467. pre_pause = 0;
  1468. }
  1469. if (dict_flags & FLAG_SPELLWORD) {
  1470. // redo the word, speaking single letters
  1471. for (pw = word; *pw != ' ';) {
  1472. memset(number_buf, ' ', 9);
  1473. nx = utf8_in(&c_temp, pw);
  1474. memcpy(&number_buf[2], pw, nx);
  1475. TranslateWord2(tr, &number_buf[2], &words[ix], 0);
  1476. pw += nx;
  1477. }
  1478. }
  1479. if ((dict_flags & (FLAG_ALLOW_DOT | FLAG_NEEDS_DOT)) && (ix == word_count - 1 - dictionary_skipwords) && (terminator & CLAUSE_DOT_AFTER_LAST_WORD)) {
  1480. // probably an abbreviation such as Mr. or B. rather than end of sentence
  1481. clause_pause = 10;
  1482. if (tone_out != NULL)
  1483. *tone_out = 4;
  1484. }
  1485. }
  1486. if (dict_flags & FLAG_SKIPWORDS) {
  1487. // dictionary indicates skip next word(s)
  1488. while (dictionary_skipwords > 0) {
  1489. words[ix+dictionary_skipwords].flags |= FLAG_DELETE_WORD;
  1490. dictionary_skipwords--;
  1491. }
  1492. }
  1493. }
  1494. if (embedded_read < embedded_ix) {
  1495. // any embedded commands not yet processed?
  1496. Word_EmbeddedCmd();
  1497. }
  1498. for (ix = 0; ix < 2; ix++) {
  1499. // terminate the clause with 2 PAUSE phonemes
  1500. PHONEME_LIST2 *p2;
  1501. p2 = &ph_list2[n_ph_list2 + ix];
  1502. p2->phcode = phonPAUSE;
  1503. p2->stresslevel = 0;
  1504. p2->sourceix = source_index;
  1505. p2->synthflags = 0;
  1506. }
  1507. n_ph_list2 += 2;
  1508. if (count_words == 0)
  1509. clause_pause = 0;
  1510. if (Eof() && ((word_count == 0) || (option_endpause == 0)))
  1511. clause_pause = 10;
  1512. MakePhonemeList(tr, clause_pause, new_sentence2);
  1513. phoneme_list[N_PHONEME_LIST].ph = NULL; // recognize end of phoneme_list array, in Generate()
  1514. phoneme_list[N_PHONEME_LIST].sourceix = 1;
  1515. if (embedded_count) { // ???? is this needed
  1516. phoneme_list[n_phoneme_list-2].synthflags = SFLAG_EMBEDDED;
  1517. embedded_list[embedded_ix-1] |= 0x80;
  1518. embedded_list[embedded_ix] = 0x80;
  1519. }
  1520. new_sentence = false;
  1521. if (terminator & CLAUSE_TYPE_SENTENCE)
  1522. new_sentence = true; // next clause is a new sentence
  1523. if (voice_change != NULL) {
  1524. // return new voice name if an embedded voice change command terminated the clause
  1525. if (terminator & CLAUSE_TYPE_VOICE_CHANGE)
  1526. *voice_change = voice_change_name;
  1527. else
  1528. *voice_change = NULL;
  1529. }
  1530. }
  1531. void InitText(int control)
  1532. {
  1533. count_sentences = 0;
  1534. count_words = 0;
  1535. end_character_position = 0;
  1536. skip_sentences = 0;
  1537. skip_marker[0] = 0;
  1538. skip_words = 0;
  1539. skip_characters = 0;
  1540. skipping_text = false;
  1541. new_sentence = true;
  1542. option_sayas = 0;
  1543. option_sayas2 = 0;
  1544. option_emphasis = 0;
  1545. word_emphasis = 0;
  1546. embedded_flag = 0;
  1547. InitText2();
  1548. if ((control & espeakKEEP_NAMEDATA) == 0)
  1549. InitNamedata();
  1550. }