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.cpp 63KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345
  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. #define WORD_STRESS_CHAR '*'
  33. Translator *translator = NULL; // the main translator
  34. static Translator *translator2 = NULL; // secondary translator for certain words
  35. static char translator2_language[20] = {0};
  36. FILE *f_trans = NULL; // phoneme output text
  37. int option_tone1 = 0;
  38. int option_tone2 = 0;
  39. int option_phonemes = 0;
  40. int option_phoneme_events = 0;
  41. int option_quiet = 0;
  42. int option_endpause = 0; // suppress pause after end of text
  43. int option_capitals = 0;
  44. int option_punctuation = 0;
  45. int option_sayas = 0;
  46. int option_sayas2 = 0; // used in translate_clause()
  47. int option_emphasis = 0;
  48. int option_ssml = 0;
  49. int option_phoneme_input = 1; // allow [[phonemes]] in input
  50. int option_phoneme_variants = 0; // 0= don't display phoneme variant mnemonics
  51. int count_sayas_digits;
  52. int skip_sentences;
  53. int skip_words;
  54. int skip_characters;
  55. char skip_marker[N_MARKER_LENGTH];
  56. int skipping_text; // waiting until word count, sentence count, or named marker is reached
  57. int end_character_position;
  58. int count_sentences;
  59. int count_words;
  60. int clause_start_char;
  61. int clause_start_word;
  62. int new_sentence;
  63. int prev_clause_pause=0;
  64. int max_clause_pause = 0;
  65. wchar_t option_punctlist[N_PUNCTLIST]={0};
  66. char ctrl_embedded = '\001'; // to allow an alternative CTRL for embedded commands
  67. int option_multibyte=espeakCHARS_AUTO; // 0=auto, 1=utf8, 2=8bit, 3=wchar
  68. // these are overridden by defaults set in the "speak" file
  69. int option_linelength = 0;
  70. #define N_EMBEDDED_LIST 250
  71. static int embedded_ix;
  72. static int embedded_read;
  73. unsigned int embedded_list[N_EMBEDDED_LIST];
  74. // the source text of a single clause
  75. #define N_TR_SOURCE 350
  76. static char source[N_TR_SOURCE+40]; // extra space for embedded command & voice change info at end
  77. int n_replace_phonemes;
  78. REPLACE_PHONEMES replace_phonemes[N_REPLACE_PHONEMES];
  79. // brackets, also 0x2014 to 0x021f which don't need to be in this list
  80. static const unsigned short brackets[] = {
  81. '(',')','[',']','{','}','<','>','"','\'','`',
  82. 0xab,0xbb, // double angle brackets
  83. 0x300a,0x300b, // double angle brackets (ideograph)
  84. 0};
  85. // other characters which break a word, but don't produce a pause
  86. static const unsigned short breaks[] = {'_', 0};
  87. // Translate character codes 0xA0 to 0xFF into their unicode values
  88. // ISO_8859_1 is set as default
  89. static const unsigned short ISO_8859_1[0x60] = {
  90. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0
  91. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8
  92. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0
  93. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8
  94. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  95. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  96. 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  97. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, // d8
  98. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  99. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  100. 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  101. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff, // f8
  102. };
  103. static const unsigned short ISO_8859_2[0x60] = {
  104. 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, // a0
  105. 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, // a8
  106. 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, // b0
  107. 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, // b8
  108. 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, // c0
  109. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, // c8
  110. 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, // d0
  111. 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, // d8
  112. 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, // e0
  113. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, // e8
  114. 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, // f0
  115. 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, // f8
  116. };
  117. static const unsigned short ISO_8859_3[0x60] = {
  118. 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, // a0
  119. 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b, // a8
  120. 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, // b0
  121. 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0x0000, 0x017c, // b8
  122. 0x00c0, 0x00c1, 0x00c2, 0x0000, 0x00c4, 0x010a, 0x0108, 0x00c7, // c0
  123. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  124. 0x0000, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, // d0
  125. 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df, // d8
  126. 0x00e0, 0x00e1, 0x00e2, 0x0000, 0x00e4, 0x010b, 0x0109, 0x00e7, // e0
  127. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  128. 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, // f0
  129. 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9, // f8
  130. };
  131. static const unsigned short ISO_8859_4[0x60] = {
  132. 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, // a0
  133. 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, // a8
  134. 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, // b0
  135. 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, // b8
  136. 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, // c0
  137. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, // c8
  138. 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  139. 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, // d8
  140. 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, // e0
  141. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, // e8
  142. 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  143. 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9, // f8
  144. };
  145. static const unsigned short ISO_8859_5[0x60] = {
  146. 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, // a0 Cyrillic
  147. 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f, // a8
  148. 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, // b0
  149. 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, // b8
  150. 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, // c0
  151. 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, // c8
  152. 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, // d0
  153. 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, // d8
  154. 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, // e0
  155. 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, // e8
  156. 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, // f0
  157. 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f, // f8
  158. };
  159. static const unsigned short ISO_8859_7[0x60] = {
  160. 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, // a0 Greek
  161. 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015, // a8
  162. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7, // b0
  163. 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, // b8
  164. 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, // c0
  165. 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, // c8
  166. 0x03a0, 0x03a1, 0x0000, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, // d0
  167. 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, // d8
  168. 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, // e0
  169. 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, // e8
  170. 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, // f0
  171. 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000, // f8
  172. };
  173. static const unsigned short ISO_8859_9[0x60] = {
  174. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0
  175. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8
  176. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0
  177. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8
  178. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  179. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  180. 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  181. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df, // d8
  182. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  183. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  184. 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  185. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff, // f8
  186. };
  187. static const unsigned short ISO_8859_14[0x60] = {
  188. 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, // a0 Welsh
  189. 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178, // a8
  190. 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56, // b0
  191. 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, // b8
  192. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  193. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  194. 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a, // d0
  195. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df, // d8
  196. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  197. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  198. 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, // f0
  199. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff, // f8
  200. };
  201. static const unsigned short KOI8_R[0x60] = {
  202. 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, // a0 Russian
  203. 0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x255c, 0x255d, 0x255e, // a8
  204. 0x255f, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, // b0
  205. 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b, 0x256c, 0x00a9, // b8
  206. 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, // c0
  207. 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, // c8
  208. 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, // d0
  209. 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, // d8
  210. 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, // e0
  211. 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, // e8
  212. 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, // f0
  213. 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a, // f8
  214. };
  215. static const unsigned short ISCII[0x60] = {
  216. 0x0020, 0x0901, 0x0902, 0x0903, 0x0905, 0x0906, 0x0907, 0x0908, // a0
  217. 0x0909, 0x090a, 0x090b, 0x090e, 0x090f, 0x0910, 0x090d, 0x0912, // a8
  218. 0x0913, 0x0914, 0x0911, 0x0915, 0x0916, 0x0917, 0x0918, 0x0919, // b0
  219. 0x091a, 0x091b, 0x091c, 0x091d, 0x091e, 0x091f, 0x0920, 0x0921, // b8
  220. 0x0922, 0x0923, 0x0924, 0x0925, 0x0926, 0x0927, 0x0928, 0x0929, // c0
  221. 0x092a, 0x092b, 0x092c, 0x092d, 0x092e, 0x092f, 0x095f, 0x0930, // c8
  222. 0x0931, 0x0932, 0x0933, 0x0934, 0x0935, 0x0936, 0x0937, 0x0938, // d0
  223. 0x0939, 0x0020, 0x093e, 0x093f, 0x0940, 0x0941, 0x0942, 0x0943, // d8
  224. 0x0946, 0x0947, 0x0948, 0x0945, 0x094a, 0x094b, 0x094c, 0x0949, // e0
  225. 0x094d, 0x093c, 0x0964, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, // e8
  226. 0x0020, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, // f0
  227. 0x0037, 0x0038, 0x0039, 0x20, 0x20, 0x20, 0x20, 0x20, // f8
  228. };
  229. const unsigned short *charsets[N_CHARSETS] = {
  230. ISO_8859_1,
  231. ISO_8859_1,
  232. ISO_8859_2,
  233. ISO_8859_3,
  234. ISO_8859_4,
  235. ISO_8859_5,
  236. ISO_8859_1,
  237. ISO_8859_7,
  238. ISO_8859_1,
  239. ISO_8859_9,
  240. ISO_8859_1,
  241. ISO_8859_1,
  242. ISO_8859_1,
  243. ISO_8859_1,
  244. ISO_8859_14,
  245. ISO_8859_1,
  246. ISO_8859_1,
  247. ISO_8859_1,
  248. KOI8_R, // 18
  249. ISCII };
  250. // Tables of the relative lengths of vowels, depending on the
  251. // type of the two phonemes that follow
  252. // indexes are the "length_mod" value for the following phonemes
  253. // use this table if vowel is not the last in the word
  254. static unsigned char length_mods_en[100] = {
  255. /* a , t s n d z r N <- next */
  256. 100,120,100,105,100,110,110,100, 95, 100, /* a <- next2 */
  257. 105,120,105,110,125,130,135,115,125, 100, /* , */
  258. 105,120, 75,100, 75,105,120, 85, 75, 100, /* t */
  259. 105,120, 85,105, 95,115,120,100, 95, 100, /* s */
  260. 110,120, 95,105,100,115,120,100,100, 100, /* n */
  261. 105,120,100,105, 95,115,120,110, 95, 100, /* d */
  262. 105,120,100,105,105,122,125,110,105, 100, /* z */
  263. 105,120,100,105,105,122,125,110,105, 100, /* r */
  264. 105,120, 95,105,100,115,120,110,100, 100, /* N */
  265. 100,120,100,100,100,100,100,100,100, 100 }; // SPARE
  266. // as above, but for the last syllable in a word
  267. static unsigned char length_mods_en0[100] = {
  268. /* a , t s n d z r N <- next */
  269. 100,150,100,105,110,115,110,110,110, 100, /* a <- next2 */
  270. 105,150,105,110,125,135,140,115,135, 100, /* , */
  271. 105,150, 90,105, 90,122,135,100, 90, 100, /* t */
  272. 105,150,100,105,100,122,135,100,100, 100, /* s */
  273. 105,150,100,105,105,115,135,110,105, 100, /* n */
  274. 105,150,100,105,105,122,130,120,125, 100, /* d */
  275. 105,150,100,105,110,122,125,115,110, 100, /* z */
  276. 105,150,100,105,105,122,135,120,105, 100, /* r */
  277. 105,150,100,105,105,115,135,110,105, 100, /* N */
  278. 100,100,100,100,100,100,100,100,100, 100 }; // SPARE
  279. static unsigned char length_mods_equal[100] = {
  280. /* a , t s n d z r N <- next */
  281. 110,110,110,110,110,110,110,110,110, 110, /* a <- next2 */
  282. 110,110,110,110,110,110,110,110,110, 110, /* , */
  283. 110,110,110,110,110,110,110,110,110, 110, /* t */
  284. 110,110,110,110,110,110,110,110,110, 110, /* s */
  285. 110,110,110,110,110,110,110,110,110, 110, /* n */
  286. 110,110,110,110,110,110,110,110,110, 110, /* d */
  287. 110,110,110,110,110,110,110,110,110, 110, /* z */
  288. 110,110,110,110,110,110,110,110,110, 110, /* r */
  289. 110,110,110,110,110,110,110,110,110, 110, /* N */
  290. 110,110,110,110,110,110,110,110,110, 110 }; // SPARE
  291. unsigned char *length_mod_tabs[6] = {
  292. length_mods_en,
  293. length_mods_en, // 1
  294. length_mods_en0, // 2
  295. length_mods_equal, // 3
  296. length_mods_equal, // 4
  297. length_mods_equal // 5
  298. };
  299. /* index by 0=. 1=, 2=?, 3=! 4=none */
  300. static unsigned char punctuation_to_tone[4][5] = {
  301. {0,1,1,2,0},
  302. {3,4,4,5,3},
  303. {6,7,7,8,6},
  304. {9,10,10,11,9} };
  305. void SetLengthMods(Translator *tr, int value)
  306. {//==========================================
  307. int value2;
  308. tr->langopts.length_mods0 = tr->langopts.length_mods = length_mod_tabs[value % 100];
  309. if((value2 = value / 100) != 0)
  310. {
  311. tr->langopts.length_mods0 = length_mod_tabs[value2];
  312. }
  313. }
  314. int IsAlpha(unsigned int c)
  315. {//========================
  316. // Replacement for iswalph() which also checks for some in-word symbols
  317. if(iswalpha(c))
  318. return(1);
  319. if((c >= 0x901) && (c <= 0x957))
  320. return(1); // Devanagari vowel signs and other signs
  321. return(0);
  322. }
  323. int IsDigit(unsigned int c)
  324. {//========================
  325. if(iswdigit(c))
  326. return(1);
  327. if((c >= 0x966) && (c <= 0x96f))
  328. return(1);
  329. return(0);
  330. }
  331. Translator::Translator()
  332. {//=====================
  333. int ix;
  334. static int stress_amps2[] = {16,16, 20,20, 20,24, 24,21 };
  335. static int stress_lengths2[8] = {182,140, 220,220, 220,240, 260,280};
  336. static const wchar_t empty_wstring[1] = {0};
  337. charset_a0 = charsets[1]; // ISO-8859-1, this is for when the input is not utf8
  338. dictionary_name[0] = 0;
  339. dict_condition=0;
  340. data_dictrules = NULL; // language_1 translation rules file
  341. data_dictlist = NULL; // language_2 dictionary lookup file
  342. transpose_offset = 0;
  343. // only need lower case
  344. letter_bits_offset = 0;
  345. memset(letter_bits,0,sizeof(letter_bits));
  346. memset(letter_groups,0,sizeof(letter_groups));
  347. // 0-5 sets of characters matched by A B C E F G in pronunciation rules
  348. // these may be set differently for different languages
  349. SetLetterBits(this,0,"aeiou"); // A vowels, except y
  350. SetLetterBits(this,1,"bcdfgjklmnpqstvxz"); // B hard consonants, excluding h,r,w
  351. SetLetterBits(this,2,"bcdfghjklmnpqrstvwxz"); // C all consonants
  352. SetLetterBits(this,3,"hlmnr"); // H 'soft' consonants
  353. SetLetterBits(this,4,"cfhkpqstx"); // F voiceless consonants
  354. SetLetterBits(this,5,"bdgjlmnrvwyz"); // G voiced
  355. SetLetterBits(this,6,"eiy"); // Letter group Y, front vowels
  356. SetLetterBits(this,7,"aeiouy"); // vowels, including y
  357. char_plus_apostrophe = empty_wstring;
  358. for(ix=0; ix<8; ix++)
  359. {
  360. stress_amps[ix] = stress_amps2[ix];
  361. stress_amps_r[ix] = stress_amps2[ix] - 1;
  362. stress_lengths[ix] = stress_lengths2[ix];
  363. }
  364. memset(&langopts,0,sizeof(langopts));
  365. langopts.stress_rule = 2;
  366. langopts.unstressed_wd1 = 1;
  367. langopts.unstressed_wd2 = 3;
  368. langopts.param[LOPT_SONORANT_MIN] = 95;
  369. langopts.param[LOPT_MAXAMP_EOC] = 19;
  370. langopts.param[LOPT_UNPRONOUNCABLE] = 's'; // don't count this character at start of word
  371. langopts.max_initial_consonants = 3;
  372. langopts.replace_chars = NULL;
  373. langopts.length_mods = length_mods_en;
  374. langopts.length_mods0 = length_mods_en0;
  375. langopts.long_stop = 100;
  376. langopts.max_roman = 49;
  377. langopts.thousands_sep = ',';
  378. langopts.decimal_sep = '.';
  379. memcpy(punct_to_tone,punctuation_to_tone,sizeof(punct_to_tone));
  380. punct_to_tone[0][3] = 0; // exclamation, use period until we can improve the exclamation intonation
  381. }
  382. Translator::~Translator(void)
  383. {//==========================
  384. if(data_dictlist != NULL)
  385. Free(data_dictlist);
  386. }
  387. int lookupwchar(const unsigned short *list,int c)
  388. {//==============================================
  389. // Is the character c in the list ?
  390. int ix;
  391. for(ix=0; list[ix] != 0; ix++)
  392. {
  393. if(list[ix] == c)
  394. return(ix+1);
  395. }
  396. return(0);
  397. }
  398. int IsBracket(int c)
  399. {//=================
  400. if((c >= 0x2014) && (c <= 0x201f))
  401. return(1);
  402. return(lookupwchar(brackets,c));
  403. }
  404. int utf8_out(unsigned int c, char *buf)
  405. {//====================================
  406. // write a unicode character into a buffer as utf8
  407. // returns the number of bytes written
  408. int n_bytes;
  409. int j;
  410. int shift;
  411. static char unsigned code[4] = {0,0xc0,0xe0,0xf0};
  412. if(c < 0x80)
  413. {
  414. buf[0] = c;
  415. return(1);
  416. }
  417. if(c >= 0x110000)
  418. {
  419. buf[0] = ' '; // out of range character code
  420. return(1);
  421. }
  422. if(c < 0x0800)
  423. n_bytes = 1;
  424. else
  425. if(c < 0x10000)
  426. n_bytes = 2;
  427. else
  428. n_bytes = 3;
  429. shift = 6*n_bytes;
  430. buf[0] = code[n_bytes] | (c >> shift);
  431. for(j=0; j<n_bytes; j++)
  432. {
  433. shift -= 6;
  434. buf[j+1] = 0x80 + ((c >> shift) & 0x3f);
  435. }
  436. return(n_bytes+1);
  437. } // end of utf8_out
  438. int utf8_in(int *c, const char *buf, int backwards)
  439. {//================================================
  440. int c1;
  441. int n_bytes;
  442. int ix;
  443. static const unsigned char mask[4] = {0xff,0x1f,0x0f,0x07};
  444. // find the start of the next/previous character
  445. while((*buf & 0xc0) == 0x80)
  446. {
  447. // skip over non-initial bytes of a multi-byte utf8 character
  448. if(backwards)
  449. buf--;
  450. else
  451. buf++;
  452. }
  453. n_bytes = 0;
  454. if((c1 = *buf++) & 0x80)
  455. {
  456. if((c1 & 0xe0) == 0xc0)
  457. n_bytes = 1;
  458. else
  459. if((c1 & 0xf0) == 0xe0)
  460. n_bytes = 2;
  461. else
  462. if((c1 & 0xf8) == 0xf0)
  463. n_bytes = 3;
  464. c1 &= mask[n_bytes];
  465. for(ix=0; ix<n_bytes; ix++)
  466. {
  467. c1 = (c1 << 6) + (*buf++ & 0x3f);
  468. }
  469. }
  470. *c = c1;
  471. return(n_bytes+1);
  472. }
  473. char *strchr_w(const char *s, int c)
  474. {//=================================
  475. // return NULL for any non-ascii character
  476. if(c >= 0x80)
  477. return(NULL);
  478. return(strchr((char *)s,c)); // (char *) is needed for Borland compiler
  479. }
  480. int PhonemeCode(unsigned int mnem)
  481. {//===============================
  482. int ix;
  483. for(ix=0; ix<n_phoneme_tab; ix++)
  484. {
  485. if(phoneme_tab[ix]->mnemonic == mnem)
  486. return(phoneme_tab[ix]->code);
  487. }
  488. return(phonSCHWA);
  489. }
  490. int Translator::TranslateWord(char *word1, int next_pause, WORD_TAB *wtab)
  491. {//=======================================================================
  492. // word1 is terminated by space (0x20) character
  493. int length;
  494. int word_length;
  495. int ix;
  496. int posn;
  497. unsigned int dictionary_flags=0;
  498. unsigned int dictionary_flags2=0;
  499. int end_type=0;
  500. int prefix_type=0;
  501. char *wordx;
  502. char phonemes[N_WORD_PHONEMES];
  503. char *ph_limit;
  504. char *phonemes_ptr;
  505. char prefix_phonemes[N_WORD_PHONEMES];
  506. char end_phonemes[N_WORD_PHONEMES];
  507. char word_copy[N_WORD_BYTES];
  508. int found=0;
  509. int end_flags;
  510. char c_temp; // save a character byte while we temporarily replace it with space
  511. int first_char;
  512. int last_char = 0;
  513. int unpron_length;
  514. int add_plural_suffix = 0;
  515. int prefix_flags = 0;
  516. int confirm_prefix;
  517. int spell_word;
  518. int wflags = wtab->flags;
  519. int wmark = wtab->wmark;
  520. // translate these to get pronunciations of plural 's' suffix (different forms depending on
  521. // the preceding letter
  522. static char word_zz[4] = {0,'z','z',0};
  523. static char word_iz[4] = {0,'i','z',0};
  524. static char word_ss[4] = {0,'s','s',0};
  525. prefix_phonemes[0] = 0;
  526. end_phonemes[0] = 0;
  527. ph_limit = &phonemes[N_WORD_PHONEMES];
  528. // count the length of the word
  529. wordx = word1;
  530. utf8_in(&first_char,wordx,0);
  531. word_length = 0;
  532. while((*wordx != 0) && (*wordx != ' '))
  533. {
  534. wordx += utf8_in(&last_char,wordx,0);
  535. word_length++;
  536. }
  537. // try an initial lookup in the dictionary list, we may find a pronunciation specified, or
  538. // we may just find some flags
  539. if((option_sayas & 0xf0) == 0x10)
  540. {
  541. // SAYAS_CHAR, SAYAS_GYLPH, or SAYAS_SINGLE_CHAR
  542. spell_word = option_sayas & 0xf; // 2,3,4
  543. }
  544. else
  545. {
  546. spell_word = 0;
  547. found = LookupDictList(&word1,phonemes,&dictionary_flags,FLAG_ALLOW_TEXTMODE | wflags << 16); // the original word
  548. if(phonemes[0] == phonSWITCH)
  549. {
  550. // change to another language in order to translate this word
  551. strcpy(word_phonemes,phonemes);
  552. return(0);
  553. }
  554. if((wmark > 0) && (wmark < 8))
  555. {
  556. // the stressed syllable has been specified in the text (TESTING)
  557. dictionary_flags = (dictionary_flags & ~0xf) | wmark;
  558. }
  559. if(!found && (dictionary_flags & FLAG_ABBREV))
  560. {
  561. // the word has $abbrev flag, but no pronunciation specified. Speak as individual letters
  562. spell_word = 1;
  563. }
  564. if(!found && iswdigit(first_char))
  565. {
  566. Lookup("_0lang",word_phonemes);
  567. if(word_phonemes[0] == phonSWITCH)
  568. return(0);
  569. found = TranslateNumber(word1,phonemes,&dictionary_flags,wflags);
  570. }
  571. if(!found & ((word_flags & FLAG_UPPERS) != FLAG_FIRST_UPPER))
  572. {
  573. // either all upper or all lower case
  574. if((langopts.numbers & NUM_ROMAN) || ((langopts.numbers & NUM_ROMAN_UC) && (word_flags & FLAG_ALL_UPPER)))
  575. {
  576. if((found = TranslateRoman(word1,phonemes)) != 0)
  577. dictionary_flags |= FLAG_ABBREV; // don't spell capital Roman numbers as individual letters
  578. }
  579. }
  580. if((wflags & FLAG_ALL_UPPER) && (clause_upper_count <= clause_lower_count) &&
  581. !(dictionary_flags & (FLAG_ABBREV | FLAG_SKIPWORDS)) && (word_length>1) && (word_length<4) && iswalpha(first_char))
  582. {
  583. // An upper case word in a lower case clause. This could be an abbreviation.
  584. spell_word = 1;
  585. }
  586. }
  587. if(spell_word > 0)
  588. {
  589. // Speak as individual letters
  590. wordx = word1;
  591. posn = 0;
  592. phonemes[0] = 0;
  593. end_type = 0;
  594. while(*wordx != ' ')
  595. {
  596. wordx += TranslateLetter(wordx, phonemes,spell_word);
  597. if(phonemes[0] == phonSWITCH)
  598. {
  599. // change to another language in order to translate this word
  600. strcpy(word_phonemes,phonemes);
  601. return(0);
  602. }
  603. }
  604. SetSpellingStress(phonemes,spell_word);
  605. }
  606. else
  607. if(found == 0)
  608. {
  609. // word's pronunciation is not given in the dictionary list, although
  610. // dictionary_flags may have ben set there
  611. posn = 0;
  612. length = 999;
  613. wordx = word1;
  614. while(((length < 3) && (length > 0))|| (word_length > 1 && Unpronouncable(wordx)))
  615. {
  616. char *p;
  617. // This word looks "unpronouncable", so speak letters individually until we
  618. // find a remainder that we can pronounce.
  619. wordx += TranslateLetter(wordx,phonemes,0);
  620. if(phonemes[0] == phonSWITCH)
  621. {
  622. // change to another language in order to translate this word
  623. strcpy(word_phonemes,phonemes);
  624. return(0);
  625. }
  626. p = &wordx[word_length-3];
  627. if(memcmp(p,"'s ",3) == 0)
  628. {
  629. // remove a 's suffix and pronounce this separately (not as an individual letter)
  630. add_plural_suffix = 1;
  631. p[0] = ' ';
  632. p[1] = ' ';
  633. last_char = p[-1];
  634. }
  635. length=0;
  636. while(wordx[length] != ' ') length++;
  637. if(length > 0)
  638. wordx[-1] = ' '; // prevent this affecting the pronunciation of the pronuncable part
  639. }
  640. SetSpellingStress(phonemes,0);
  641. // anything left ?
  642. if(*wordx != ' ')
  643. {
  644. // Translate the stem
  645. unpron_length = strlen(phonemes);
  646. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags);
  647. if(phonemes[0] == phonSWITCH)
  648. {
  649. // change to another language in order to translate this word
  650. strcpy(word_phonemes,phonemes);
  651. return(0);
  652. }
  653. c_temp = wordx[-1];
  654. found = 0;
  655. confirm_prefix = 1;
  656. while(end_type & SUFX_P)
  657. {
  658. // Found a standard prefix, remove it and retranslate
  659. if(confirm_prefix)
  660. {
  661. int end2;
  662. char phonemes2[N_WORD_PHONEMES];
  663. char end_phonemes2[N_WORD_PHONEMES];
  664. // remove any standard suffix and confirm that the prefix is still recognised
  665. phonemes2[0] = 0;
  666. end2 = TranslateRules(wordx, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags);
  667. if(end2)
  668. {
  669. RemoveEnding(wordx,end2,word_copy);
  670. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags);
  671. memcpy(wordx,word_copy,strlen(word_copy));
  672. if((end_type & SUFX_P) == 0)
  673. {
  674. // after removing the suffix, the prefix is no longer recognised.
  675. // Keep the suffix, but don't use the prefix
  676. end_type = end2;
  677. strcpy(phonemes,phonemes2);
  678. strcpy(end_phonemes,end_phonemes2);
  679. if(option_phonemes == 2)
  680. {
  681. DecodePhonemes(end_phonemes,end_phonemes2);
  682. fprintf(f_trans," suffix [%s]\n\n",end_phonemes2);
  683. }
  684. }
  685. confirm_prefix = 0;
  686. continue;
  687. }
  688. }
  689. strcat(prefix_phonemes,end_phonemes);
  690. end_phonemes[0] = 0;
  691. prefix_type = end_type;
  692. if(prefix_type & SUFX_V)
  693. {
  694. expect_verb = 1; // use the verb form of the word
  695. }
  696. wordx[-1] = c_temp;
  697. for(ix=(prefix_type & 0xf); ix>0; ix--) // num. of characters to remove
  698. {
  699. wordx++;
  700. while((*wordx & 0xc0) == 0x80) wordx++; // for multibyte characters
  701. }
  702. c_temp = wordx[-1];
  703. wordx[-1] = ' ';
  704. confirm_prefix = 1;
  705. end_type = 0;
  706. found = LookupDictList(&wordx,phonemes,&dictionary_flags2,SUFX_P | (wflags << 16)); // without prefix
  707. if(dictionary_flags==0)
  708. dictionary_flags = dictionary_flags2;
  709. else
  710. prefix_flags = 1;
  711. if(found == 0)
  712. {
  713. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags);
  714. if(phonemes[0] == phonSWITCH)
  715. {
  716. // change to another language in order to translate this word
  717. wordx[-1] = c_temp;
  718. strcpy(word_phonemes,phonemes);
  719. return(0);
  720. }
  721. }
  722. }
  723. if((end_type != 0) && !(end_type & SUFX_P))
  724. {
  725. char phonemes2[N_WORD_PHONEMES];
  726. strcpy(phonemes2,phonemes);
  727. // The word has a standard ending, re-translate without this ending
  728. end_flags = RemoveEnding(wordx,end_type,word_copy);
  729. phonemes_ptr = &phonemes[unpron_length];
  730. phonemes_ptr[0] = 0;
  731. if(prefix_phonemes[0] != 0)
  732. {
  733. // lookup the stem without the prefix removed
  734. wordx[-1] = c_temp;
  735. found = LookupDictList(&word1,phonemes_ptr,&dictionary_flags2,end_flags | (wflags << 16)); // include prefix, but not suffix
  736. wordx[-1] = ' ';
  737. if(dictionary_flags==0)
  738. dictionary_flags = dictionary_flags2;
  739. if(found)
  740. prefix_phonemes[0] = 0; // matched whole word, don't need prefix now
  741. if((found==0) && (dictionary_flags2 != 0))
  742. prefix_flags = 1;
  743. }
  744. if(found == 0)
  745. {
  746. found = LookupDictList(&wordx,phonemes_ptr,&dictionary_flags2,end_flags | (wflags << 16)); // without prefix and suffix
  747. if(phonemes_ptr[0] == phonSWITCH)
  748. {
  749. // change to another language in order to translate this word
  750. memcpy(wordx,word_copy,strlen(word_copy));
  751. strcpy(word_phonemes,phonemes_ptr);
  752. return(0);
  753. }
  754. if(dictionary_flags==0)
  755. dictionary_flags = dictionary_flags2;
  756. }
  757. if(found == 0)
  758. {
  759. if(end_type & SUFX_Q)
  760. {
  761. // don't retranslate, use the original lookup result
  762. strcpy(phonemes,phonemes2);
  763. // language specific changes
  764. ApplySpecialAttribute(phonemes,dictionary_flags);
  765. }
  766. else
  767. {
  768. if(end_flags & FLAG_SUFX)
  769. TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags | FLAG_SUFFIX_REMOVED, dictionary_flags);
  770. else
  771. TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags,dictionary_flags);
  772. if(phonemes[0] == phonSWITCH)
  773. {
  774. // change to another language in order to translate this word
  775. strcpy(word_phonemes,phonemes);
  776. memcpy(wordx,word_copy,strlen(word_copy));
  777. wordx[-1] = c_temp;
  778. return(0);
  779. }
  780. }
  781. }
  782. if((end_type & SUFX_T) == 0)
  783. {
  784. // the default is to add the suffix and then determine the word's stress pattern
  785. AppendPhonemes(phonemes, N_WORD_PHONEMES, end_phonemes);
  786. end_phonemes[0] = 0;
  787. }
  788. }
  789. wordx[-1] = c_temp;
  790. }
  791. }
  792. if((add_plural_suffix) || (wflags & FLAG_HAS_PLURAL))
  793. {
  794. // s or 's suffix, append [s], [z] or [Iz] depending on previous letter
  795. if(last_char == 'f')
  796. TranslateRules(&word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  797. else
  798. if((last_char==0) || (strchr_w("hsx",last_char)==NULL))
  799. TranslateRules(&word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  800. else
  801. TranslateRules(&word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  802. }
  803. /* determine stress pattern for this word */
  804. /******************************************/
  805. /* NOTE: this also adds a single PAUSE if the previous word ended
  806. in a primary stress, and this one starts with one */
  807. if(prefix_flags || (strchr(prefix_phonemes,phonSTRESS_P)!=NULL))
  808. {
  809. if((langopts.param[LOPT_PREFIXES]) || (prefix_type & SUFX_T))
  810. {
  811. char *p;
  812. // German, keep a secondary stress on the stem
  813. SetWordStress(phonemes,dictionary_flags,3,0);
  814. // reduce all but the first primary stress
  815. ix=0;
  816. for(p=prefix_phonemes; *p != 0; p++)
  817. {
  818. if(*p == phonSTRESS_P)
  819. {
  820. if(ix==0)
  821. ix=1;
  822. else
  823. *p = phonSTRESS_3;
  824. }
  825. }
  826. strcpy(word_phonemes,prefix_phonemes);
  827. strcat(word_phonemes,phonemes);
  828. SetWordStress(word_phonemes,dictionary_flags,-1,0);
  829. }
  830. else
  831. {
  832. // stress position affects the whole word, including prefix
  833. strcpy(word_phonemes,prefix_phonemes);
  834. strcat(word_phonemes,phonemes);
  835. SetWordStress(word_phonemes,dictionary_flags,-1,prev_last_stress);
  836. }
  837. }
  838. else
  839. {
  840. if(prefix_phonemes[0] == 0)
  841. SetWordStress(phonemes,dictionary_flags,-1,prev_last_stress);
  842. else
  843. SetWordStress(phonemes,dictionary_flags,-1,0);
  844. strcpy(word_phonemes,prefix_phonemes);
  845. strcat(word_phonemes,phonemes);
  846. }
  847. if(end_phonemes[0] != 0)
  848. {
  849. // a suffix had the SUFX_T option set, add the suffix after the stress pattern has been determined
  850. strcat(word_phonemes,end_phonemes);
  851. }
  852. // if(next_pause > 2)
  853. ix = ((dictionary_flags >> 5) & 7); // dictionary indicates skip next word(s)
  854. if(wtab[ix].flags & FLAG_LAST_WORD)
  855. {
  856. // the word has attribute to stress or unstress when at end of clause
  857. if(dictionary_flags & (FLAG_STRESS_END | FLAG_STRESS_END2))
  858. ChangeWordStress(this,word_phonemes,4);
  859. // SetWordStress(word_phonemes,0,4,prev_last_stress);
  860. else
  861. if(dictionary_flags & FLAG_UNSTRESS_END)
  862. ChangeWordStress(this,word_phonemes,3);
  863. // SetWordStress(word_phonemes,0,3,prev_last_stress);
  864. }
  865. if(wflags & FLAG_STRESSED_WORD)
  866. {
  867. // A word is indicated in the source text as stressed
  868. // we need to improve the intonation module to deal better with a clauses tonic
  869. // stress being early in the clause, before enabling this
  870. //SetWordStress(word_phonemes,0,5,prev_last_stress);
  871. }
  872. // dictionary flags for this word give a clue about which alternative pronunciations of
  873. // following words to use.
  874. if(end_type & SUFX_F)
  875. {
  876. // expect a verb form, with or without -s suffix
  877. expect_verb = 2;
  878. expect_verb_s = 2;
  879. }
  880. if(dictionary_flags & FLAG_PASTF)
  881. {
  882. /* expect perfect tense in next two words */
  883. expect_past = 3;
  884. expect_verb = 0;
  885. }
  886. else
  887. if(dictionary_flags & FLAG_VERBF)
  888. {
  889. /* expect a verb in the next word */
  890. expect_verb = 2;
  891. expect_verb_s = 0; /* verb won't have -s suffix */
  892. }
  893. else
  894. if(dictionary_flags & FLAG_VERBSF)
  895. {
  896. // expect a verb, must have a -s suffix
  897. expect_verb = 0;
  898. expect_verb_s = 2;
  899. expect_past = 0;
  900. }
  901. else
  902. if(dictionary_flags & FLAG_NOUNF)
  903. {
  904. /* not expecting a verb next */
  905. expect_verb = 0;
  906. expect_verb_s = 0;
  907. expect_past = 0;
  908. }
  909. if((wordx[0] != 0) && (!(dictionary_flags & FLAG_VERB_EXT)))
  910. {
  911. if(expect_verb > 0)
  912. expect_verb -= 1;
  913. if(expect_verb_s > 0)
  914. expect_verb_s -= 1;
  915. if(expect_past > 0)
  916. expect_past -= 1;
  917. }
  918. if((word_length == 1) && iswalpha(first_char) && (first_char != 'i'))
  919. {
  920. // English Specific !!!!
  921. // any single letter before a dot is an abbreviation, except 'I'
  922. dictionary_flags |= FLAG_DOT;
  923. }
  924. return(dictionary_flags);
  925. } // end of TranslateWord
  926. static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode)
  927. {//==========================================================
  928. p->phcode = phcode;
  929. p->stress = 0;
  930. p->tone_number = 0;
  931. p->synthflags = 0;
  932. p->sourceix = 0;
  933. }
  934. static int CountSyllables(unsigned char *phonemes)
  935. {//===============================================
  936. int count = 0;
  937. int phon;
  938. while((phon = *phonemes++) != 0)
  939. {
  940. if(phoneme_tab[phon]->type == phVOWEL)
  941. count++;
  942. }
  943. return(count);
  944. }
  945. int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int next_pause)
  946. {//======================================================================================
  947. int flags=0;
  948. int stress;
  949. int next_stress;
  950. int next_tone=0;
  951. unsigned char *p;
  952. int srcix;
  953. int embedded_flag=0;
  954. int embedded_cmd;
  955. int value;
  956. int found_dict_flag;
  957. unsigned char ph_code;
  958. PHONEME_LIST2 *plist2;
  959. PHONEME_TAB *ph;
  960. int max_stress;
  961. int max_stress_ix=0;
  962. int prev_vowel = -1;
  963. int pitch_raised = 0;
  964. int switch_phonemes = -1;
  965. int first_phoneme = 1;
  966. int source_ix;
  967. int len;
  968. int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
  969. const char *new_language;
  970. unsigned char bad_phoneme[4];
  971. len = wtab->length;
  972. if(len > 31) len = 31;
  973. source_ix = (wtab->sourceix & 0x7ff) | (len << 11); // bits 0-10 sourceix, bits 11-15 word length
  974. word_flags = wtab[0].flags;
  975. if(word_flags & FLAG_EMBEDDED)
  976. {
  977. embedded_flag = SFLAG_EMBEDDED;
  978. value = embedded_list[embedded_read] >> 8;
  979. switch(embedded_cmd = embedded_list[embedded_read] & 0x1f)
  980. {
  981. case EMBED_Y:
  982. option_sayas = value;
  983. break;
  984. case EMBED_F:
  985. option_emphasis = value;
  986. break;
  987. case EMBED_B:
  988. // break command
  989. if(value == 0)
  990. pre_pause = 0; // break=none
  991. else
  992. pre_pause += value;
  993. break;
  994. }
  995. while((embedded_list[embedded_read++] & 0x80) == 0); // read over the embedded commands for this word
  996. }
  997. if(word[0] == 0)
  998. {
  999. // nothing to translate
  1000. word_phonemes[0] = 0;
  1001. return(0);
  1002. }
  1003. // after a $pause word attribute, ignore a $pause attribute on the next two words
  1004. if(prepause_timeout > 0)
  1005. prepause_timeout--;
  1006. if((option_sayas & 0xf0) == 0x10)
  1007. {
  1008. // SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
  1009. pre_pause += 4;
  1010. }
  1011. if(word_flags & FLAG_FIRST_UPPER)
  1012. {
  1013. if((option_capitals > 2) && (embedded_ix < N_EMBEDDED_LIST-6))
  1014. {
  1015. // indicate capital letter by raising pitch
  1016. if(embedded_flag)
  1017. embedded_list[embedded_ix-1] &= ~0x80; // already embedded command before this word, remove terminator
  1018. if((pitch_raised = option_capitals) == 3)
  1019. pitch_raised = 20; // default pitch raise for capitals
  1020. embedded_list[embedded_ix++] = EMBED_P+0x40+0x80 + (pitch_raised << 8); // raise pitch
  1021. embedded_flag = SFLAG_EMBEDDED;
  1022. }
  1023. }
  1024. p = (unsigned char *)translator->word_phonemes;
  1025. if(word_flags & FLAG_PHONEMES)
  1026. {
  1027. // The input is in phoneme mnemonics, not language text
  1028. EncodePhonemes(word,word_phonemes,bad_phoneme);
  1029. flags = FLAG_FOUND;
  1030. }
  1031. else
  1032. {
  1033. flags = translator->TranslateWord(word, next_pause, wtab);
  1034. if((flags & FLAG_ALT2_TRANS) && ((sylimit = langopts.param[LOPT_COMBINE_WORDS]) > 0))
  1035. {
  1036. char *p2;
  1037. int ok = 1;
  1038. int flags2;
  1039. int c_word2;
  1040. char ph_buf[N_WORD_PHONEMES];
  1041. // LANG=cs,sk
  1042. // combine a preposition with the following word
  1043. p2 = word;
  1044. while(*p2 != ' ') p2++;
  1045. utf8_in(&c_word2, p2+1, 0); // first character of the next word;
  1046. if(!iswalpha(c_word2))
  1047. {
  1048. ok =0;
  1049. }
  1050. if(sylimit & 0x100)
  1051. {
  1052. // only if the second word has $alt attribute
  1053. strcpy(ph_buf,word_phonemes);
  1054. flags2 = translator->TranslateWord(p2+1, 0, wtab+1);
  1055. if((flags2 & FLAG_ALT_TRANS) == 0)
  1056. {
  1057. ok = 0;
  1058. strcpy(word_phonemes,ph_buf);
  1059. }
  1060. }
  1061. if((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD))
  1062. {
  1063. // not if the next word is end-of-sentence
  1064. ok = 0;
  1065. }
  1066. if(ok)
  1067. {
  1068. *p2 = '-'; // replace next space by hyphen
  1069. flags = translator->TranslateWord(word, next_pause, wtab); // translate the combined word
  1070. if(CountSyllables(p) > (sylimit & 0xf))
  1071. {
  1072. // revert to separate words
  1073. *p2 = ' ';
  1074. flags = translator->TranslateWord(word, next_pause, wtab);
  1075. }
  1076. else
  1077. {
  1078. flags |= FLAG_SKIPWORDS;
  1079. dictionary_skipwords = 1;
  1080. }
  1081. }
  1082. }
  1083. if(p[0] == phonSWITCH)
  1084. {
  1085. // this word uses a different language
  1086. new_language = (char *)(&p[1]);
  1087. if(new_language[0]==0)
  1088. new_language = "en";
  1089. if((switch_phonemes = SelectPhonemeTableName(new_language)) >= 0)
  1090. {
  1091. if((translator2 != NULL) && (strcmp(new_language,translator2_language) != 0))
  1092. {
  1093. // we already have an alternative translator, but not for the required language, delete it
  1094. delete translator2;
  1095. translator2 = NULL;
  1096. }
  1097. if(translator2 == NULL)
  1098. {
  1099. translator2 = SelectTranslator(new_language);
  1100. strcpy(translator2_language,new_language);
  1101. if(translator2->LoadDictionary(new_language,0) != 0)
  1102. {
  1103. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  1104. switch_phonemes = -1;
  1105. translator2_language[0] = 0;
  1106. }
  1107. }
  1108. }
  1109. if(switch_phonemes >= 0)
  1110. {
  1111. // re-translate the word using the new translator
  1112. flags = translator2->TranslateWord(word, next_pause, wtab);
  1113. strcpy((char *)p,translator2->word_phonemes);
  1114. if(p[0] == phonSWITCH)
  1115. {
  1116. // the second translator doesn't want to process this word
  1117. switch_phonemes = -1;
  1118. }
  1119. }
  1120. if(switch_phonemes < 0)
  1121. {
  1122. // language code is not recognised or 2nd translator won't translate it
  1123. p[0] = phonSCHWA; // just say something
  1124. p[1] = phonSCHWA;
  1125. p[2] = 0;
  1126. }
  1127. }
  1128. if(!(word_flags & FLAG_LAST_WORD) && !(word_flags & FLAG_HYPHEN))
  1129. {
  1130. if(flags & FLAG_PAUSE1)
  1131. {
  1132. if(pre_pause < 1)
  1133. pre_pause = 1;
  1134. }
  1135. if((flags & FLAG_PREPAUSE) && (prepause_timeout == 0))
  1136. {
  1137. // the word is marked in the dictionary list with $pause
  1138. if(pre_pause < 4) pre_pause = 4;
  1139. prepause_timeout = 3;
  1140. }
  1141. }
  1142. if((option_emphasis >= 3) && (pre_pause < 2))
  1143. pre_pause = 2;
  1144. }
  1145. plist2 = &ph_list2[n_ph_list2];
  1146. stress = 0;
  1147. next_stress = 0;
  1148. srcix = 0;
  1149. max_stress = -1;
  1150. found_dict_flag = 0;
  1151. if(flags & FLAG_FOUND)
  1152. found_dict_flag = SFLAG_DICTIONARY;
  1153. while((pre_pause > 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1154. {
  1155. // add pause phonemes here. Either because of punctuation (brackets or quotes) in the
  1156. // text, or because the word is marked in the dictionary lookup as a conjunction
  1157. if(pre_pause > 1)
  1158. {
  1159. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE);
  1160. pre_pause -= 2;
  1161. }
  1162. else
  1163. {
  1164. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_NOLINK);
  1165. pre_pause--;
  1166. }
  1167. end_stressed_vowel = 0; // forget about the previous word
  1168. prev_dict_flags = 0;
  1169. }
  1170. if((option_capitals==1) && (word_flags & FLAG_FIRST_UPPER))
  1171. {
  1172. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1173. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1174. if((word_flags & FLAG_ALL_UPPER) && IsAlpha(word[1]))
  1175. {
  1176. // word > 1 letter and all capitals
  1177. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1178. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1179. }
  1180. }
  1181. if(switch_phonemes >= 0)
  1182. {
  1183. // this word uses a different phoneme table
  1184. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1185. ph_list2[n_ph_list2++].tone_number = switch_phonemes; // temporary phoneme table number
  1186. }
  1187. // remove initial pause from a word if it follows a hyphen
  1188. if((word_flags & FLAG_HYPHEN) && (phoneme_tab[*p]->type == phPAUSE))
  1189. p++;
  1190. while(((ph_code = *p++) != 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1191. {
  1192. if(ph_code == 255)
  1193. continue; // unknown phoneme
  1194. // Add the phonemes to the first stage phoneme list (ph_list2)
  1195. ph = phoneme_tab[ph_code];
  1196. if(ph->type == phSTRESS)
  1197. {
  1198. // don't add stress phonemes codes to the list, but give their stress
  1199. // value to the next vowel phoneme
  1200. // std_length is used to hold stress number or (if >10) a tone number for a tone language
  1201. if(ph->spect == 0)
  1202. next_stress = ph->std_length;
  1203. else
  1204. {
  1205. // for tone languages, the tone number for a syllable follows the vowel
  1206. if(prev_vowel >= 0)
  1207. {
  1208. ph_list2[prev_vowel].tone_number = ph_code;
  1209. }
  1210. else
  1211. {
  1212. next_tone = ph_code; // no previous vowel, apply to the next vowel
  1213. }
  1214. }
  1215. }
  1216. else
  1217. if(ph_code == phonSYLLABIC)
  1218. {
  1219. // mark the previous phoneme as a syllabic consonant
  1220. ph_list2[n_ph_list2-1].synthflags |= SFLAG_SYLLABLE;
  1221. ph_list2[n_ph_list2-1].stress = next_stress;
  1222. }
  1223. else
  1224. if(ph_code == phonLENGTHEN)
  1225. {
  1226. ph_list2[n_ph_list2-1].synthflags |= SFLAG_LENGTHEN;
  1227. }
  1228. else
  1229. if(ph_code == phonEND_WORD)
  1230. {
  1231. // a || symbol in a phoneme string was used to indicate a word boundary
  1232. // Don't add this phoneme to the list, but make sure the next phoneme has
  1233. // a newword indication
  1234. srcix = source_ix+1;
  1235. }
  1236. else
  1237. if(ph_code == phonX1)
  1238. {
  1239. // a language specific action
  1240. if(langopts.param[LOPT_IT_DOUBLING])
  1241. {
  1242. flags |= FLAG_DOUBLING;
  1243. }
  1244. }
  1245. else
  1246. {
  1247. ph_list2[n_ph_list2].phcode = ph_code;
  1248. ph_list2[n_ph_list2].tone_number = 0;
  1249. ph_list2[n_ph_list2].synthflags = embedded_flag | found_dict_flag;
  1250. embedded_flag = 0;
  1251. ph_list2[n_ph_list2].sourceix = srcix;
  1252. srcix = 0;
  1253. if(ph->type == phVOWEL)
  1254. {
  1255. stress = next_stress;
  1256. next_stress = 0;
  1257. if((prev_vowel >= 0) && (n_ph_list2-1) != prev_vowel)
  1258. ph_list2[n_ph_list2-1].stress = stress; // set stress for previous consonant
  1259. ph_list2[n_ph_list2].synthflags |= SFLAG_SYLLABLE;
  1260. prev_vowel = n_ph_list2;
  1261. if(stress > max_stress)
  1262. {
  1263. max_stress = stress;
  1264. max_stress_ix = n_ph_list2;
  1265. }
  1266. if(next_tone != 0)
  1267. {
  1268. ph_list2[n_ph_list2].tone_number = next_tone;
  1269. next_tone=0;
  1270. }
  1271. }
  1272. else
  1273. {
  1274. if(first_phoneme && langopts.param[LOPT_IT_DOUBLING])
  1275. {
  1276. if(((prev_dict_flags & FLAG_DOUBLING) && (langopts.param[LOPT_IT_DOUBLING] & 1)) ||
  1277. (end_stressed_vowel && (langopts.param[LOPT_IT_DOUBLING] & 2)))
  1278. {
  1279. // italian, double the initial consonant if the previous word ends with a
  1280. // stressed vowel, or is marked with a flag
  1281. ph_list2[n_ph_list2].synthflags |= SFLAG_LENGTHEN;
  1282. }
  1283. }
  1284. }
  1285. ph_list2[n_ph_list2].stress = stress;
  1286. n_ph_list2++;
  1287. first_phoneme = 0;
  1288. }
  1289. }
  1290. plist2->sourceix = source_ix; // ????
  1291. end_stressed_vowel = 0;
  1292. if((stress >= 4) && (phoneme_tab[ph_list2[n_ph_list2-1].phcode]->type == phVOWEL))
  1293. {
  1294. end_stressed_vowel = 1; // word ends with a stressed vowel
  1295. }
  1296. if(switch_phonemes >= 0)
  1297. {
  1298. // this word uses a different phoneme table, now switch back
  1299. SelectPhonemeTable(voice->phoneme_tab_ix);
  1300. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1301. ph_list2[n_ph_list2++].tone_number = voice->phoneme_tab_ix; // original phoneme table number
  1302. }
  1303. if(pitch_raised > 0)
  1304. {
  1305. embedded_list[embedded_ix++] = EMBED_P+0x60+0x80 + (pitch_raised << 8); // lower pitch
  1306. SetPlist2(&ph_list2[n_ph_list2],phonPAUSE_SHORT);
  1307. ph_list2[n_ph_list2++].synthflags = SFLAG_EMBEDDED;
  1308. }
  1309. if(flags & FLAG_STRESS_END2)
  1310. {
  1311. // this's word's stress could be increased later
  1312. ph_list2[max_stress_ix].synthflags |= SFLAG_PROMOTE_STRESS;
  1313. }
  1314. prev_dict_flags = flags;
  1315. return(flags);
  1316. } // end of TranslateWord2
  1317. static int EmbeddedCommand(unsigned int &source_index)
  1318. {//===================================================
  1319. // An embedded command to change the pitch, volume, etc.
  1320. // returns number of commands added to embedded_list
  1321. // pitch,speed,amplitude,expression,reverb,tone,voice,sayas
  1322. const char *commands = "PSARHTIVYMUBF";
  1323. int value = -1;
  1324. int sign = 0;
  1325. unsigned char c;
  1326. char *p;
  1327. int cmd;
  1328. c = source[source_index];
  1329. if(c == '+')
  1330. {
  1331. sign = 0x40;
  1332. source_index++;
  1333. }
  1334. else
  1335. if(c == '-')
  1336. {
  1337. sign = 0x60;
  1338. source_index++;
  1339. }
  1340. if(isdigit(source[source_index]))
  1341. {
  1342. value = atoi(&source[source_index]);
  1343. while(isdigit(source[source_index]))
  1344. source_index++;
  1345. }
  1346. c = source[source_index++];
  1347. if(embedded_ix >= (N_EMBEDDED_LIST - 2))
  1348. return(0); // list is full
  1349. if((p = strchr_w(commands,c)) == NULL)
  1350. return(0);
  1351. cmd = (p - commands)+1;
  1352. if(value == -1)
  1353. {
  1354. value = embedded_default[cmd];
  1355. sign = 0;
  1356. }
  1357. if(cmd == EMBED_Y)
  1358. {
  1359. option_sayas2 = value;
  1360. count_sayas_digits = 0;
  1361. }
  1362. embedded_list[embedded_ix++] = cmd + sign + (value << 8);
  1363. return(1);
  1364. } // end of EmbeddedCommand
  1365. int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, int *insert)
  1366. {//==================================================================================
  1367. int ix;
  1368. unsigned int word;
  1369. unsigned int new_c, c2, c_lower;
  1370. int upper_case = 0;
  1371. static int ignore_next = 0;
  1372. const unsigned int *replace_chars;
  1373. if(ignore_next)
  1374. {
  1375. ignore_next = 0;
  1376. return(8);
  1377. }
  1378. if(c == 0) return(0);
  1379. if((replace_chars = tr->langopts.replace_chars) == NULL)
  1380. return(c);
  1381. // there is a list of character codes to be substituted with alternative codes
  1382. if(iswupper(c_lower = c))
  1383. {
  1384. c_lower = towlower(c);
  1385. upper_case = 1;
  1386. }
  1387. new_c = 0;
  1388. for(ix=0; (word = replace_chars[ix]) != 0; ix+=2)
  1389. {
  1390. if(c_lower == (word & 0xffff))
  1391. {
  1392. if((word >> 16) == 0)
  1393. {
  1394. new_c = replace_chars[ix+1];
  1395. break;
  1396. }
  1397. if((word >> 16) == (unsigned int)tolower(next_in))
  1398. {
  1399. new_c = replace_chars[ix+1];
  1400. ignore_next = 1;
  1401. break;
  1402. }
  1403. }
  1404. }
  1405. if(new_c == 0)
  1406. return(c); // no substitution
  1407. if(new_c & 0xffe00000)
  1408. {
  1409. // there is a second character to be inserted
  1410. // don't convert the case of the second character unless the next letter is also upper case
  1411. c2 = new_c >> 16;
  1412. if(upper_case && iswupper(next_in))
  1413. c2 = towupper(c2);
  1414. *insert = c2;
  1415. new_c &= 0xffff;
  1416. }
  1417. if(upper_case)
  1418. new_c = towupper(new_c);
  1419. return(new_c);
  1420. }
  1421. int Translator::TranslateChar(char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert)
  1422. {//=====================================================================================================
  1423. // To allow language specific examination and replacement of characters
  1424. return(SubstituteChar(this,c,next_in,insert));
  1425. }
  1426. void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_out, char **voice_change)
  1427. {//======================================================================================================
  1428. int ix;
  1429. int c;
  1430. int cc;
  1431. unsigned int source_index=0;
  1432. unsigned int prev_source_index=0;
  1433. int prev_in;
  1434. int prev_out=' ';
  1435. int prev_out2;
  1436. int prev_in2=0;
  1437. int next_in;
  1438. int char_inserted=0;
  1439. int clause_pause;
  1440. int pre_pause=0;
  1441. int pre_pause_add=0;
  1442. int word_mark = 0;
  1443. int all_upper_case=FLAG_ALL_UPPER;
  1444. int finished;
  1445. int single_quoted;
  1446. int phoneme_mode = 0;
  1447. int dict_flags; // returned from dictionary lookup
  1448. int word_flags; // set here
  1449. int next_word_flags;
  1450. int embedded_count = 0;
  1451. int letter_count = 0;
  1452. int space_inserted = 0;
  1453. char *word;
  1454. char *p;
  1455. int j, k;
  1456. int n_digits;
  1457. unsigned short charix[N_TR_SOURCE+1];
  1458. WORD_TAB words[N_CLAUSE_WORDS];
  1459. int word_count=0; // index into words
  1460. char sbuf[512];
  1461. int terminator;
  1462. int tone;
  1463. p_textinput = (char *)vp_input;
  1464. p_wchar_input = (wchar_t *)vp_input;
  1465. embedded_ix = 0;
  1466. embedded_read = 0;
  1467. if((clause_start_char = count_characters) < 0)
  1468. clause_start_char = 0;
  1469. clause_start_word = count_words + 1;
  1470. for(ix=0; ix<N_TR_SOURCE; ix++)
  1471. charix[ix] = 0;
  1472. terminator = translator->ReadClause(f_text,source,charix,N_TR_SOURCE);
  1473. charix[N_TR_SOURCE] = count_characters;
  1474. clause_pause = (terminator & 0xff) * 10; // mS
  1475. tone = (terminator & 0xf00) >> 8;
  1476. for(p=source; *p != 0; p++)
  1477. {
  1478. if(!isspace2(*p))
  1479. {
  1480. break;
  1481. }
  1482. }
  1483. if(*p == 0)
  1484. {
  1485. // No characters except spaces. This is not a sentence.
  1486. // Don't add this pause, just make up the previous pause to this value;
  1487. clause_pause -= max_clause_pause;
  1488. if(clause_pause < 0)
  1489. clause_pause = 0;
  1490. terminator &= ~CLAUSE_BIT_SENTENCE; // clear sentence bit
  1491. max_clause_pause += clause_pause;
  1492. }
  1493. else
  1494. {
  1495. max_clause_pause = clause_pause;
  1496. }
  1497. if(new_sentence)
  1498. {
  1499. count_sentences++;
  1500. if(skip_sentences > 0)
  1501. {
  1502. skip_sentences--;
  1503. if(skip_sentences == 0)
  1504. skipping_text = 0;
  1505. }
  1506. }
  1507. ph_list2[0].phcode = phonPAUSE_SHORT;
  1508. ph_list2[0].stress = 0;
  1509. ph_list2[0].tone_number = 0;
  1510. ph_list2[0].sourceix = 0;
  1511. n_ph_list2 = 1;
  1512. prev_last_stress = 0;
  1513. prepause_timeout = 0;
  1514. word_count = 0;
  1515. single_quoted = 0;
  1516. word_flags = 0;
  1517. next_word_flags = 0;
  1518. expect_verb=0;
  1519. expect_past=0;
  1520. expect_verb_s=0;
  1521. end_stressed_vowel=0;
  1522. prev_dict_flags = 0;
  1523. sbuf[0] = 0;
  1524. sbuf[1] = ' ';
  1525. sbuf[2] = ' ';
  1526. ix = 3;
  1527. prev_in = ' ';
  1528. words[0].start = ix;
  1529. words[0].flags = 0;
  1530. finished = 0;
  1531. for(j=0; charix[j]==0; j++);
  1532. words[0].sourceix = charix[j];
  1533. for(k=j; charix[k]!=0; k++);
  1534. words[0].length = k-j;
  1535. while(!finished && (ix < (int)sizeof(sbuf))&& (n_ph_list2 < N_PHONEME_LIST-4))
  1536. {
  1537. prev_out2 = prev_out;
  1538. utf8_in(&prev_out,&sbuf[ix-1],1); // prev_out = sbuf[ix-1];
  1539. if(langopts.tone_numbers && isdigit(prev_out) && IsAlpha(prev_out2))
  1540. {
  1541. // tone numbers can be part of a word, consider them as alphabetic
  1542. prev_out = 'a';
  1543. }
  1544. if(prev_in2 != 0)
  1545. {
  1546. prev_in = prev_in2;
  1547. prev_in2 = 0;
  1548. }
  1549. else
  1550. if(source_index > 0)
  1551. {
  1552. utf8_in(&prev_in,&source[source_index-1],1); // prev_in = source[source_index-1];
  1553. }
  1554. prev_source_index = source_index;
  1555. if(char_inserted)
  1556. {
  1557. c = char_inserted;
  1558. char_inserted = 0;
  1559. }
  1560. else
  1561. {
  1562. source_index += utf8_in(&cc,&source[source_index],0); // cc = source[source_index++];
  1563. c = cc;
  1564. }
  1565. utf8_in(&next_in,&source[source_index],0);
  1566. if((c == CTRL_EMBEDDED) || (c == ctrl_embedded))
  1567. {
  1568. // start of embedded command in the text
  1569. int srcix = source_index-1;
  1570. if(prev_in != ' ')
  1571. {
  1572. c = ' ';
  1573. prev_in2 = c;
  1574. source_index--;
  1575. }
  1576. else
  1577. {
  1578. embedded_count += EmbeddedCommand(source_index);
  1579. prev_in2 = prev_in;
  1580. // replace the embedded command by spaces
  1581. memset(&source[srcix],' ',source_index-srcix);
  1582. source_index = srcix;
  1583. continue;
  1584. }
  1585. }
  1586. if(phoneme_mode)
  1587. {
  1588. all_upper_case = FLAG_PHONEMES;
  1589. if((c == ']') && (next_in == ']'))
  1590. {
  1591. phoneme_mode = 0;
  1592. source_index++;
  1593. c = ' ';
  1594. }
  1595. }
  1596. else
  1597. if((option_sayas2 & 0xf0) == SAYAS_DIGITS)
  1598. {
  1599. if(iswdigit(c))
  1600. {
  1601. count_sayas_digits++;
  1602. if(count_sayas_digits > (option_sayas2 & 0xf))
  1603. {
  1604. // break after the specified number of digits
  1605. c = ' ';
  1606. space_inserted = 1;
  1607. count_sayas_digits = 0;
  1608. }
  1609. }
  1610. else
  1611. {
  1612. count_sayas_digits = 0;
  1613. if(iswdigit(prev_out))
  1614. {
  1615. c = ' ';
  1616. space_inserted = 1;
  1617. }
  1618. }
  1619. }
  1620. else
  1621. if((option_sayas2 & 0xf0) != 0x10)
  1622. {
  1623. // speak as words
  1624. #ifdef deleted
  1625. if((c == '/') && (langopts.testing & 2) && isdigit(next_in) && IsAlpha(prev_out))
  1626. {
  1627. // TESTING, explicit indication of stressed syllable by /2 after the word
  1628. word_mark = next_in-'0';
  1629. source_index++;
  1630. c = ' ';
  1631. }
  1632. #endif
  1633. if((c == 0x92) || (c == 0xb4) || (c == 0x2019))
  1634. c = '\''; // 'microsoft' quote or sexed closing single quote - possibly used as apostrophe
  1635. if((c == '?') && IsAlpha(prev_out) && IsAlpha(next_in))
  1636. {
  1637. // ? between two letters may be a smart-quote replaced by ?
  1638. c = '\'';
  1639. }
  1640. c = TranslateChar(&source[source_index], prev_in,c, next_in, &char_inserted); // optional language specific function
  1641. if(c == 8)
  1642. continue; // ignore this character
  1643. if(char_inserted)
  1644. next_in = char_inserted;
  1645. if(!IsAlpha(c) && !iswspace(c) && (c != '\''))
  1646. {
  1647. if(IsAlpha(prev_out))
  1648. {
  1649. if(langopts.tone_numbers && isdigit(c) && !isdigit(next_in))
  1650. {
  1651. // allow a tone number as part of the word
  1652. }
  1653. else
  1654. {
  1655. c = ' '; // ensure we have an end-of-word terminator
  1656. space_inserted = 1;
  1657. }
  1658. }
  1659. }
  1660. if(iswdigit(prev_out))
  1661. {
  1662. if(!iswdigit(c) && (c != '.') && (c != ','))
  1663. {
  1664. c = ' '; // terminate digit string with a space
  1665. space_inserted = 1;
  1666. }
  1667. }
  1668. if((c == '[') && (next_in == '[') && option_phoneme_input)
  1669. {
  1670. phoneme_mode = FLAG_PHONEMES;
  1671. source_index++;
  1672. continue;
  1673. }
  1674. if(c == 0)
  1675. {
  1676. finished = 1;
  1677. c = ' ';
  1678. }
  1679. else
  1680. if(IsAlpha(c))
  1681. {
  1682. if(!IsAlpha(prev_out) || (langopts.ideographs && ((c >= 0x3000) || (prev_out >= 0x3000))))
  1683. {
  1684. if(prev_out != '\'')
  1685. letter_count = 0; // don't reset count for an apostrophy within a word
  1686. if((prev_out != ' ') && (prev_out != '\''))
  1687. {
  1688. // start of word, insert space if not one there already
  1689. c = ' ';
  1690. space_inserted = 1;
  1691. }
  1692. else
  1693. {
  1694. if(iswupper(c))
  1695. word_flags |= FLAG_FIRST_UPPER;
  1696. if((prev_out == ' ') && iswdigit(sbuf[ix-2]) && !iswdigit(prev_in))
  1697. {
  1698. // word, following a number, but with a space between
  1699. // Add an extra space, to distinguish "2 a" from "2a"
  1700. sbuf[ix++] = ' ';
  1701. words[word_count].start++;
  1702. }
  1703. }
  1704. }
  1705. letter_count++;
  1706. if(iswupper(c))
  1707. {
  1708. c = towlower(c);
  1709. if(iswlower(prev_in))
  1710. {
  1711. c = ' '; // lower case followed by upper case, treat as new word
  1712. space_inserted = 1;
  1713. prev_in2 = c;
  1714. }
  1715. //#ifdef deleted
  1716. // changed to break after the last uppercase letter, not before. See below
  1717. else
  1718. if((c != ' ') && iswupper(prev_in) && iswlower(next_in) &&
  1719. (memcmp(&source[source_index],"s ",2) != 0)) // ENGLISH specific plural
  1720. {
  1721. c = ' '; // change from upper to lower case, start new word at the last uppercase
  1722. space_inserted = 1;
  1723. prev_in2 = c;
  1724. next_word_flags |= FLAG_NOSPACE;
  1725. }
  1726. //#endif
  1727. }
  1728. else
  1729. {
  1730. #ifdef deleted
  1731. if(iswupper(prev_in) && iswalpha(prev_out2) &&
  1732. (memcmp(&source[source_index-1],"s ",2) != 0)) // ENGLISH specific plural
  1733. {
  1734. // change to break after the last uppercase letter, not before.
  1735. c = ' '; // more than one upper case followed by lower case, treat as new word
  1736. space_inserted = 1;
  1737. prev_in2 = c;
  1738. }
  1739. #endif
  1740. if((all_upper_case) && (letter_count > 2))
  1741. {
  1742. if((c == 's') && (next_in==' '))
  1743. {
  1744. c = ' ';
  1745. all_upper_case |= FLAG_HAS_PLURAL;
  1746. if(sbuf[ix-1] == '\'')
  1747. sbuf[ix-1] = ' ';
  1748. }
  1749. else
  1750. all_upper_case = 0; // current word contains lower case letters, not "'s"
  1751. }
  1752. else
  1753. all_upper_case = 0;
  1754. }
  1755. }
  1756. else
  1757. if(c=='-')
  1758. {
  1759. if(IsAlpha(prev_in) && IsAlpha(next_in))
  1760. {
  1761. // '-' between two letters is a hyphen, treat as a space
  1762. word_flags |= FLAG_HYPHEN;
  1763. words[word_count-1].flags |= FLAG_HYPHEN_AFTER;
  1764. c = ' ';
  1765. }
  1766. else
  1767. if((prev_in==' ') && (next_in==' '))
  1768. {
  1769. // ' - ' dash between two spaces, treat as pause
  1770. c = ' ';
  1771. pre_pause_add = 4;
  1772. }
  1773. else
  1774. if(next_in=='-')
  1775. {
  1776. // double hyphen, treat as pause
  1777. source_index++;
  1778. c = ' ';
  1779. pre_pause_add = 4;
  1780. }
  1781. else
  1782. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1783. {
  1784. // insert extra space between a word + space + hyphen, to distinguish 'a -2' from 'a-2'
  1785. sbuf[ix++] = ' ';
  1786. words[word_count].start++;
  1787. }
  1788. }
  1789. else
  1790. if(c == '\'')
  1791. {
  1792. if(iswalnum(prev_in) && IsAlpha(next_in))
  1793. {
  1794. // between two letters, consider apostrophe as part of the word
  1795. single_quoted = 0;
  1796. }
  1797. else
  1798. if((wcschr(char_plus_apostrophe,prev_in) != 0) && (prev_out2 == ' '))
  1799. {
  1800. // consider single character plus apostrophe as a word
  1801. single_quoted = 0;
  1802. if(next_in == ' ')
  1803. {
  1804. source_index++; // skip following space
  1805. }
  1806. }
  1807. else
  1808. {
  1809. if((prev_out == 's') && (single_quoted==0))
  1810. {
  1811. // looks like apostrophe after an 's'
  1812. c = ' ';
  1813. }
  1814. else
  1815. {
  1816. if(iswspace(prev_out))
  1817. single_quoted = 1;
  1818. else
  1819. single_quoted = 0;
  1820. pre_pause_add = 4; // single quote
  1821. c = ' ';
  1822. }
  1823. }
  1824. }
  1825. else
  1826. if(IsBracket(c))
  1827. {
  1828. pre_pause_add = 4;
  1829. c = ' ';
  1830. }
  1831. else
  1832. if(lookupwchar(breaks,c) != 0)
  1833. {
  1834. c = ' '; // various characters to treat as space
  1835. }
  1836. else
  1837. if(iswdigit(c))
  1838. {
  1839. if(langopts.tone_numbers && IsAlpha(prev_out) && !isdigit(next_in))
  1840. {
  1841. }
  1842. else
  1843. if((prev_out != ' ') && !iswdigit(prev_out) && (prev_out != langopts.decimal_sep)) // TEST2
  1844. {
  1845. c = ' ';
  1846. space_inserted = 1;
  1847. }
  1848. else
  1849. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1850. {
  1851. // insert extra space between a word and a number, to distinguish 'a 2' from 'a2'
  1852. sbuf[ix++] = ' ';
  1853. words[word_count].start++;
  1854. }
  1855. }
  1856. }
  1857. if(iswspace(c))
  1858. {
  1859. if(space_inserted)
  1860. {
  1861. source_index = prev_source_index; // rewind to the previous character
  1862. char_inserted = 0;
  1863. space_inserted = 0;
  1864. }
  1865. if(prev_out == ' ')
  1866. {
  1867. continue; // multiple spaces
  1868. }
  1869. // end of 'word'
  1870. sbuf[ix++] = ' ';
  1871. if((ix > words[word_count].start) && (word_count < N_CLAUSE_WORDS-1))
  1872. {
  1873. if(embedded_count > 0)
  1874. {
  1875. // there are embedded commands before this word
  1876. embedded_list[embedded_ix-1] |= 0x80; // terminate list of commands for this word
  1877. words[word_count].flags |= FLAG_EMBEDDED;
  1878. embedded_count = 0;
  1879. }
  1880. words[word_count].pre_pause = pre_pause;
  1881. words[word_count].flags |= (all_upper_case | word_flags);
  1882. words[word_count].wmark = word_mark;
  1883. if(pre_pause > 0)
  1884. {
  1885. // insert an extra space before the word, to prevent influence from previous word across the pause
  1886. for(j=ix; j>words[word_count].start; j--)
  1887. {
  1888. sbuf[j] = sbuf[j-1];
  1889. }
  1890. sbuf[j] = ' ';
  1891. words[word_count].start++;
  1892. ix++;
  1893. }
  1894. word_count++;
  1895. words[word_count].start = ix;
  1896. words[word_count].flags = 0;
  1897. for(j=source_index; charix[j] == 0; j++);
  1898. words[word_count].sourceix = charix[j];
  1899. for(k=j; charix[k]!=0; k++);
  1900. words[word_count].length = k-j;
  1901. word_flags = next_word_flags;
  1902. next_word_flags = 0;
  1903. pre_pause = 0;
  1904. word_mark = 0;
  1905. all_upper_case = FLAG_ALL_UPPER;
  1906. }
  1907. }
  1908. else
  1909. {
  1910. ix += utf8_out(c,&sbuf[ix]); // sbuf[ix++] = c;
  1911. }
  1912. if(pre_pause_add > pre_pause)
  1913. pre_pause = pre_pause_add;
  1914. pre_pause_add = 0;
  1915. }
  1916. if((word_count==0) && (embedded_count > 0))
  1917. {
  1918. // add a null 'word' to carry the embedded command flag
  1919. embedded_list[embedded_ix-1] |= 0x80;
  1920. words[word_count].flags |= FLAG_EMBEDDED;
  1921. word_count = 1;
  1922. }
  1923. clause_end = &sbuf[ix-1];
  1924. sbuf[ix] = 0;
  1925. words[0].pre_pause = 0; // don't add extra pause at beginning of clause
  1926. words[word_count].pre_pause = 8;
  1927. if(word_count > 0)
  1928. words[word_count-1].flags |= FLAG_LAST_WORD;
  1929. for(ix=0; ix<word_count; ix++)
  1930. {
  1931. int j;
  1932. char *pn;
  1933. char *pw;
  1934. char number_buf[80];
  1935. // start speaking at a specified word position in the text?
  1936. count_words++;
  1937. if(skip_words > 0)
  1938. {
  1939. skip_words--;
  1940. if(skip_words == 0)
  1941. skipping_text = 0;
  1942. }
  1943. if(skipping_text)
  1944. continue;
  1945. word = pw = &sbuf[words[ix].start];
  1946. for(n_digits=0; iswdigit(word[n_digits]); n_digits++); // count consecutive digits
  1947. if((n_digits > 4) && (word[0] != '0'))
  1948. {
  1949. // word is entirely digits, insert commas and break into 3 digit "words"
  1950. number_buf[0] = ' ';
  1951. pn = &number_buf[1];
  1952. j = n_digits;
  1953. while(pn < &number_buf[sizeof(number_buf)-3])
  1954. {
  1955. if(!isdigit(c = *pw++) && (c != langopts.decimal_sep))
  1956. break;
  1957. *pn++ = c;
  1958. if((--j > 0) && (j % 3)==0)
  1959. {
  1960. if(langopts.thousands_sep != ' ')
  1961. *pn++ = langopts.thousands_sep;
  1962. *pn++ = ' ';
  1963. }
  1964. }
  1965. pn[0] = ' ';
  1966. pn[1] = 0;
  1967. word = pw;
  1968. for(pw = &number_buf[1]; pw < pn;)
  1969. {
  1970. TranslateWord2(pw, &words[ix], words[ix].pre_pause,0 );
  1971. while(*pw++ != ' ');
  1972. words[ix].pre_pause = 0;
  1973. words[ix].flags = 0;
  1974. }
  1975. }
  1976. else
  1977. {
  1978. dict_flags = TranslateWord2(word, &words[ix], words[ix].pre_pause, words[ix+1].pre_pause);
  1979. if(dict_flags & FLAG_SKIPWORDS)
  1980. ix += dictionary_skipwords; // dictionary indicates skip next word(s)
  1981. if((dict_flags & FLAG_DOT) && (ix == word_count-1) && (terminator == CLAUSE_PERIOD))
  1982. {
  1983. // probably an abbreviation such as Mr. or B. rather than end of sentence
  1984. clause_pause = 10;
  1985. tone = 4;
  1986. }
  1987. }
  1988. }
  1989. for(ix=0; ix<2; ix++)
  1990. {
  1991. // terminate the clause with 2 PAUSE phonemes
  1992. ph_list2[n_ph_list2+ix].phcode = phonPAUSE;
  1993. ph_list2[n_ph_list2+ix].stress = 0;
  1994. ph_list2[n_ph_list2+ix].sourceix = 0;
  1995. ph_list2[n_ph_list2+ix].synthflags = 0;
  1996. }
  1997. n_ph_list2 += 2;
  1998. if(Eof() && ((word_count == 0) || (option_endpause==0)))
  1999. {
  2000. clause_pause = 10;
  2001. }
  2002. MakePhonemeList(clause_pause, new_sentence);
  2003. if(embedded_count) // ???? is this needed
  2004. {
  2005. phoneme_list[n_phoneme_list-2].synthflags = SFLAG_EMBEDDED;
  2006. embedded_list[embedded_ix-1] |= 0x80;
  2007. }
  2008. prev_clause_pause = clause_pause;
  2009. *tone_out = tone;
  2010. new_sentence = 0;
  2011. if(terminator & CLAUSE_BIT_SENTENCE)
  2012. {
  2013. new_sentence = 1; // next clause is a new sentence
  2014. }
  2015. if(voice_change != NULL)
  2016. {
  2017. // return new voice name if an embedded voice change command terminated the clause
  2018. if(terminator & CLAUSE_BIT_VOICE)
  2019. *voice_change = &source[source_index];
  2020. else
  2021. *voice_change = NULL;
  2022. }
  2023. if(Eof() || (vp_input==NULL))
  2024. return(NULL);
  2025. if(option_multibyte == espeakCHARS_WCHAR)
  2026. return((void *)p_wchar_input);
  2027. else
  2028. return((void *)p_textinput);
  2029. } // end of TranslateClause
  2030. void InitText(int control)
  2031. {//=======================
  2032. count_sentences = 0;
  2033. count_words = 0;
  2034. end_character_position = 0;
  2035. skip_sentences = 0;
  2036. skip_marker[0] = 0;
  2037. skip_words = 0;
  2038. skip_characters = 0;
  2039. skipping_text = 0;
  2040. new_sentence = 1;
  2041. ungot_char = 0;
  2042. prev_clause_pause = 0;
  2043. option_sayas = 0;
  2044. option_sayas2 = 0;
  2045. option_emphasis = 0;
  2046. InitText2();
  2047. if((control & espeakKEEP_NAMEDATA) == 0)
  2048. {
  2049. InitNamedata();
  2050. }
  2051. }