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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315
  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, 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 *word;
  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. word = word1;
  526. prefix_phonemes[0] = 0;
  527. end_phonemes[0] = 0;
  528. ph_limit = &phonemes[N_WORD_PHONEMES];
  529. // count the length of the word
  530. utf8_in(&first_char,word,0);
  531. word_length = 0;
  532. while((*word != 0) && (*word != ' '))
  533. {
  534. word += utf8_in(&last_char,word,0);
  535. word_length++;
  536. }
  537. word = word1;
  538. // try an initial lookup in the dictionary list, we may find a pronunciation specified, or
  539. // we may just find some flags
  540. if((option_sayas & 0xf0) == 0x10)
  541. {
  542. // SAYAS_CHAR, SAYAS_GYLPH, or SAYAS_SINGLE_CHAR
  543. spell_word = option_sayas & 0xf; // 2,3,4
  544. }
  545. else
  546. {
  547. spell_word = 0;
  548. found = LookupDictList(word,phonemes,&dictionary_flags,wflags << 16);
  549. if(phonemes[0] == phonSWITCH)
  550. {
  551. // change to another language in order to translate this word
  552. strcpy(word_phonemes,phonemes);
  553. return(0);
  554. }
  555. if((wmark > 0) && (wmark < 8))
  556. {
  557. // the stressed syllable has been specified in the text (TESTING)
  558. dictionary_flags = (dictionary_flags & ~0xf) | wmark;
  559. }
  560. if(!found && (dictionary_flags & FLAG_ABBREV))
  561. {
  562. // the word has $abbrev flag, but no pronunciation specified. Speak as individual letters
  563. spell_word = 1;
  564. }
  565. if(!found && iswdigit(first_char))
  566. {
  567. found = TranslateNumber(word,phonemes,&dictionary_flags,wflags);
  568. }
  569. if(!found & ((word_flags & FLAG_UPPERS) != FLAG_FIRST_UPPER))
  570. {
  571. // either all upper or all lower case
  572. if((found = TranslateRoman(word,phonemes)) != 0)
  573. dictionary_flags |= FLAG_ABBREV; // don't spell capital Roman numbers as individual letters
  574. }
  575. if((wflags & FLAG_ALL_UPPER) && (clause_upper_count <= clause_lower_count) &&
  576. !(dictionary_flags & (FLAG_ABBREV | FLAG_SKIPWORDS)) && (word_length>1) && (word_length<4) && iswalpha(first_char))
  577. {
  578. // An upper case word in a lower case clause. This could be an abbreviation.
  579. spell_word = 1;
  580. }
  581. }
  582. if(spell_word > 0)
  583. {
  584. // Speak as individual letters
  585. word = word1;
  586. posn = 0;
  587. phonemes[0] = 0;
  588. end_type = 0;
  589. while(*word != ' ')
  590. {
  591. word += TranslateLetter(word, phonemes,spell_word);
  592. if(phonemes[0] == phonSWITCH)
  593. {
  594. // change to another language in order to translate this word
  595. strcpy(word_phonemes,phonemes);
  596. return(0);
  597. }
  598. }
  599. SetSpellingStress(phonemes,spell_word);
  600. }
  601. else
  602. if(found == 0)
  603. {
  604. // word's pronunciation is not given in the dictionary list, although
  605. // dictionary_flags may have ben set there
  606. posn = 0;
  607. length = 999;
  608. while(((length < 3) && (length > 0))|| (word_length > 1 && Unpronouncable(word)))
  609. {
  610. char *p;
  611. // This word looks "unpronouncable", so speak letters individually until we
  612. // find a remainder that we can pronounce.
  613. word += TranslateLetter(word,phonemes,0);
  614. if(phonemes[0] == phonSWITCH)
  615. {
  616. // change to another language in order to translate this word
  617. strcpy(word_phonemes,phonemes);
  618. return(0);
  619. }
  620. p = &word[word_length-3];
  621. if(memcmp(p,"'s ",3) == 0)
  622. {
  623. // remove a 's suffix and pronounce this separately (not as an individual letter)
  624. add_plural_suffix = 1;
  625. p[0] = ' ';
  626. p[1] = ' ';
  627. last_char = p[-1];
  628. }
  629. length=0;
  630. while(word[length] != ' ') length++;
  631. if(length > 0)
  632. word[-1] = ' '; // prevent this affecting the pronunciation of the pronuncable part
  633. }
  634. SetSpellingStress(phonemes,0);
  635. // anything left ?
  636. if(*word != ' ')
  637. {
  638. // Translate the stem
  639. unpron_length = strlen(phonemes);
  640. end_type = TranslateRules(word, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags);
  641. if(phonemes[0] == phonSWITCH)
  642. {
  643. // change to another language in order to translate this word
  644. strcpy(word_phonemes,phonemes);
  645. return(0);
  646. }
  647. c_temp = word[-1];
  648. found = 0;
  649. confirm_prefix = 1;
  650. while(end_type & SUFX_P)
  651. {
  652. // Found a standard prefix, remove it and retranslate
  653. if(confirm_prefix)
  654. {
  655. int end2;
  656. char phonemes2[N_WORD_PHONEMES];
  657. char end_phonemes2[N_WORD_PHONEMES];
  658. // remove any standard suffix and confirm that the prefix is still recognised
  659. phonemes2[0] = 0;
  660. end2 = TranslateRules(word, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags);
  661. if(end2)
  662. {
  663. RemoveEnding(word,end2,word_copy);
  664. end_type = TranslateRules(word, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags);
  665. memcpy(word,word_copy,strlen(word_copy));
  666. if((end_type & SUFX_P) == 0)
  667. {
  668. // after removing the suffix, the prefix is no longer recognised.
  669. // Keep the suffix, but don't use the prefix
  670. end_type = end2;
  671. strcpy(phonemes,phonemes2);
  672. strcpy(end_phonemes,end_phonemes2);
  673. if(option_phonemes == 2)
  674. {
  675. DecodePhonemes(end_phonemes,end_phonemes2);
  676. fprintf(f_trans," suffix [%s]\n\n",end_phonemes2);
  677. }
  678. }
  679. confirm_prefix = 0;
  680. continue;
  681. }
  682. }
  683. strcat(prefix_phonemes,end_phonemes);
  684. end_phonemes[0] = 0;
  685. prefix_type = end_type;
  686. if(prefix_type & SUFX_V)
  687. {
  688. expect_verb = 1; // use the verb form of the word
  689. }
  690. word[-1] = c_temp;
  691. for(ix=(prefix_type & 0xf); ix>0; ix--) // num. of characters to remove
  692. {
  693. word++;
  694. while((*word & 0xc0) == 0x80) word++; // for multibyte characters
  695. }
  696. c_temp = word[-1];
  697. word[-1] = ' ';
  698. confirm_prefix = 1;
  699. end_type = 0;
  700. found = LookupDictList(word,phonemes,&dictionary_flags2,SUFX_P | (wflags << 16));
  701. if(dictionary_flags==0)
  702. dictionary_flags = dictionary_flags2;
  703. else
  704. prefix_flags = 1;
  705. if(found == 0)
  706. {
  707. end_type = TranslateRules(word, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags);
  708. if(phonemes[0] == phonSWITCH)
  709. {
  710. // change to another language in order to translate this word
  711. word[-1] = c_temp;
  712. strcpy(word_phonemes,phonemes);
  713. return(0);
  714. }
  715. }
  716. }
  717. if((end_type != 0) && !(end_type & SUFX_P))
  718. {
  719. char phonemes2[N_WORD_PHONEMES];
  720. strcpy(phonemes2,phonemes);
  721. // The word has a standard ending, re-translate without this ending
  722. end_flags = RemoveEnding(word,end_type,word_copy);
  723. phonemes_ptr = &phonemes[unpron_length];
  724. phonemes_ptr[0] = 0;
  725. if(prefix_phonemes[0] != 0)
  726. {
  727. // lookup the stem without the prefix removed
  728. word[-1] = c_temp;
  729. found = LookupDictList(word1,phonemes_ptr,&dictionary_flags2,end_flags | (wflags << 16));
  730. word[-1] = ' ';
  731. if(dictionary_flags==0)
  732. dictionary_flags = dictionary_flags2;
  733. if(found)
  734. prefix_phonemes[0] = 0; // matched whole word, don't need prefix now
  735. // if(found || (dictionary_flags2 != 0))
  736. // prefix_flags = 1; // ?? this looks wrong
  737. if((found==0) && (dictionary_flags2 != 0))
  738. prefix_flags = 1;
  739. }
  740. if(found == 0)
  741. {
  742. found = LookupDictList(word,phonemes_ptr,&dictionary_flags2,end_flags | (wflags << 16));
  743. if(phonemes_ptr[0] == phonSWITCH)
  744. {
  745. // change to another language in order to translate this word
  746. memcpy(word,word_copy,strlen(word_copy));
  747. strcpy(word_phonemes,phonemes_ptr);
  748. return(0);
  749. }
  750. if(dictionary_flags==0)
  751. dictionary_flags = dictionary_flags2;
  752. }
  753. if(found == 0)
  754. {
  755. if(end_type & SUFX_Q)
  756. {
  757. // don't retranslate, use the original lookup result
  758. strcpy(phonemes,phonemes2);
  759. // language specific changes
  760. ApplySpecialAttribute(phonemes,dictionary_flags);
  761. }
  762. else
  763. {
  764. if(end_flags & FLAG_SUFX)
  765. TranslateRules(word, phonemes, N_WORD_PHONEMES, NULL,wflags | FLAG_SUFFIX_REMOVED, dictionary_flags);
  766. else
  767. TranslateRules(word, phonemes, N_WORD_PHONEMES, NULL,wflags,dictionary_flags);
  768. if(phonemes[0] == phonSWITCH)
  769. {
  770. // change to another language in order to translate this word
  771. strcpy(word_phonemes,phonemes);
  772. memcpy(word,word_copy,strlen(word_copy));
  773. word[-1] = c_temp;
  774. return(0);
  775. }
  776. }
  777. }
  778. if((end_type & SUFX_T) == 0)
  779. {
  780. // the default is to add the suffix and then determine the word's stress pattern
  781. AppendPhonemes(phonemes, N_WORD_PHONEMES, end_phonemes);
  782. end_phonemes[0] = 0;
  783. }
  784. }
  785. word[-1] = c_temp;
  786. }
  787. }
  788. if((add_plural_suffix) || (wflags & FLAG_HAS_PLURAL))
  789. {
  790. // s or 's suffix, append [s], [z] or [Iz] depending on previous letter
  791. if(last_char == 'f')
  792. TranslateRules(&word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  793. else
  794. if(strchr_w("hsx",last_char)==NULL)
  795. TranslateRules(&word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  796. else
  797. TranslateRules(&word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  798. }
  799. /* determine stress pattern for this word */
  800. /******************************************/
  801. /* NOTE: this also adds a single PAUSE if the previous word ended
  802. in a primary stress, and this one starts with one */
  803. if(prefix_flags || (strchr(prefix_phonemes,phonSTRESS_P)!=NULL))
  804. {
  805. if((langopts.param[LOPT_PREFIXES]) || (prefix_type & SUFX_T))
  806. {
  807. char *p;
  808. // German, keep a secondary stress on the stem
  809. SetWordStress(phonemes,dictionary_flags,3,0);
  810. // reduce all but the first primary stress
  811. ix=0;
  812. for(p=prefix_phonemes; *p != 0; p++)
  813. {
  814. if(*p == phonSTRESS_P)
  815. {
  816. if(ix==0)
  817. ix=1;
  818. else
  819. *p = phonSTRESS_3;
  820. }
  821. }
  822. strcpy(word_phonemes,prefix_phonemes);
  823. strcat(word_phonemes,phonemes);
  824. SetWordStress(word_phonemes,dictionary_flags,-1,0);
  825. }
  826. else
  827. {
  828. // stress position affects the whole word, including prefix
  829. strcpy(word_phonemes,prefix_phonemes);
  830. strcat(word_phonemes,phonemes);
  831. SetWordStress(word_phonemes,dictionary_flags,-1,prev_last_stress);
  832. }
  833. }
  834. else
  835. {
  836. if(prefix_phonemes[0] == 0)
  837. SetWordStress(phonemes,dictionary_flags,-1,prev_last_stress);
  838. else
  839. SetWordStress(phonemes,dictionary_flags,-1,0);
  840. strcpy(word_phonemes,prefix_phonemes);
  841. strcat(word_phonemes,phonemes);
  842. }
  843. if(end_phonemes[0] != 0)
  844. {
  845. // a suffix had the SUFX_T option set, add the suffix after the stress pattern has been determined
  846. strcat(word_phonemes,end_phonemes);
  847. }
  848. // if(next_pause > 2)
  849. ix = ((dictionary_flags >> 5) & 7); // dictionary indicates skip next word(s)
  850. if(wtab[ix].flags & FLAG_LAST_WORD)
  851. {
  852. // the word has attribute to stress or unstress when at end of clause
  853. if(dictionary_flags & (FLAG_STRESS_END | FLAG_STRESS_END2))
  854. ChangeWordStress(this,word_phonemes,4);
  855. // SetWordStress(word_phonemes,0,4,prev_last_stress);
  856. else
  857. if(dictionary_flags & FLAG_UNSTRESS_END)
  858. ChangeWordStress(this,word_phonemes,3);
  859. // SetWordStress(word_phonemes,0,3,prev_last_stress);
  860. }
  861. if(wflags & FLAG_STRESSED_WORD)
  862. {
  863. // A word is indicated in the source text as stressed
  864. // we need to improve the intonation module to deal better with a clauses tonic
  865. // stress being early in the clause, before enabling this
  866. //SetWordStress(word_phonemes,0,5,prev_last_stress);
  867. }
  868. // dictionary flags for this word give a clue about which alternative pronunciations of
  869. // following words to use.
  870. if(end_type & SUFX_F)
  871. {
  872. // expect a verb form, with or without -s suffix
  873. expect_verb = 2;
  874. expect_verb_s = 2;
  875. }
  876. if(dictionary_flags & FLAG_PASTF)
  877. {
  878. /* expect perfect tense in next two words */
  879. expect_past = 3;
  880. expect_verb = 0;
  881. }
  882. else
  883. if(dictionary_flags & FLAG_VERBF)
  884. {
  885. /* expect a verb in the next word */
  886. expect_verb = 2;
  887. expect_verb_s = 0; /* verb won't have -s suffix */
  888. }
  889. else
  890. if(dictionary_flags & FLAG_VERBSF)
  891. {
  892. // expect a verb, must have a -s suffix
  893. expect_verb = 0;
  894. expect_verb_s = 2;
  895. expect_past = 0;
  896. }
  897. else
  898. if(dictionary_flags & FLAG_NOUNF)
  899. {
  900. /* not expecting a verb next */
  901. expect_verb = 0;
  902. expect_verb_s = 0;
  903. expect_past = 0;
  904. }
  905. if((word[0] != 0) && (!(dictionary_flags & FLAG_VERB_EXT)))
  906. {
  907. if(expect_verb > 0)
  908. expect_verb -= 1;
  909. if(expect_verb_s > 0)
  910. expect_verb_s -= 1;
  911. if(expect_past > 0)
  912. expect_past -= 1;
  913. }
  914. if((word_length == 1) && iswalpha(first_char) && (first_char != 'i'))
  915. {
  916. // English Specific !!!!
  917. // any single letter before a dot is an abbreviation, except 'I'
  918. dictionary_flags |= FLAG_DOT;
  919. }
  920. return(dictionary_flags);
  921. } // end of TranslateWord
  922. static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode)
  923. {//==========================================================
  924. p->phcode = phcode;
  925. p->stress = 0;
  926. p->tone_number = 0;
  927. p->synthflags = 0;
  928. p->sourceix = 0;
  929. }
  930. static int CountSyllables(unsigned char *phonemes)
  931. {//===============================================
  932. int count = 0;
  933. int phon;
  934. while((phon = *phonemes++) != 0)
  935. {
  936. if(phoneme_tab[phon]->type == phVOWEL)
  937. count++;
  938. }
  939. return(count);
  940. }
  941. int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int next_pause)
  942. {//======================================================================================
  943. int flags=0;
  944. int stress;
  945. int next_stress;
  946. int next_tone=0;
  947. unsigned char *p;
  948. int srcix;
  949. int embedded_flag=0;
  950. int embedded_cmd;
  951. int value;
  952. int found_dict_flag;
  953. unsigned char ph_code;
  954. PHONEME_LIST2 *plist2;
  955. PHONEME_TAB *ph;
  956. int max_stress;
  957. int max_stress_ix=0;
  958. int prev_vowel = -1;
  959. int pitch_raised = 0;
  960. int switch_phonemes = -1;
  961. int first_phoneme = 1;
  962. int source_ix;
  963. int len;
  964. int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
  965. char *new_language;
  966. unsigned char bad_phoneme[4];
  967. len = wtab->length;
  968. if(len > 31) len = 31;
  969. source_ix = (wtab->sourceix & 0x7ff) | (len << 11); // bits 0-10 sourceix, bits 11-15 word length
  970. word_flags = wtab[0].flags;
  971. if(word_flags & FLAG_EMBEDDED)
  972. {
  973. embedded_flag = SFLAG_EMBEDDED;
  974. value = embedded_list[embedded_read] >> 8;
  975. switch(embedded_cmd = embedded_list[embedded_read] & 0x1f)
  976. {
  977. case EMBED_Y:
  978. option_sayas = value;
  979. break;
  980. case EMBED_F:
  981. option_emphasis = value;
  982. break;
  983. case EMBED_B:
  984. // break command
  985. if(value == 0)
  986. pre_pause = 0; // break=none
  987. else
  988. pre_pause += value;
  989. break;
  990. }
  991. while((embedded_list[embedded_read++] & 0x80) == 0); // read over the embedded commands for this word
  992. }
  993. if(word[0] == 0)
  994. {
  995. // nothing to translate
  996. word_phonemes[0] = 0;
  997. return(0);
  998. }
  999. // after a $pause word attribute, ignore a $pause attribute on the next two words
  1000. if(prepause_timeout > 0)
  1001. prepause_timeout--;
  1002. if((option_sayas & 0xf0) == 0x10)
  1003. {
  1004. // SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
  1005. pre_pause += 4;
  1006. }
  1007. if(word_flags & FLAG_FIRST_UPPER)
  1008. {
  1009. if((option_capitals > 2) && (embedded_ix < N_EMBEDDED_LIST-6))
  1010. {
  1011. // indicate capital letter by raising pitch
  1012. if(embedded_flag)
  1013. embedded_list[embedded_ix-1] &= ~0x80; // already embedded command before this word, remove terminator
  1014. if((pitch_raised = option_capitals) == 3)
  1015. pitch_raised = 20; // default pitch raise for capitals
  1016. embedded_list[embedded_ix++] = EMBED_P+0x40+0x80 + (pitch_raised << 8); // raise pitch
  1017. embedded_flag = SFLAG_EMBEDDED;
  1018. }
  1019. }
  1020. p = (unsigned char *)translator->word_phonemes;
  1021. if(word_flags & FLAG_PHONEMES)
  1022. {
  1023. // The input is in phoneme mnemonics, not language text
  1024. EncodePhonemes(word,word_phonemes,bad_phoneme);
  1025. flags = FLAG_FOUND;
  1026. }
  1027. else
  1028. {
  1029. flags = translator->TranslateWord(word, next_pause, wtab);
  1030. if((flags & FLAG_ALT2_TRANS) && ((sylimit = langopts.param[LOPT_COMBINE_WORDS]) > 0))
  1031. {
  1032. char *p2;
  1033. int ok = 1;
  1034. int flags2;
  1035. int c_word2;
  1036. char ph_buf[N_WORD_PHONEMES];
  1037. // LANG=cs,sk
  1038. // combine a preposition with the following word
  1039. p2 = word;
  1040. while(*p2 != ' ') p2++;
  1041. utf8_in(&c_word2, p2+1, 0); // first character of the next word;
  1042. if(!iswalpha(c_word2))
  1043. {
  1044. ok =0;
  1045. }
  1046. if(sylimit & 0x100)
  1047. {
  1048. // only if the second word has $alt attribute
  1049. strcpy(ph_buf,word_phonemes);
  1050. flags2 = translator->TranslateWord(p2+1, 0, wtab+1);
  1051. if((flags2 & FLAG_ALT_TRANS) == 0)
  1052. {
  1053. ok = 0;
  1054. strcpy(word_phonemes,ph_buf);
  1055. }
  1056. }
  1057. if((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD))
  1058. {
  1059. // not if the next word is end-of-sentence
  1060. ok = 0;
  1061. }
  1062. if(ok)
  1063. {
  1064. *p2 = '-'; // replace next space by hyphen
  1065. flags = translator->TranslateWord(word, next_pause, wtab); // translate the combined word
  1066. if(CountSyllables(p) > (sylimit & 0xf))
  1067. {
  1068. // revert to separate words
  1069. *p2 = ' ';
  1070. flags = translator->TranslateWord(word, next_pause, wtab);
  1071. }
  1072. else
  1073. {
  1074. flags |= FLAG_SKIPWORDS_1;
  1075. }
  1076. }
  1077. }
  1078. if(p[0] == phonSWITCH)
  1079. {
  1080. // this word uses a different language
  1081. new_language = (char *)(&p[1]);
  1082. if(new_language[0]==0)
  1083. new_language = "en";
  1084. if((switch_phonemes = SelectPhonemeTableName(new_language)) >= 0)
  1085. {
  1086. if((translator2 != NULL) && (strcmp(new_language,translator2_language) != 0))
  1087. {
  1088. // we already have an alternative translator, but not for the required language, delete it
  1089. delete translator2;
  1090. translator2 = NULL;
  1091. }
  1092. if(translator2 == NULL)
  1093. {
  1094. translator2 = SelectTranslator(new_language);
  1095. strcpy(translator2_language,new_language);
  1096. if(translator2->LoadDictionary(new_language,0) != 0)
  1097. {
  1098. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  1099. switch_phonemes = -1;
  1100. translator2_language[0] = 0;
  1101. }
  1102. }
  1103. }
  1104. if(switch_phonemes >= 0)
  1105. {
  1106. // re-translate the word using the new translator
  1107. flags = translator2->TranslateWord(word, next_pause, wtab);
  1108. strcpy((char *)p,translator2->word_phonemes);
  1109. if(p[0] == phonSWITCH)
  1110. {
  1111. // the second translator doesn't want to process this word
  1112. switch_phonemes = -1;
  1113. }
  1114. }
  1115. if(switch_phonemes < 0)
  1116. {
  1117. // language code is not recognised or 2nd translator won't translate it
  1118. p[0] = phonSCHWA; // just say something
  1119. p[1] = phonSCHWA;
  1120. p[2] = 0;
  1121. }
  1122. }
  1123. if(!(word_flags & FLAG_LAST_WORD) && !(word_flags & FLAG_HYPHEN))
  1124. {
  1125. if(flags & FLAG_PAUSE1)
  1126. {
  1127. if(pre_pause < 1)
  1128. pre_pause = 1;
  1129. }
  1130. if((flags & FLAG_PREPAUSE) && (prepause_timeout == 0))
  1131. {
  1132. // the word is marked in the dictionary list with $pause
  1133. if(pre_pause < 4) pre_pause = 4;
  1134. prepause_timeout = 3;
  1135. }
  1136. }
  1137. if((option_emphasis >= 3) && (pre_pause < 2))
  1138. pre_pause = 2;
  1139. }
  1140. plist2 = &ph_list2[n_ph_list2];
  1141. stress = 0;
  1142. next_stress = 0;
  1143. srcix = 0;
  1144. max_stress = -1;
  1145. found_dict_flag = 0;
  1146. if(flags & FLAG_FOUND)
  1147. found_dict_flag = SFLAG_DICTIONARY;
  1148. while((pre_pause > 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1149. {
  1150. // add pause phonemes here. Either because of punctuation (brackets or quotes) in the
  1151. // text, or because the word is marked in the dictionary lookup as a conjunction
  1152. if(pre_pause > 1)
  1153. {
  1154. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE);
  1155. pre_pause -= 2;
  1156. }
  1157. else
  1158. {
  1159. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_NOLINK);
  1160. pre_pause--;
  1161. }
  1162. end_stressed_vowel = 0; // forget about the previous word
  1163. prev_dict_flags = 0;
  1164. }
  1165. if((option_capitals==1) && (word_flags & FLAG_FIRST_UPPER))
  1166. {
  1167. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1168. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1169. if((word_flags & FLAG_ALL_UPPER) && IsAlpha(word[1]))
  1170. {
  1171. // word > 1 letter and all capitals
  1172. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1173. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1174. }
  1175. }
  1176. if(switch_phonemes >= 0)
  1177. {
  1178. // this word uses a different phoneme table
  1179. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1180. ph_list2[n_ph_list2++].tone_number = switch_phonemes; // temporary phoneme table number
  1181. }
  1182. // remove initial pause from a word if it follows a hyphen
  1183. if((word_flags & FLAG_HYPHEN) && (phoneme_tab[*p]->type == phPAUSE))
  1184. p++;
  1185. while(((ph_code = *p++) != 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1186. {
  1187. if(ph_code == 255)
  1188. continue; // unknown phoneme
  1189. // Add the phonemes to the first stage phoneme list (ph_list2)
  1190. ph = phoneme_tab[ph_code];
  1191. if(ph->type == phSTRESS)
  1192. {
  1193. // don't add stress phonemes codes to the list, but give their stress
  1194. // value to the next vowel phoneme
  1195. // std_length is used to hold stress number or (if >10) a tone number for a tone language
  1196. if(ph->spect == 0)
  1197. next_stress = ph->std_length;
  1198. else
  1199. {
  1200. // for tone languages, the tone number for a syllable follows the vowel
  1201. if(prev_vowel >= 0)
  1202. {
  1203. ph_list2[prev_vowel].tone_number = ph_code;
  1204. }
  1205. else
  1206. {
  1207. next_tone = ph_code; // no previous vowel, apply to the next vowel
  1208. }
  1209. }
  1210. }
  1211. else
  1212. if(ph_code == phonSYLLABIC)
  1213. {
  1214. // mark the previous phoneme as a syllabic consonant
  1215. ph_list2[n_ph_list2-1].synthflags |= SFLAG_SYLLABLE;
  1216. ph_list2[n_ph_list2-1].stress = next_stress;
  1217. }
  1218. else
  1219. if(ph_code == phonLENGTHEN)
  1220. {
  1221. ph_list2[n_ph_list2-1].synthflags |= SFLAG_LENGTHEN;
  1222. }
  1223. else
  1224. if(ph_code == phonEND_WORD)
  1225. {
  1226. // a || symbol in a phoneme string was used to indicate a word boundary
  1227. // Don't add this phoneme to the list, but make sure the next phoneme has
  1228. // a newword indication
  1229. srcix = source_ix+1;
  1230. }
  1231. else
  1232. if(ph_code == phonX1)
  1233. {
  1234. // a language specific action
  1235. if(langopts.param[LOPT_IT_DOUBLING])
  1236. {
  1237. flags |= FLAG_DOUBLING;
  1238. }
  1239. }
  1240. else
  1241. {
  1242. ph_list2[n_ph_list2].phcode = ph_code;
  1243. ph_list2[n_ph_list2].tone_number = 0;
  1244. ph_list2[n_ph_list2].synthflags = embedded_flag | found_dict_flag;
  1245. embedded_flag = 0;
  1246. ph_list2[n_ph_list2].sourceix = srcix;
  1247. srcix = 0;
  1248. if(ph->type == phVOWEL)
  1249. {
  1250. stress = next_stress;
  1251. next_stress = 0;
  1252. if((prev_vowel >= 0) && (n_ph_list2-1) != prev_vowel)
  1253. ph_list2[n_ph_list2-1].stress = stress; // set stress for previous consonant
  1254. ph_list2[n_ph_list2].synthflags |= SFLAG_SYLLABLE;
  1255. prev_vowel = n_ph_list2;
  1256. if(stress > max_stress)
  1257. {
  1258. max_stress = stress;
  1259. max_stress_ix = n_ph_list2;
  1260. }
  1261. if(next_tone != 0)
  1262. {
  1263. ph_list2[n_ph_list2].tone_number = next_tone;
  1264. next_tone=0;
  1265. }
  1266. }
  1267. else
  1268. {
  1269. if(first_phoneme && langopts.param[LOPT_IT_DOUBLING])
  1270. {
  1271. if(((prev_dict_flags & FLAG_DOUBLING) && (langopts.param[LOPT_IT_DOUBLING] & 1)) ||
  1272. (end_stressed_vowel && (langopts.param[LOPT_IT_DOUBLING] & 2)))
  1273. {
  1274. // italian, double the initial consonant if the previous word ends with a
  1275. // stressed vowel, or is marked with a flag
  1276. ph_list2[n_ph_list2].synthflags |= SFLAG_LENGTHEN;
  1277. }
  1278. }
  1279. }
  1280. ph_list2[n_ph_list2].stress = stress;
  1281. n_ph_list2++;
  1282. first_phoneme = 0;
  1283. }
  1284. }
  1285. plist2->sourceix = source_ix; // ????
  1286. end_stressed_vowel = 0;
  1287. if((stress >= 4) && (phoneme_tab[ph_list2[n_ph_list2-1].phcode]->type == phVOWEL))
  1288. {
  1289. end_stressed_vowel = 1; // word ends with a stressed vowel
  1290. }
  1291. if(switch_phonemes >= 0)
  1292. {
  1293. // this word uses a different phoneme table, now switch back
  1294. SelectPhonemeTable(voice->phoneme_tab_ix);
  1295. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1296. ph_list2[n_ph_list2++].tone_number = voice->phoneme_tab_ix; // original phoneme table number
  1297. }
  1298. if(pitch_raised > 0)
  1299. {
  1300. embedded_list[embedded_ix++] = EMBED_P+0x60+0x80 + (pitch_raised << 8); // lower pitch
  1301. SetPlist2(&ph_list2[n_ph_list2],phonPAUSE_SHORT);
  1302. ph_list2[n_ph_list2++].synthflags = SFLAG_EMBEDDED;
  1303. }
  1304. if(flags & FLAG_STRESS_END2)
  1305. {
  1306. // this's word's stress could be increased later
  1307. ph_list2[max_stress_ix].stress |= 0x80;
  1308. }
  1309. prev_dict_flags = flags;
  1310. return(flags);
  1311. } // end of TranslateWord2
  1312. static int EmbeddedCommand(unsigned int &source_index)
  1313. {//===================================================
  1314. // An embedded command to change the pitch, volume, etc.
  1315. // returns number of commands added to embedded_list
  1316. // pitch,speed,amplitude,expression,reverb,tone,voice,sayas
  1317. const char *commands = "PSARHTIVYMUBF";
  1318. int value = -1;
  1319. int sign = 0;
  1320. unsigned char c;
  1321. char *p;
  1322. int cmd;
  1323. c = source[source_index];
  1324. if(c == '+')
  1325. {
  1326. sign = 0x40;
  1327. source_index++;
  1328. }
  1329. else
  1330. if(c == '-')
  1331. {
  1332. sign = 0x60;
  1333. source_index++;
  1334. }
  1335. if(isdigit(source[source_index]))
  1336. {
  1337. value = atoi(&source[source_index]);
  1338. while(isdigit(source[source_index]))
  1339. source_index++;
  1340. }
  1341. c = source[source_index++];
  1342. if(embedded_ix >= (N_EMBEDDED_LIST - 2))
  1343. return(0); // list is full
  1344. if((p = strchr_w(commands,c)) == NULL)
  1345. return(0);
  1346. cmd = (p - commands)+1;
  1347. if(value == -1)
  1348. {
  1349. value = embedded_default[cmd];
  1350. sign = 0;
  1351. }
  1352. if(cmd == EMBED_Y)
  1353. {
  1354. option_sayas2 = value;
  1355. count_sayas_digits = 0;
  1356. }
  1357. embedded_list[embedded_ix++] = cmd + sign + (value << 8);
  1358. return(1);
  1359. } // end of EmbeddedCommand
  1360. int Translator::TranslateChar(char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert)
  1361. {//=====================================================================================================
  1362. // To allow language specific examination and replacement of characters
  1363. int ix;
  1364. unsigned int word;
  1365. unsigned int new_c, c2;
  1366. int upper_case = 0;
  1367. static int ignore_next = 0;
  1368. if(ignore_next)
  1369. {
  1370. ignore_next = 0;
  1371. return(8);
  1372. }
  1373. if(c == 0) return(0);
  1374. if(langopts.replace_chars == NULL)
  1375. return(c);
  1376. // there is a list of character codes to be substituted with alternative codes
  1377. if(iswupper(c))
  1378. {
  1379. c = towlower(c);
  1380. upper_case = 1;
  1381. }
  1382. new_c = 0;
  1383. for(ix=0; (word = langopts.replace_chars[ix]) != 0; ix++)
  1384. {
  1385. if(c == (word & 0xffff))
  1386. {
  1387. if((word >> 16) == 0)
  1388. {
  1389. new_c = langopts.replacement_chars[ix];
  1390. break;
  1391. }
  1392. if((word >> 16) == (unsigned int)tolower(next_in))
  1393. {
  1394. new_c = langopts.replacement_chars[ix];
  1395. ignore_next = 1;
  1396. break;
  1397. }
  1398. }
  1399. }
  1400. if(new_c == 0)
  1401. return(c); // no substitution
  1402. if(new_c & 0xffe00000)
  1403. {
  1404. // there is a second character to be inserted
  1405. // don't convert the case of the second character unless the next letter is also upper case
  1406. c2 = new_c >> 16;
  1407. if(upper_case && iswupper(next_in))
  1408. c2 = towupper(c2);
  1409. *insert = c2;
  1410. new_c &= 0xffff;
  1411. }
  1412. if(upper_case)
  1413. new_c = towupper(new_c);
  1414. return(new_c);
  1415. }
  1416. void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_out, char **voice_change)
  1417. {//======================================================================================================
  1418. int ix;
  1419. int c;
  1420. int cc;
  1421. unsigned int source_index=0;
  1422. unsigned int prev_source_index=0;
  1423. int prev_in;
  1424. int prev_out=' ';
  1425. int prev_out2;
  1426. int prev_in2=0;
  1427. int next_in;
  1428. int char_inserted=0;
  1429. int clause_pause;
  1430. int pre_pause=0;
  1431. int pre_pause_add=0;
  1432. int word_mark = 0;
  1433. int all_upper_case=FLAG_ALL_UPPER;
  1434. int finished;
  1435. int single_quoted;
  1436. int phoneme_mode = 0;
  1437. int dict_flags; // returned from dictionary lookup
  1438. int word_flags; // set here
  1439. int next_word_flags;
  1440. int embedded_count = 0;
  1441. int letter_count = 0;
  1442. char *word;
  1443. char *p;
  1444. int j, k;
  1445. int n_digits;
  1446. unsigned short charix[N_TR_SOURCE+1];
  1447. WORD_TAB words[N_CLAUSE_WORDS];
  1448. int word_count=0; // index into words
  1449. char sbuf[512];
  1450. int terminator;
  1451. int tone;
  1452. p_textinput = (char *)vp_input;
  1453. p_wchar_input = (wchar_t *)vp_input;
  1454. embedded_ix = 0;
  1455. embedded_read = 0;
  1456. if((clause_start_char = count_characters) < 0)
  1457. clause_start_char = 0;
  1458. clause_start_word = count_words + 1;
  1459. for(ix=0; ix<N_TR_SOURCE; ix++)
  1460. charix[ix] = 0;
  1461. terminator = translator->ReadClause(f_text,source,charix,N_TR_SOURCE);
  1462. charix[N_TR_SOURCE] = count_characters;
  1463. clause_pause = (terminator & 0xff) * 10; // mS
  1464. tone = (terminator & 0xf00) >> 8;
  1465. for(p=source; *p != 0; p++)
  1466. {
  1467. if(!isspace2(*p))
  1468. {
  1469. break;
  1470. }
  1471. }
  1472. if(*p == 0)
  1473. {
  1474. // No characters except spaces. This is not a sentence.
  1475. // Don't add this pause, just make up the previous pause to this value;
  1476. clause_pause -= max_clause_pause;
  1477. if(clause_pause < 0)
  1478. clause_pause = 0;
  1479. terminator &= ~CLAUSE_BIT_SENTENCE; // clear sentence bit
  1480. max_clause_pause += clause_pause;
  1481. }
  1482. else
  1483. {
  1484. max_clause_pause = clause_pause;
  1485. }
  1486. if(new_sentence)
  1487. {
  1488. count_sentences++;
  1489. if(skip_sentences > 0)
  1490. {
  1491. skip_sentences--;
  1492. if(skip_sentences == 0)
  1493. skipping_text = 0;
  1494. }
  1495. }
  1496. ph_list2[0].phcode = phonPAUSE_SHORT;
  1497. ph_list2[0].stress = 0;
  1498. ph_list2[0].tone_number = 0;
  1499. ph_list2[0].sourceix = 0;
  1500. n_ph_list2 = 1;
  1501. prev_last_stress = 0;
  1502. prepause_timeout = 0;
  1503. word_count = 0;
  1504. single_quoted = 0;
  1505. word_flags = 0;
  1506. next_word_flags = 0;
  1507. expect_verb=0;
  1508. expect_past=0;
  1509. expect_verb_s=0;
  1510. end_stressed_vowel=0;
  1511. prev_dict_flags = 0;
  1512. sbuf[0] = 0;
  1513. sbuf[1] = ' ';
  1514. sbuf[2] = ' ';
  1515. ix = 3;
  1516. prev_in = ' ';
  1517. words[0].start = ix;
  1518. words[0].flags = 0;
  1519. finished = 0;
  1520. for(j=0; charix[j]==0; j++);
  1521. words[0].sourceix = charix[j];
  1522. for(k=j; charix[k]!=0; k++);
  1523. words[0].length = k-j;
  1524. while(!finished && (ix < (int)sizeof(sbuf))&& (n_ph_list2 < N_PHONEME_LIST-4))
  1525. {
  1526. prev_out2 = prev_out;
  1527. utf8_in(&prev_out,&sbuf[ix-1],1); // prev_out = sbuf[ix-1];
  1528. if(prev_in2 != 0)
  1529. {
  1530. prev_in = prev_in2;
  1531. prev_in2 = 0;
  1532. }
  1533. else
  1534. if(source_index > 0)
  1535. {
  1536. utf8_in(&prev_in,&source[source_index-1],1); // prev_in = source[source_index-1];
  1537. }
  1538. if(prev_source_index == source_index)
  1539. char_inserted = 0; // have done an unget, so discard any character to be inserted
  1540. prev_source_index = source_index;
  1541. if(char_inserted)
  1542. {
  1543. c = char_inserted;
  1544. char_inserted = 0;
  1545. }
  1546. else
  1547. {
  1548. source_index += utf8_in(&cc,&source[source_index],0); // cc = source[source_index++];
  1549. c = cc;
  1550. }
  1551. utf8_in(&next_in,&source[source_index],0);
  1552. if((c == CTRL_EMBEDDED) || (c == ctrl_embedded))
  1553. {
  1554. // start of embedded command in the text
  1555. int srcix = source_index-1;
  1556. if(prev_in != ' ')
  1557. {
  1558. c = ' ';
  1559. prev_in2 = c;
  1560. source_index--;
  1561. }
  1562. else
  1563. {
  1564. embedded_count += EmbeddedCommand(source_index);
  1565. prev_in2 = prev_in;
  1566. // replace the embedded command by spaces
  1567. memset(&source[srcix],' ',source_index-srcix);
  1568. source_index = srcix;
  1569. continue;
  1570. }
  1571. }
  1572. if(phoneme_mode)
  1573. {
  1574. all_upper_case = FLAG_PHONEMES;
  1575. if((c == ']') && (next_in == ']'))
  1576. {
  1577. phoneme_mode = 0;
  1578. source_index++;
  1579. c = ' ';
  1580. }
  1581. }
  1582. else
  1583. if((option_sayas2 & 0xf0) == SAYAS_DIGITS)
  1584. {
  1585. if(iswdigit(c))
  1586. {
  1587. count_sayas_digits++;
  1588. if(count_sayas_digits > (option_sayas2 & 0xf))
  1589. {
  1590. // break after the specified number of digits
  1591. c = ' ';
  1592. source_index = prev_source_index; // unget
  1593. count_sayas_digits = 0;
  1594. }
  1595. }
  1596. else
  1597. {
  1598. count_sayas_digits = 0;
  1599. if(iswdigit(prev_out))
  1600. {
  1601. c = ' ';
  1602. source_index = prev_source_index; // unget
  1603. }
  1604. }
  1605. }
  1606. else
  1607. if((option_sayas2 & 0xf0) != 0x10)
  1608. {
  1609. if((c == '/') && (langopts.testing & 2) && isdigit(next_in) && IsAlpha(prev_out))
  1610. {
  1611. // TESTING, explicit indication of stressed syllable by /2 after the word
  1612. word_mark = next_in-'0';
  1613. source_index++;
  1614. c = ' ';
  1615. }
  1616. if((c == 0x92) || (c == 0xb4) || (c == 0x2019))
  1617. c = '\''; // 'microsoft' quote or sexed closing single quote - possibly used as apostrophe
  1618. if((c == '?') && IsAlpha(prev_out) && IsAlpha(next_in))
  1619. {
  1620. // ? between two letters may be a smart-quote replaced by ?
  1621. c = '\'';
  1622. }
  1623. c = TranslateChar(&source[source_index], prev_in,c, next_in, &char_inserted); // optional language specific function
  1624. if(c == 8)
  1625. continue; // ignore this character
  1626. if(char_inserted)
  1627. next_in = char_inserted;
  1628. if(!IsAlpha(c) && !iswspace(c) && (c != '\''))
  1629. {
  1630. if(IsAlpha(prev_out))
  1631. {
  1632. if(langopts.tone_numbers && isdigit(c) && !isdigit(next_in))
  1633. {
  1634. // allow a tone number as part of the word
  1635. }
  1636. else
  1637. {
  1638. c = ' '; // ensure we have an end-of-word terminator
  1639. source_index = prev_source_index;
  1640. }
  1641. }
  1642. }
  1643. if(iswdigit(prev_out))
  1644. {
  1645. if(!iswdigit(c) && (c != '.') && (c != ','))
  1646. {
  1647. c = ' '; // terminate digit string with a space
  1648. source_index = prev_source_index;
  1649. }
  1650. }
  1651. if((c == '[') && (next_in == '[') && option_phoneme_input)
  1652. {
  1653. phoneme_mode = FLAG_PHONEMES;
  1654. source_index++;
  1655. continue;
  1656. }
  1657. if(c == 0)
  1658. {
  1659. finished = 1;
  1660. c = ' ';
  1661. }
  1662. else
  1663. if(IsAlpha(c))
  1664. {
  1665. if(!IsAlpha(prev_out) || (langopts.ideographs && (c >= 0x3000)))
  1666. {
  1667. if(prev_out != '\'')
  1668. letter_count = 0; // don't reset count for an apostrophy within a word
  1669. if((prev_out != ' ') && (prev_out != '\''))
  1670. {
  1671. // start of word, insert space if not one there already
  1672. c = ' ';
  1673. source_index = prev_source_index; // unget
  1674. }
  1675. else
  1676. {
  1677. if(iswupper(c))
  1678. word_flags |= FLAG_FIRST_UPPER;
  1679. if((prev_out == ' ') && iswdigit(sbuf[ix-2]) && !iswdigit(prev_in))
  1680. {
  1681. // word, following a number, but with a space between
  1682. // Add an extra space, to distinguish "2 a" from "2a"
  1683. sbuf[ix++] = ' ';
  1684. words[word_count].start++;
  1685. }
  1686. }
  1687. }
  1688. letter_count++;
  1689. if(iswupper(c))
  1690. {
  1691. c = towlower(c);
  1692. if(iswlower(prev_in))
  1693. {
  1694. c = ' '; // lower case followed by upper case, treat as new word
  1695. prev_in2 = c;
  1696. source_index = prev_source_index; // unget
  1697. }
  1698. //#ifdef deleted
  1699. // changed to break after the last uppercase letter, not before. See below
  1700. else
  1701. if((c != ' ') && iswupper(prev_in) && iswlower(next_in) &&
  1702. (memcmp(&source[source_index],"s ",2) != 0)) // ENGLISH specific plural
  1703. {
  1704. c = ' '; // change from upper to lower case, start new word at the last uppercase
  1705. prev_in2 = c;
  1706. source_index = prev_source_index; // unget
  1707. next_word_flags |= FLAG_NOSPACE;
  1708. }
  1709. //#endif
  1710. }
  1711. else
  1712. {
  1713. #ifdef deleted
  1714. if(iswupper(prev_in) && iswalpha(prev_out2) &&
  1715. (memcmp(&source[source_index-1],"s ",2) != 0)) // ENGLISH specific plural
  1716. {
  1717. // change to break after the last uppercase letter, not before.
  1718. c = ' '; // more than one upper case followed by lower case, treat as new word
  1719. prev_in2 = c;
  1720. source_index = prev_source_index; // unget
  1721. }
  1722. #endif
  1723. if((all_upper_case) && (letter_count > 2))
  1724. {
  1725. if((c == 's') && (next_in==' '))
  1726. {
  1727. c = ' ';
  1728. all_upper_case |= FLAG_HAS_PLURAL;
  1729. if(sbuf[ix-1] == '\'')
  1730. sbuf[ix-1] = ' ';
  1731. }
  1732. else
  1733. all_upper_case = 0; // current word contains lower case letters, not "'s"
  1734. }
  1735. else
  1736. all_upper_case = 0;
  1737. }
  1738. }
  1739. else
  1740. if(c=='-')
  1741. {
  1742. if(IsAlpha(prev_in) && IsAlpha(next_in))
  1743. {
  1744. // '-' between two letters is a hyphen, treat as a space
  1745. word_flags |= FLAG_HYPHEN;
  1746. words[word_count-1].flags |= FLAG_HYPHEN_AFTER;
  1747. c = ' ';
  1748. }
  1749. else
  1750. if((prev_in==' ') && (next_in==' '))
  1751. {
  1752. // ' - ' dash between two spaces, treat as pause
  1753. c = ' ';
  1754. pre_pause_add = 4;
  1755. }
  1756. else
  1757. if(next_in=='-')
  1758. {
  1759. // double hyphen, treat as pause
  1760. source_index++;
  1761. c = ' ';
  1762. pre_pause_add = 4;
  1763. }
  1764. else
  1765. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1766. {
  1767. // insert extra space between a word + space + hyphen, to distinguish 'a -2' from 'a-2'
  1768. sbuf[ix++] = ' ';
  1769. words[word_count].start++;
  1770. }
  1771. }
  1772. else
  1773. if(c == '\'')
  1774. {
  1775. if(iswalnum(prev_in) && IsAlpha(next_in))
  1776. {
  1777. // between two letters, consider apostrophe as part of the word
  1778. single_quoted = 0;
  1779. }
  1780. else
  1781. if((wcschr(char_plus_apostrophe,prev_in) != 0) && (prev_out2 == ' '))
  1782. {
  1783. // consider single character plus apostrophe as a word
  1784. single_quoted = 0;
  1785. if(next_in == ' ')
  1786. {
  1787. source_index++; // skip following space
  1788. }
  1789. }
  1790. else
  1791. {
  1792. if((prev_out == 's') && (single_quoted==0))
  1793. {
  1794. // looks like apostrophe after an 's'
  1795. c = ' ';
  1796. }
  1797. else
  1798. {
  1799. if(iswspace(prev_out))
  1800. single_quoted = 1;
  1801. else
  1802. single_quoted = 0;
  1803. pre_pause_add = 4; // single quote
  1804. c = ' ';
  1805. }
  1806. }
  1807. }
  1808. else
  1809. if(IsBracket(c))
  1810. {
  1811. pre_pause_add = 4;
  1812. c = ' ';
  1813. }
  1814. else
  1815. if(lookupwchar(breaks,c) != 0)
  1816. {
  1817. c = ' '; // various characters to treat as space
  1818. }
  1819. else
  1820. if(iswdigit(c))
  1821. {
  1822. if(langopts.tone_numbers && IsAlpha(prev_out) && !isdigit(next_in))
  1823. {
  1824. }
  1825. else
  1826. if((prev_out != ' ') && !iswdigit(prev_out) && (prev_out != langopts.decimal_sep)) // TEST2
  1827. {
  1828. c = ' ';
  1829. source_index = prev_source_index;
  1830. }
  1831. else
  1832. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1833. {
  1834. // insert extra space between a word and a number, to distinguish 'a 2' from 'a2'
  1835. sbuf[ix++] = ' ';
  1836. words[word_count].start++;
  1837. }
  1838. }
  1839. }
  1840. if(iswspace(c))
  1841. {
  1842. if(prev_out == ' ')
  1843. {
  1844. continue; // multiple spaces
  1845. }
  1846. // end of 'word'
  1847. sbuf[ix++] = ' ';
  1848. if((ix > words[word_count].start) && (word_count < N_CLAUSE_WORDS-1))
  1849. {
  1850. if(embedded_count > 0)
  1851. {
  1852. // there are embedded commands before this word
  1853. embedded_list[embedded_ix-1] |= 0x80; // terminate list of commands for this word
  1854. words[word_count].flags |= FLAG_EMBEDDED;
  1855. embedded_count = 0;
  1856. }
  1857. words[word_count].pre_pause = pre_pause;
  1858. words[word_count].flags |= (all_upper_case | word_flags);
  1859. words[word_count].wmark = word_mark;
  1860. if(pre_pause > 0)
  1861. {
  1862. // insert an extra space before the word, to prevent influence from previous word across the pause
  1863. for(j=ix; j>words[word_count].start; j--)
  1864. {
  1865. sbuf[j] = sbuf[j-1];
  1866. }
  1867. sbuf[j] = ' ';
  1868. words[word_count].start++;
  1869. ix++;
  1870. }
  1871. word_count++;
  1872. words[word_count].start = ix;
  1873. words[word_count].flags = 0;
  1874. for(j=source_index; charix[j] == 0; j++);
  1875. words[word_count].sourceix = charix[j];
  1876. for(k=j; charix[k]!=0; k++);
  1877. words[word_count].length = k-j;
  1878. word_flags = next_word_flags;
  1879. next_word_flags = 0;
  1880. pre_pause = 0;
  1881. word_mark = 0;
  1882. all_upper_case = FLAG_ALL_UPPER;
  1883. }
  1884. }
  1885. else
  1886. {
  1887. ix += utf8_out(c,&sbuf[ix]); // sbuf[ix++] = c;
  1888. }
  1889. if(pre_pause_add > pre_pause)
  1890. pre_pause = pre_pause_add;
  1891. pre_pause_add = 0;
  1892. }
  1893. if((word_count==0) && (embedded_count > 0))
  1894. {
  1895. // add a null 'word' to carry the embedded command flag
  1896. embedded_list[embedded_ix-1] |= 0x80;
  1897. words[word_count].flags |= FLAG_EMBEDDED;
  1898. word_count = 1;
  1899. }
  1900. clause_end = &sbuf[ix-1];
  1901. sbuf[ix] = 0;
  1902. words[0].pre_pause = 0; // don't add extra pause at beginning of clause
  1903. words[word_count].pre_pause = 8;
  1904. if(word_count > 0)
  1905. words[word_count-1].flags |= FLAG_LAST_WORD;
  1906. for(ix=0; ix<word_count; ix++)
  1907. {
  1908. int j;
  1909. char *pn;
  1910. char *pw;
  1911. char number_buf[80];
  1912. // start speaking at a specified word position in the text?
  1913. count_words++;
  1914. if(skip_words > 0)
  1915. {
  1916. skip_words--;
  1917. if(skip_words == 0)
  1918. skipping_text = 0;
  1919. }
  1920. if(skipping_text)
  1921. continue;
  1922. word = pw = &sbuf[words[ix].start];
  1923. for(n_digits=0; iswdigit(word[n_digits]); n_digits++); // count consecutive digits
  1924. if((n_digits > 4) && (word[0] != '0'))
  1925. {
  1926. // word is entirely digits, insert commas and break into 3 digit "words"
  1927. number_buf[0] = ' ';
  1928. pn = &number_buf[1];
  1929. j = n_digits;
  1930. while(pn < &number_buf[sizeof(number_buf)-3])
  1931. {
  1932. if(!isdigit(c = *pw++) && (c != langopts.decimal_sep))
  1933. break;
  1934. *pn++ = c;
  1935. if((--j > 0) && (j % 3)==0)
  1936. {
  1937. if(langopts.thousands_sep != ' ')
  1938. *pn++ = langopts.thousands_sep;
  1939. *pn++ = ' ';
  1940. }
  1941. }
  1942. pn[0] = ' ';
  1943. pn[1] = 0;
  1944. word = pw;
  1945. for(pw = &number_buf[1]; pw < pn;)
  1946. {
  1947. TranslateWord2(pw, &words[ix], words[ix].pre_pause,0 );
  1948. while(*pw++ != ' ');
  1949. words[ix].pre_pause = 0;
  1950. words[ix].flags = 0;
  1951. }
  1952. }
  1953. else
  1954. {
  1955. dict_flags = TranslateWord2(word, &words[ix], words[ix].pre_pause, words[ix+1].pre_pause);
  1956. ix += ((dict_flags >> 5) & 7); // dictionary indicates skip next word(s)
  1957. if((dict_flags & FLAG_DOT) && (ix == word_count-1) && (terminator == CLAUSE_PERIOD))
  1958. {
  1959. // probably an abbreviation such as Mr. or B. rather than end of sentence
  1960. clause_pause = 10;
  1961. tone = 4;
  1962. }
  1963. }
  1964. }
  1965. for(ix=0; ix<2; ix++)
  1966. {
  1967. // terminate the clause with 2 PAUSE phonemes
  1968. ph_list2[n_ph_list2+ix].phcode = phonPAUSE;
  1969. ph_list2[n_ph_list2+ix].stress = 0;
  1970. ph_list2[n_ph_list2+ix].sourceix = 0;
  1971. ph_list2[n_ph_list2+ix].synthflags = 0;
  1972. }
  1973. n_ph_list2 += 2;
  1974. if(Eof() && ((word_count == 0) || (option_endpause==0)))
  1975. {
  1976. clause_pause = 10;
  1977. }
  1978. MakePhonemeList(clause_pause, new_sentence);
  1979. if(embedded_count) // ???? is this needed
  1980. {
  1981. phoneme_list[n_phoneme_list-2].synthflags = SFLAG_EMBEDDED;
  1982. embedded_list[embedded_ix-1] |= 0x80;
  1983. }
  1984. prev_clause_pause = clause_pause;
  1985. GetTranslatedPhonemeString(phon_out,sizeof(phon_out));
  1986. *tone_out = tone;
  1987. new_sentence = 0;
  1988. if(terminator & CLAUSE_BIT_SENTENCE)
  1989. {
  1990. new_sentence = 1; // next clause is a new sentence
  1991. }
  1992. if(voice_change != NULL)
  1993. {
  1994. // return new voice name if an embedded voice change command terminated the clause
  1995. if(terminator & CLAUSE_BIT_VOICE)
  1996. *voice_change = &source[source_index];
  1997. else
  1998. *voice_change = NULL;
  1999. }
  2000. if(Eof() || (vp_input==NULL))
  2001. return(NULL);
  2002. if(option_multibyte == espeakCHARS_WCHAR)
  2003. return((void *)p_wchar_input);
  2004. else
  2005. return((void *)p_textinput);
  2006. } // end of TranslateClause
  2007. void InitText(int control)
  2008. {//=======================
  2009. count_sentences = 0;
  2010. count_words = 0;
  2011. end_character_position = 0;
  2012. skip_sentences = 0;
  2013. skip_marker[0] = 0;
  2014. skip_words = 0;
  2015. skip_characters = 0;
  2016. skipping_text = 0;
  2017. new_sentence = 1;
  2018. ungot_char = 0;
  2019. prev_clause_pause = 0;
  2020. option_sayas = 0;
  2021. option_sayas2 = 0;
  2022. option_emphasis = 0;
  2023. InitText2();
  2024. if((control & espeakKEEP_NAMEDATA) == 0)
  2025. {
  2026. InitNamedata();
  2027. }
  2028. }