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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2010 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. 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_tone2 = 0;
  38. int option_tone_flags = 0; // bit 8=emphasize allcaps, bit 9=emphasize penultimate stress
  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. static int option_sayas2 = 0; // used in translate_clause()
  47. static int option_emphasis = 0; // 0=normal, 1=normal, 2=weak, 3=moderate, 4=strong
  48. int option_ssml = 0;
  49. int option_phoneme_input = 0; // allow [[phonemes]] in input
  50. int option_phoneme_variants = 0; // 0= don't display phoneme variant mnemonics
  51. int option_wordgap = 0;
  52. static int count_sayas_digits;
  53. int skip_sentences;
  54. int skip_words;
  55. int skip_characters;
  56. char skip_marker[N_MARKER_LENGTH];
  57. int skipping_text; // waiting until word count, sentence count, or named marker is reached
  58. int end_character_position;
  59. int count_sentences;
  60. int count_words;
  61. int clause_start_char;
  62. int clause_start_word;
  63. int new_sentence;
  64. static int word_emphasis = 0; // set if emphasis level 3 or 4
  65. static int embedded_flag = 0; // there are embedded commands to be applied to the next phoneme, used in TranslateWord2()
  66. static int prev_clause_pause=0;
  67. static int max_clause_pause = 0;
  68. static int any_stressed_words;
  69. int pre_pause;
  70. // these were previously in translator class
  71. #ifdef PLATFORM_WINDOWS
  72. char word_phonemes[N_WORD_PHONEMES*2]; // longer, because snprint() is not available
  73. #else
  74. char word_phonemes[N_WORD_PHONEMES]; // a word translated into phoneme codes
  75. #endif
  76. int n_ph_list2;
  77. PHONEME_LIST2 ph_list2[N_PHONEME_LIST]; // first stage of text->phonemes
  78. wchar_t option_punctlist[N_PUNCTLIST]={0};
  79. char ctrl_embedded = '\001'; // to allow an alternative CTRL for embedded commands
  80. int option_multibyte=espeakCHARS_AUTO; // 0=auto, 1=utf8, 2=8bit, 3=wchar, 4=16bit
  81. // these are overridden by defaults set in the "speak" file
  82. int option_linelength = 0;
  83. #define N_EMBEDDED_LIST 250
  84. static int embedded_ix;
  85. static int embedded_read;
  86. unsigned int embedded_list[N_EMBEDDED_LIST];
  87. // the source text of a single clause (UTF8 bytes)
  88. #define N_TR_SOURCE 700
  89. static char source[N_TR_SOURCE+40]; // extra space for embedded command & voice change info at end
  90. int n_replace_phonemes;
  91. REPLACE_PHONEMES replace_phonemes[N_REPLACE_PHONEMES];
  92. // brackets, also 0x2014 to 0x021f which don't need to be in this list
  93. static const unsigned short brackets[] = {
  94. '(',')','[',']','{','}','<','>','"','\'','`',
  95. 0xab,0xbb, // double angle brackets
  96. 0x300a,0x300b, // double angle brackets (ideograph)
  97. 0};
  98. // other characters which break a word, but don't produce a pause
  99. static const unsigned short breaks[] = {'_', 0};
  100. // treat these characters as spaces, in addition to iswspace()
  101. static const wchar_t chars_space[] = {0x2500,0}; // box drawing horiz
  102. // Translate character codes 0xA0 to 0xFF into their unicode values
  103. // ISO_8859_1 is set as default
  104. static const unsigned short ISO_8859_1[0x60] = {
  105. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0
  106. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8
  107. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0
  108. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8
  109. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  110. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  111. 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  112. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, // d8
  113. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  114. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  115. 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  116. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff, // f8
  117. };
  118. static const unsigned short ISO_8859_2[0x60] = {
  119. 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, // a0
  120. 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, // a8
  121. 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, // b0
  122. 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, // b8
  123. 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, // c0
  124. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, // c8
  125. 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, // d0
  126. 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, // d8
  127. 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, // e0
  128. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, // e8
  129. 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, // f0
  130. 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, // f8
  131. };
  132. static const unsigned short ISO_8859_3[0x60] = {
  133. 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, // a0
  134. 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b, // a8
  135. 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, // b0
  136. 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0x0000, 0x017c, // b8
  137. 0x00c0, 0x00c1, 0x00c2, 0x0000, 0x00c4, 0x010a, 0x0108, 0x00c7, // c0
  138. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  139. 0x0000, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, // d0
  140. 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df, // d8
  141. 0x00e0, 0x00e1, 0x00e2, 0x0000, 0x00e4, 0x010b, 0x0109, 0x00e7, // e0
  142. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  143. 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, // f0
  144. 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9, // f8
  145. };
  146. static const unsigned short ISO_8859_4[0x60] = {
  147. 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, // a0
  148. 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, // a8
  149. 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, // b0
  150. 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, // b8
  151. 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, // c0
  152. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, // c8
  153. 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  154. 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, // d8
  155. 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, // e0
  156. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, // e8
  157. 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  158. 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9, // f8
  159. };
  160. static const unsigned short ISO_8859_5[0x60] = {
  161. 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, // a0 Cyrillic
  162. 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f, // a8
  163. 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, // b0
  164. 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, // b8
  165. 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, // c0
  166. 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, // c8
  167. 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, // d0
  168. 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, // d8
  169. 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, // e0
  170. 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, // e8
  171. 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, // f0
  172. 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f, // f8
  173. };
  174. static const unsigned short ISO_8859_7[0x60] = {
  175. 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, // a0 Greek
  176. 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015, // a8
  177. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7, // b0
  178. 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, // b8
  179. 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, // c0
  180. 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, // c8
  181. 0x03a0, 0x03a1, 0x0000, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, // d0
  182. 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, // d8
  183. 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, // e0
  184. 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, // e8
  185. 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, // f0
  186. 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000, // f8
  187. };
  188. static const unsigned short ISO_8859_9[0x60] = {
  189. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0
  190. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8
  191. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0
  192. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8
  193. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  194. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  195. 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  196. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df, // d8
  197. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  198. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  199. 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  200. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff, // f8
  201. };
  202. static const unsigned short ISO_8859_14[0x60] = {
  203. 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, // a0 Welsh
  204. 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178, // a8
  205. 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56, // b0
  206. 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, // b8
  207. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  208. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  209. 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a, // d0
  210. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df, // d8
  211. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  212. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  213. 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, // f0
  214. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff, // f8
  215. };
  216. static const unsigned short KOI8_R[0x60] = {
  217. 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, // a0 Russian
  218. 0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x255c, 0x255d, 0x255e, // a8
  219. 0x255f, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, // b0
  220. 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b, 0x256c, 0x00a9, // b8
  221. 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, // c0
  222. 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, // c8
  223. 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, // d0
  224. 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, // d8
  225. 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, // e0
  226. 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, // e8
  227. 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, // f0
  228. 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a, // f8
  229. };
  230. static const unsigned short ISCII[0x60] = {
  231. 0x0020, 0x0901, 0x0902, 0x0903, 0x0905, 0x0906, 0x0907, 0x0908, // a0
  232. 0x0909, 0x090a, 0x090b, 0x090e, 0x090f, 0x0910, 0x090d, 0x0912, // a8
  233. 0x0913, 0x0914, 0x0911, 0x0915, 0x0916, 0x0917, 0x0918, 0x0919, // b0
  234. 0x091a, 0x091b, 0x091c, 0x091d, 0x091e, 0x091f, 0x0920, 0x0921, // b8
  235. 0x0922, 0x0923, 0x0924, 0x0925, 0x0926, 0x0927, 0x0928, 0x0929, // c0
  236. 0x092a, 0x092b, 0x092c, 0x092d, 0x092e, 0x092f, 0x095f, 0x0930, // c8
  237. 0x0931, 0x0932, 0x0933, 0x0934, 0x0935, 0x0936, 0x0937, 0x0938, // d0
  238. 0x0939, 0x0020, 0x093e, 0x093f, 0x0940, 0x0941, 0x0942, 0x0943, // d8
  239. 0x0946, 0x0947, 0x0948, 0x0945, 0x094a, 0x094b, 0x094c, 0x0949, // e0
  240. 0x094d, 0x093c, 0x0964, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, // e8
  241. 0x0020, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, // f0
  242. 0x0037, 0x0038, 0x0039, 0x20, 0x20, 0x20, 0x20, 0x20, // f8
  243. };
  244. const unsigned short *charsets[N_CHARSETS] = {
  245. ISO_8859_1,
  246. ISO_8859_1,
  247. ISO_8859_2,
  248. ISO_8859_3,
  249. ISO_8859_4,
  250. ISO_8859_5,
  251. ISO_8859_1,
  252. ISO_8859_7,
  253. ISO_8859_1,
  254. ISO_8859_9,
  255. ISO_8859_1,
  256. ISO_8859_1,
  257. ISO_8859_1,
  258. ISO_8859_1,
  259. ISO_8859_14,
  260. ISO_8859_1,
  261. ISO_8859_1,
  262. ISO_8859_1,
  263. KOI8_R, // 18
  264. ISCII };
  265. // Tables of the relative lengths of vowels, depending on the
  266. // type of the two phonemes that follow
  267. // indexes are the "length_mod" value for the following phonemes
  268. // use this table if vowel is not the last in the word
  269. static unsigned char length_mods_en[100] = {
  270. /* a , t s n d z r N <- next */
  271. 100,120,100,105,100,110,110,100, 95, 100, /* a <- next2 */
  272. 105,120,105,110,125,130,135,115,125, 100, /* , */
  273. 105,120, 75,100, 75,105,120, 85, 75, 100, /* t */
  274. 105,120, 85,105, 95,115,120,100, 95, 100, /* s */
  275. 110,120, 95,105,100,115,120,100,100, 100, /* n */
  276. 105,120,100,105, 95,115,120,110, 95, 100, /* d */
  277. 105,120,100,105,105,122,125,110,105, 100, /* z */
  278. 105,120,100,105,105,122,125,110,105, 100, /* r */
  279. 105,120, 95,105,100,115,120,110,100, 100, /* N */
  280. 100,120,100,100,100,100,100,100,100, 100 }; // SPARE
  281. // as above, but for the last syllable in a word
  282. static unsigned char length_mods_en0[100] = {
  283. /* a , t s n d z r N <- next */
  284. 100,150,100,105,110,115,110,110,110, 100, /* a <- next2 */
  285. 105,150,105,110,125,135,140,115,135, 100, /* , */
  286. 105,150, 90,105, 90,122,135,100, 90, 100, /* t */
  287. 105,150,100,105,100,122,135,100,100, 100, /* s */
  288. 105,150,100,105,105,115,135,110,105, 100, /* n */
  289. 105,150,100,105,105,122,130,120,125, 100, /* d */
  290. 105,150,100,105,110,122,125,115,110, 100, /* z */
  291. 105,150,100,105,105,122,135,120,105, 100, /* r */
  292. 105,150,100,105,105,115,135,110,105, 100, /* N */
  293. 100,100,100,100,100,100,100,100,100, 100 }; // SPARE
  294. static unsigned char length_mods_equal[100] = {
  295. /* a , t s n d z r N <- next */
  296. 110,110,110,110,110,110,110,110,110, 110, /* a <- next2 */
  297. 110,110,110,110,110,110,110,110,110, 110, /* , */
  298. 110,110,110,110,110,110,110,110,110, 110, /* t */
  299. 110,110,110,110,110,110,110,110,110, 110, /* s */
  300. 110,110,110,110,110,110,110,110,110, 110, /* n */
  301. 110,110,110,110,110,110,110,110,110, 110, /* d */
  302. 110,110,110,110,110,110,110,110,110, 110, /* z */
  303. 110,110,110,110,110,110,110,110,110, 110, /* r */
  304. 110,110,110,110,110,110,110,110,110, 110, /* N */
  305. 110,110,110,110,110,110,110,110,110, 110 }; // SPARE
  306. static unsigned char *length_mod_tabs[6] = {
  307. length_mods_en,
  308. length_mods_en, // 1
  309. length_mods_en0, // 2
  310. length_mods_equal, // 3
  311. length_mods_equal, // 4
  312. length_mods_equal // 5
  313. };
  314. void SetLengthMods(Translator *tr, int value)
  315. {//==========================================
  316. int value2;
  317. tr->langopts.length_mods0 = tr->langopts.length_mods = length_mod_tabs[value % 100];
  318. if((value2 = value / 100) != 0)
  319. {
  320. tr->langopts.length_mods0 = length_mod_tabs[value2];
  321. }
  322. }
  323. int IsAlpha(unsigned int c)
  324. {//========================
  325. // Replacement for iswalph() which also checks for some in-word symbols
  326. const unsigned short extra_indic_alphas[] = {
  327. 0xa70,0xa71, // Gurmukhi: tippi, addak
  328. 0 };
  329. if(iswalpha(c))
  330. return(1);
  331. if((c >= 0x901) && (c <= 0xdf7))
  332. {
  333. // Indic scripts: Devanagari, Tamil, etc
  334. if((c & 0x7f) < 0x64)
  335. return(1);
  336. if(lookupwchar(extra_indic_alphas, c) != 0)
  337. return(1);
  338. return(0);
  339. }
  340. if((c >= 0x64b) && (c <= 0x65e))
  341. return(1); // arabic vowel marks
  342. if((c >= 0x300) && (c <= 0x36f))
  343. return(1); // combining accents
  344. if((c >= 0x1100) && (c <= 0x11ff))
  345. return(1); //Korean jamo
  346. if((c > 0x3040) && (c <= 0xa700))
  347. return(1); // Chinese/Japanese. Should never get here, but Mac OS 10.4's iswalpha seems to be broken, so just make sure
  348. return(0);
  349. }
  350. static int IsDigit09(unsigned int c)
  351. {//=========================
  352. if((c >= '0') && (c <= '9'))
  353. return(1);
  354. return(0);
  355. }
  356. int IsDigit(unsigned int c)
  357. {//========================
  358. if(iswdigit(c))
  359. return(1);
  360. if((c >= 0x966) && (c <= 0x96f))
  361. return(1);
  362. return(0);
  363. }
  364. int IsSpace(unsigned int c)
  365. {//========================
  366. if(c == 0)
  367. return(0);
  368. if(wcschr(chars_space,c))
  369. return(1);
  370. return(iswspace(c));
  371. }
  372. void DeleteTranslator(Translator *tr)
  373. {//==================================
  374. if(tr->data_dictlist != NULL)
  375. Free(tr->data_dictlist);
  376. Free(tr);
  377. }
  378. int lookupwchar(const unsigned short *list,int c)
  379. {//==============================================
  380. // Is the character c in the list ?
  381. int ix;
  382. for(ix=0; list[ix] != 0; ix++)
  383. {
  384. if(list[ix] == c)
  385. return(ix+1);
  386. }
  387. return(0);
  388. }
  389. int IsBracket(int c)
  390. {//=================
  391. if((c >= 0x2014) && (c <= 0x201f))
  392. return(1);
  393. return(lookupwchar(brackets,c));
  394. }
  395. int utf8_out(unsigned int c, char *buf)
  396. {//====================================
  397. // write a unicode character into a buffer as utf8
  398. // returns the number of bytes written
  399. int n_bytes;
  400. int j;
  401. int shift;
  402. static char unsigned code[4] = {0,0xc0,0xe0,0xf0};
  403. if(c < 0x80)
  404. {
  405. buf[0] = c;
  406. return(1);
  407. }
  408. if(c >= 0x110000)
  409. {
  410. buf[0] = ' '; // out of range character code
  411. return(1);
  412. }
  413. if(c < 0x0800)
  414. n_bytes = 1;
  415. else
  416. if(c < 0x10000)
  417. n_bytes = 2;
  418. else
  419. n_bytes = 3;
  420. shift = 6*n_bytes;
  421. buf[0] = code[n_bytes] | (c >> shift);
  422. for(j=0; j<n_bytes; j++)
  423. {
  424. shift -= 6;
  425. buf[j+1] = 0x80 + ((c >> shift) & 0x3f);
  426. }
  427. return(n_bytes+1);
  428. } // end of utf8_out
  429. int utf8_nbytes(const char *buf)
  430. {//=============================
  431. // Returns the number of bytes for the first UTF-8 character in buf
  432. unsigned char c = (unsigned char)buf[0];
  433. if(c < 0x80)
  434. return(1);
  435. if(c < 0xe0)
  436. return(2);
  437. if(c < 0xf0)
  438. return(3);
  439. return(4);
  440. }
  441. int utf8_in2(int *c, const char *buf, int backwards)
  442. {//=================================================
  443. // Read a unicode characater from a UTF8 string
  444. // Returns the number of UTF8 bytes used.
  445. // backwards: set if we are moving backwards through the UTF8 string
  446. int c1;
  447. int n_bytes;
  448. int ix;
  449. static const unsigned char mask[4] = {0xff,0x1f,0x0f,0x07};
  450. // find the start of the next/previous character
  451. while((*buf & 0xc0) == 0x80)
  452. {
  453. // skip over non-initial bytes of a multi-byte utf8 character
  454. if(backwards)
  455. buf--;
  456. else
  457. buf++;
  458. }
  459. n_bytes = 0;
  460. if((c1 = *buf++) & 0x80)
  461. {
  462. if((c1 & 0xe0) == 0xc0)
  463. n_bytes = 1;
  464. else
  465. if((c1 & 0xf0) == 0xe0)
  466. n_bytes = 2;
  467. else
  468. if((c1 & 0xf8) == 0xf0)
  469. n_bytes = 3;
  470. c1 &= mask[n_bytes];
  471. for(ix=0; ix<n_bytes; ix++)
  472. {
  473. c1 = (c1 << 6) + (*buf++ & 0x3f);
  474. }
  475. }
  476. *c = c1;
  477. return(n_bytes+1);
  478. }
  479. int utf8_in(int *c, const char *buf)
  480. {//=================================
  481. // Read a unicode characater from a UTF8 string
  482. // Returns the number of UTF8 bytes used.
  483. return(utf8_in2(c,buf,0));
  484. }
  485. char *strchr_w(const char *s, int c)
  486. {//=================================
  487. // return NULL for any non-ascii character
  488. if(c >= 0x80)
  489. return(NULL);
  490. return(strchr((char *)s,c)); // (char *) is needed for Borland compiler
  491. }
  492. int TranslateWord(Translator *tr, char *word1, int next_pause, WORD_TAB *wtab)
  493. {//===========================================================================
  494. // word1 is terminated by space (0x20) character
  495. int length;
  496. int word_length;
  497. int ix;
  498. int posn;
  499. int pfix;
  500. int n_chars;
  501. unsigned int dictionary_flags[2];
  502. unsigned int dictionary_flags2[2];
  503. int end_type=0;
  504. int prefix_type=0;
  505. char *wordx;
  506. char phonemes[N_WORD_PHONEMES];
  507. char *ph_limit;
  508. char prefix_phonemes[N_WORD_PHONEMES];
  509. char unpron_phonemes[N_WORD_PHONEMES];
  510. char end_phonemes[N_WORD_PHONEMES];
  511. char word_copy[N_WORD_BYTES];
  512. char prefix_chars[41];
  513. int found=0;
  514. int end_flags;
  515. char c_temp; // save a character byte while we temporarily replace it with space
  516. int first_char;
  517. int last_char = 0;
  518. int add_plural_suffix = 0;
  519. int prefix_flags = 0;
  520. int confirm_prefix;
  521. int spell_word;
  522. int stress_bits;
  523. int emphasize_allcaps = 0;
  524. int wflags;
  525. int wmark;
  526. WORD_TAB wtab_null[8];
  527. // translate these to get pronunciations of plural 's' suffix (different forms depending on
  528. // the preceding letter
  529. static char word_zz[4] = {0,'z','z',0};
  530. static char word_iz[4] = {0,'i','z',0};
  531. static char word_ss[4] = {0,'s','s',0};
  532. if(wtab == NULL)
  533. {
  534. memset(wtab_null, 0, sizeof(wtab_null));
  535. wtab = wtab_null;
  536. }
  537. wflags = wtab->flags;
  538. wmark = wtab->wmark;
  539. dictionary_flags[0] = 0;
  540. dictionary_flags[1] = 0;
  541. dictionary_flags2[0] = 0;
  542. dictionary_flags2[1] = 0;
  543. dictionary_skipwords = 0;
  544. phonemes[0] = 0;
  545. unpron_phonemes[0] = 0;
  546. prefix_phonemes[0] = 0;
  547. end_phonemes[0] = 0;
  548. ph_limit = &phonemes[N_WORD_PHONEMES];
  549. if(tr->data_dictlist == NULL)
  550. {
  551. // dictionary is not loaded
  552. word_phonemes[0] = 0;
  553. return(0);
  554. }
  555. // count the length of the word
  556. if(*word1 == ' ') word1++; // possibly a dot was replaced by space: $dot
  557. wordx = word1;
  558. utf8_in(&first_char,wordx);
  559. word_length = 0;
  560. while((*wordx != 0) && (*wordx != ' '))
  561. {
  562. wordx += utf8_in(&last_char,wordx);
  563. word_length++;
  564. }
  565. spell_word = 0;
  566. if(option_sayas == SAYAS_KEY)
  567. {
  568. if(word_length == 1)
  569. spell_word = 4;
  570. else
  571. {
  572. // is there a translation for this keyname ?
  573. word1--;
  574. *word1 = '_'; // prefix keyname with '_'
  575. found = LookupDictList(tr, &word1, phonemes, dictionary_flags, 0, wtab);
  576. }
  577. }
  578. // try an initial lookup in the dictionary list, we may find a pronunciation specified, or
  579. // we may just find some flags
  580. if(option_sayas & 0x10)
  581. {
  582. // SAYAS_CHAR, SAYAS_GYLPH, or SAYAS_SINGLE_CHAR
  583. spell_word = option_sayas & 0xf; // 2,3,4
  584. }
  585. else
  586. {
  587. if(!found)
  588. found = LookupDictList(tr, &word1, phonemes, dictionary_flags, FLAG_ALLOW_TEXTMODE, wtab); // the original word
  589. if((dictionary_flags[0] & (FLAG_ALLOW_DOT || FLAG_NEEDS_DOT)) && (wordx[1] == '.'))
  590. {
  591. wordx[1] = ' '; // remove a Dot after this word
  592. }
  593. if(dictionary_flags[0] & FLAG_TEXTMODE)
  594. {
  595. first_char = word1[0];
  596. stress_bits = dictionary_flags[0] & 0x7f;
  597. found = LookupDictList(tr, &word1, phonemes, dictionary_flags2, 0, wtab); // the text replacement
  598. if(dictionary_flags2[0]!=0)
  599. {
  600. dictionary_flags[0] = dictionary_flags2[0];
  601. dictionary_flags[1] = dictionary_flags2[1];
  602. if(stress_bits != 0)
  603. {
  604. // keep any stress information from the original word
  605. dictionary_flags[0] = (dictionary_flags[0] & ~0x7f) | stress_bits;
  606. }
  607. }
  608. }
  609. else
  610. if((found==0) && (dictionary_flags[0] & FLAG_SKIPWORDS))
  611. {
  612. // grouped words, but no translation. Join the words with hyphens.
  613. wordx = word1;
  614. ix = 0;
  615. while(ix < dictionary_skipwords)
  616. {
  617. if(*wordx == ' ')
  618. {
  619. *wordx = '-';
  620. ix++;
  621. }
  622. wordx++;
  623. }
  624. }
  625. // if textmode, LookupDictList() replaces word1 by the new text and returns found=0
  626. if(phonemes[0] == phonSWITCH)
  627. {
  628. // change to another language in order to translate this word
  629. strcpy(word_phonemes,phonemes);
  630. return(0);
  631. }
  632. if((wmark > 0) && (wmark < 8))
  633. {
  634. // the stressed syllable has been specified in the text (TESTING)
  635. dictionary_flags[0] = (dictionary_flags[0] & ~0xf) | wmark;
  636. }
  637. if(!found && (dictionary_flags[0] & FLAG_ABBREV))
  638. {
  639. // the word has $abbrev flag, but no pronunciation specified. Speak as individual letters
  640. spell_word = 1;
  641. }
  642. if(!found && iswdigit(first_char))
  643. {
  644. Lookup(tr,"_0lang",word_phonemes);
  645. if(word_phonemes[0] == phonSWITCH)
  646. return(0);
  647. found = TranslateNumber(tr,word1,phonemes,dictionary_flags,wtab);
  648. }
  649. if(!found & ((wflags & FLAG_UPPERS) != FLAG_FIRST_UPPER))
  650. {
  651. // either all upper or all lower case
  652. if((tr->langopts.numbers & NUM_ROMAN) || ((tr->langopts.numbers & NUM_ROMAN_UC) && (wflags & FLAG_ALL_UPPER)))
  653. {
  654. if((found = TranslateRoman(tr, word1, phonemes, wtab)) != 0)
  655. dictionary_flags[0] |= FLAG_ABBREV; // prevent emphasis if capitals
  656. }
  657. }
  658. if((wflags & FLAG_ALL_UPPER) && (word_length > 1)&& iswalpha(first_char))
  659. {
  660. if((option_tone_flags & OPTION_EMPHASIZE_ALLCAPS) && !(dictionary_flags[0] & FLAG_ABBREV))
  661. {
  662. // emphasize words which are in capitals
  663. emphasize_allcaps = FLAG_EMPHASIZED;
  664. }
  665. else
  666. if(!found && !(dictionary_flags[0] & FLAG_SKIPWORDS) && (word_length<4) && (tr->clause_lower_count > 3)
  667. && (tr->clause_upper_count <= tr->clause_lower_count))
  668. {
  669. // An upper case word in a lower case clause. This could be an abbreviation.
  670. spell_word = 1;
  671. }
  672. }
  673. }
  674. if(spell_word > 0)
  675. {
  676. // Speak as individual letters
  677. wordx = word1;
  678. posn = 0;
  679. phonemes[0] = 0;
  680. end_type = 0;
  681. while(*wordx != ' ')
  682. {
  683. wordx += TranslateLetter(tr,wordx, phonemes, spell_word);
  684. posn++;
  685. if(phonemes[0] == phonSWITCH)
  686. {
  687. // change to another language in order to translate this word
  688. strcpy(word_phonemes,phonemes);
  689. if(word_length > 1)
  690. return(FLAG_SPELLWORD); // a mixture of languages, retranslate as individual letters, separated by spaces
  691. return(0);
  692. }
  693. }
  694. SetSpellingStress(tr,phonemes,spell_word,posn);
  695. }
  696. else
  697. if(found == 0)
  698. {
  699. // word's pronunciation is not given in the dictionary list, although
  700. // dictionary_flags may have ben set there
  701. posn = 0;
  702. length = 999;
  703. wordx = word1;
  704. while(((length < 3) && (length > 0))|| (word_length > 1 && Unpronouncable(tr,wordx)))
  705. {
  706. char *p;
  707. // This word looks "unpronouncable", so speak letters individually until we
  708. // find a remainder that we can pronounce.
  709. emphasize_allcaps = 0;
  710. wordx += TranslateLetter(tr, wordx, unpron_phonemes, 0);
  711. posn++;
  712. if(unpron_phonemes[0] == phonSWITCH)
  713. {
  714. // change to another language in order to translate this word
  715. strcpy(word_phonemes,unpron_phonemes);
  716. if(strcmp(&unpron_phonemes[1],"en")==0)
  717. return(FLAG_SPELLWORD); // _^_en must have been set in TranslateLetter(), not *_rules
  718. return(0);
  719. }
  720. p = &wordx[word_length-3]; // this looks wrong. Doesn't consider multi-byte chars.
  721. if(memcmp(p,"'s ",3) == 0)
  722. {
  723. // remove a 's suffix and pronounce this separately (not as an individual letter)
  724. add_plural_suffix = 1;
  725. p[0] = ' ';
  726. p[1] = ' ';
  727. last_char = p[-1];
  728. }
  729. length=0;
  730. while(wordx[length] != ' ') length++;
  731. if(length > 0)
  732. wordx[-1] = ' '; // prevent this affecting the pronunciation of the pronuncable part
  733. }
  734. SetSpellingStress(tr,unpron_phonemes,0,posn);
  735. // anything left ?
  736. if(*wordx != ' ')
  737. {
  738. // Translate the stem
  739. end_type = TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags);
  740. if(phonemes[0] == phonSWITCH)
  741. {
  742. // change to another language in order to translate this word
  743. strcpy(word_phonemes,phonemes);
  744. return(0);
  745. }
  746. if((phonemes[0] == 0) && (end_phonemes[0] == 0))
  747. {
  748. int wc;
  749. // characters not recognised, speak them individually
  750. utf8_in(&wc, wordx);
  751. if((word_length == 1) && IsAlpha(wc))
  752. {
  753. posn = 0;
  754. while((*wordx != ' ') && (*wordx != 0))
  755. {
  756. wordx += TranslateLetter(tr,wordx, phonemes, 4);
  757. posn++;
  758. if(phonemes[0] == phonSWITCH)
  759. {
  760. // change to another language in order to translate this word
  761. strcpy(word_phonemes,phonemes);
  762. return(0);
  763. }
  764. }
  765. SetSpellingStress(tr,phonemes,spell_word,posn);
  766. }
  767. }
  768. c_temp = wordx[-1];
  769. found = 0;
  770. confirm_prefix = 1;
  771. while(end_type & SUFX_P)
  772. {
  773. // Found a standard prefix, remove it and retranslate
  774. if(confirm_prefix && !(end_type & SUFX_B))
  775. {
  776. int end2;
  777. char phonemes2[N_WORD_PHONEMES];
  778. char end_phonemes2[N_WORD_PHONEMES];
  779. // remove any standard suffix and confirm that the prefix is still recognised
  780. phonemes2[0] = 0;
  781. end2 = TranslateRules(tr, wordx, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags);
  782. if(end2)
  783. {
  784. RemoveEnding(tr, wordx, end2, word_copy);
  785. end_type = TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags);
  786. memcpy(wordx,word_copy,strlen(word_copy));
  787. if((end_type & SUFX_P) == 0)
  788. {
  789. // after removing the suffix, the prefix is no longer recognised.
  790. // Keep the suffix, but don't use the prefix
  791. end_type = end2;
  792. strcpy(phonemes,phonemes2);
  793. strcpy(end_phonemes,end_phonemes2);
  794. if(option_phonemes == 2)
  795. {
  796. DecodePhonemes(end_phonemes,end_phonemes2);
  797. fprintf(f_trans," suffix [%s]\n\n",end_phonemes2);
  798. }
  799. }
  800. confirm_prefix = 0;
  801. continue;
  802. }
  803. }
  804. prefix_type = end_type;
  805. if(prefix_type & SUFX_V)
  806. {
  807. tr->expect_verb = 1; // use the verb form of the word
  808. }
  809. wordx[-1] = c_temp;
  810. if((prefix_type & SUFX_B) == 0)
  811. {
  812. for(ix=(prefix_type & 0xf); ix>0; ix--) // num. of characters to remove
  813. {
  814. wordx++;
  815. while((*wordx & 0xc0) == 0x80) wordx++; // for multibyte characters
  816. }
  817. }
  818. else
  819. {
  820. pfix = 1;
  821. prefix_chars[0] = 0;
  822. n_chars = prefix_type & 0x3f;
  823. for(ix=0; ix < n_chars; ix++) // num. of bytes to remove
  824. {
  825. prefix_chars[pfix++] = *wordx++;
  826. if((prefix_type & SUFX_B) && (ix == (n_chars-1)))
  827. {
  828. prefix_chars[pfix-1] = 0; // discard the last character of the prefix, this is the separator character
  829. }
  830. }
  831. prefix_chars[pfix] = 0;
  832. }
  833. c_temp = wordx[-1];
  834. wordx[-1] = ' ';
  835. confirm_prefix = 1;
  836. if(prefix_type & SUFX_B)
  837. {
  838. // SUFX_B is used for Turkish, tr_rules contains "(Pb£
  839. // retranslate the prefix part
  840. char *wordpf;
  841. char prefix_phonemes2[12];
  842. strncpy0(prefix_phonemes2,end_phonemes,sizeof(prefix_phonemes2));
  843. wordpf = &prefix_chars[1];
  844. found = LookupDictList(tr, &wordpf, phonemes, dictionary_flags, SUFX_P, wtab); // without prefix
  845. if(found == 0)
  846. {
  847. end_type = TranslateRules(tr, wordpf, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags);
  848. sprintf(prefix_phonemes,"%s%s%s",phonemes,end_phonemes,prefix_phonemes2);
  849. }
  850. prefix_flags = 1;
  851. }
  852. else
  853. {
  854. strcat(prefix_phonemes,end_phonemes);
  855. }
  856. end_phonemes[0] = 0;
  857. end_type = 0;
  858. found = LookupDictList(tr, &wordx, phonemes, dictionary_flags2, SUFX_P, wtab); // without prefix
  859. if(dictionary_flags[0]==0)
  860. {
  861. dictionary_flags[0] = dictionary_flags2[0];
  862. dictionary_flags[1] = dictionary_flags2[1];
  863. }
  864. else
  865. prefix_flags = 1;
  866. if(found == 0)
  867. {
  868. end_type = TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags);
  869. if(phonemes[0] == phonSWITCH)
  870. {
  871. // change to another language in order to translate this word
  872. wordx[-1] = c_temp;
  873. strcpy(word_phonemes,phonemes);
  874. return(0);
  875. }
  876. }
  877. }
  878. if((end_type != 0) && !(end_type & SUFX_P))
  879. {
  880. char phonemes2[N_WORD_PHONEMES];
  881. strcpy(phonemes2,phonemes);
  882. // The word has a standard ending, re-translate without this ending
  883. end_flags = RemoveEnding(tr, wordx, end_type, word_copy);
  884. phonemes[0] = 0;
  885. if(prefix_phonemes[0] != 0)
  886. {
  887. // lookup the stem without the prefix removed
  888. wordx[-1] = c_temp;
  889. found = LookupDictList(tr, &word1, phonemes, dictionary_flags2, end_flags, wtab); // include prefix, but not suffix
  890. wordx[-1] = ' ';
  891. if(dictionary_flags[0]==0)
  892. {
  893. dictionary_flags[0] = dictionary_flags2[0];
  894. dictionary_flags[1] = dictionary_flags2[1];
  895. }
  896. if(found)
  897. prefix_phonemes[0] = 0; // matched whole word, don't need prefix now
  898. if((found==0) && (dictionary_flags2[0] != 0))
  899. prefix_flags = 1;
  900. }
  901. if(found == 0)
  902. {
  903. found = LookupDictList(tr, &wordx, phonemes, dictionary_flags2, end_flags, wtab); // without prefix and suffix
  904. if(phonemes[0] == phonSWITCH)
  905. {
  906. // change to another language in order to translate this word
  907. memcpy(wordx,word_copy,strlen(word_copy));
  908. strcpy(word_phonemes,phonemes);
  909. return(0);
  910. }
  911. if(dictionary_flags[0]==0)
  912. {
  913. dictionary_flags[0] = dictionary_flags2[0];
  914. dictionary_flags[1] = dictionary_flags2[1];
  915. }
  916. }
  917. if(found == 0)
  918. {
  919. if(end_type & SUFX_Q)
  920. {
  921. // don't retranslate, use the original lookup result
  922. strcpy(phonemes,phonemes2);
  923. // language specific changes
  924. ApplySpecialAttribute(tr,phonemes,dictionary_flags[0]);
  925. }
  926. else
  927. {
  928. if(end_flags & FLAG_SUFX)
  929. TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, NULL,wflags | FLAG_SUFFIX_REMOVED, dictionary_flags);
  930. else
  931. TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, NULL,wflags,dictionary_flags);
  932. if(phonemes[0] == phonSWITCH)
  933. {
  934. // change to another language in order to translate this word
  935. strcpy(word_phonemes,phonemes);
  936. memcpy(wordx,word_copy,strlen(word_copy));
  937. wordx[-1] = c_temp;
  938. return(0);
  939. }
  940. }
  941. }
  942. if((end_type & SUFX_T) == 0)
  943. {
  944. // the default is to add the suffix and then determine the word's stress pattern
  945. AppendPhonemes(tr,phonemes, N_WORD_PHONEMES, end_phonemes);
  946. end_phonemes[0] = 0;
  947. }
  948. memcpy(wordx,word_copy,strlen(word_copy));
  949. }
  950. wordx[-1] = c_temp;
  951. }
  952. }
  953. if((add_plural_suffix) || (wflags & FLAG_HAS_PLURAL))
  954. {
  955. // s or 's suffix, append [s], [z] or [Iz] depending on previous letter
  956. if(last_char == 'f')
  957. TranslateRules(tr, &word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
  958. else
  959. if((last_char==0) || (strchr_w("hsx",last_char)==NULL))
  960. TranslateRules(tr, &word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
  961. else
  962. TranslateRules(tr, &word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
  963. }
  964. wflags |= emphasize_allcaps;
  965. /* determine stress pattern for this word */
  966. /******************************************/
  967. /* NOTE: this also adds a single PAUSE if the previous word ended
  968. in a primary stress, and this one starts with one */
  969. if(prefix_flags || (strchr(prefix_phonemes,phonSTRESS_P)!=NULL))
  970. {
  971. if((tr->langopts.param[LOPT_PREFIXES]) || (prefix_type & SUFX_T))
  972. {
  973. char *p;
  974. // German, keep a secondary stress on the stem
  975. SetWordStress(tr, phonemes, dictionary_flags, 3, 0);
  976. // reduce all but the first primary stress
  977. ix=0;
  978. for(p=prefix_phonemes; *p != 0; p++)
  979. {
  980. if(*p == phonSTRESS_P)
  981. {
  982. if(ix==0)
  983. ix=1;
  984. else
  985. *p = phonSTRESS_3;
  986. }
  987. }
  988. #ifdef PLATFORM_WINDOWS
  989. sprintf(word_phonemes, "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  990. #else
  991. snprintf(word_phonemes, sizeof(word_phonemes), "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  992. #endif
  993. word_phonemes[N_WORD_PHONEMES-1] = 0;
  994. SetWordStress(tr, word_phonemes, dictionary_flags, -1, 0);
  995. }
  996. else
  997. {
  998. // stress position affects the whole word, including prefix
  999. #ifdef PLATFORM_WINDOWS
  1000. sprintf(word_phonemes, "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1001. #else
  1002. snprintf(word_phonemes, sizeof(word_phonemes), "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1003. #endif
  1004. word_phonemes[N_WORD_PHONEMES-1] = 0;
  1005. SetWordStress(tr, word_phonemes, dictionary_flags, -1, tr->prev_last_stress);
  1006. }
  1007. }
  1008. else
  1009. {
  1010. if(prefix_phonemes[0] == 0)
  1011. SetWordStress(tr, phonemes, dictionary_flags, -1, tr->prev_last_stress);
  1012. else
  1013. SetWordStress(tr, phonemes, dictionary_flags, -1, 0);
  1014. #ifdef PLATFORM_WINDOWS
  1015. sprintf(word_phonemes, "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1016. #else
  1017. snprintf(word_phonemes, sizeof(word_phonemes), "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1018. #endif
  1019. word_phonemes[N_WORD_PHONEMES-1] = 0;
  1020. }
  1021. if(end_phonemes[0] != 0)
  1022. {
  1023. // a suffix had the SUFX_T option set, add the suffix after the stress pattern has been determined
  1024. ix = strlen(word_phonemes);
  1025. end_phonemes[N_WORD_PHONEMES-1-ix] = 0; // ensure no buffer overflow
  1026. strcpy(&word_phonemes[ix], end_phonemes);
  1027. }
  1028. if(wflags & FLAG_LAST_WORD)
  1029. {
  1030. // don't use $brk pause before the last word of a sentence
  1031. // (but allow it for emphasis, see below
  1032. dictionary_flags[0] &= ~FLAG_PAUSE1;
  1033. }
  1034. if((wflags & FLAG_HYPHEN) && (tr->langopts.stress_flags & S_HYPEN_UNSTRESS))
  1035. {
  1036. ChangeWordStress(tr,word_phonemes,3);
  1037. }
  1038. else
  1039. if(wflags & FLAG_EMPHASIZED2)
  1040. {
  1041. // A word is indicated in the source text as stressed
  1042. // Give it stress level 6 (for the intonation module)
  1043. ChangeWordStress(tr,word_phonemes,6);
  1044. if(wflags & FLAG_EMPHASIZED)
  1045. dictionary_flags[0] |= FLAG_PAUSE1; // precede by short pause
  1046. }
  1047. else
  1048. if(wtab[dictionary_skipwords].flags & FLAG_LAST_WORD)
  1049. {
  1050. // the word has attribute to stress or unstress when at end of clause
  1051. if(dictionary_flags[0] & (FLAG_STRESS_END | FLAG_STRESS_END2))
  1052. ChangeWordStress(tr,word_phonemes,4);
  1053. else
  1054. if((dictionary_flags[0] & FLAG_UNSTRESS_END) && (any_stressed_words))
  1055. ChangeWordStress(tr,word_phonemes,3);
  1056. }
  1057. // dictionary flags for this word give a clue about which alternative pronunciations of
  1058. // following words to use.
  1059. if(end_type & SUFX_F)
  1060. {
  1061. // expect a verb form, with or without -s suffix
  1062. tr->expect_verb = 2;
  1063. tr->expect_verb_s = 2;
  1064. }
  1065. if(dictionary_flags[1] & FLAG_PASTF)
  1066. {
  1067. /* expect perfect tense in next two words */
  1068. tr->expect_past = 3;
  1069. tr->expect_verb = 0;
  1070. tr->expect_noun = 0;
  1071. }
  1072. else
  1073. if(dictionary_flags[1] & FLAG_VERBF)
  1074. {
  1075. /* expect a verb in the next word */
  1076. tr->expect_verb = 2;
  1077. tr->expect_verb_s = 0; /* verb won't have -s suffix */
  1078. tr->expect_noun = 0;
  1079. }
  1080. else
  1081. if(dictionary_flags[1] & FLAG_VERBSF)
  1082. {
  1083. // expect a verb, must have a -s suffix
  1084. tr->expect_verb = 0;
  1085. tr->expect_verb_s = 2;
  1086. tr->expect_past = 0;
  1087. tr->expect_noun = 0;
  1088. }
  1089. else
  1090. if(dictionary_flags[1] & FLAG_NOUNF)
  1091. {
  1092. /* not expecting a verb next */
  1093. tr->expect_noun = 2;
  1094. tr->expect_verb = 0;
  1095. tr->expect_verb_s = 0;
  1096. tr->expect_past = 0;
  1097. }
  1098. if((wordx[0] != 0) && (!(dictionary_flags[1] & FLAG_VERB_EXT)))
  1099. {
  1100. if(tr->expect_verb > 0)
  1101. tr->expect_verb--;
  1102. if(tr->expect_verb_s > 0)
  1103. tr->expect_verb_s--;
  1104. if(tr->expect_noun >0)
  1105. tr->expect_noun--;
  1106. if(tr->expect_past > 0)
  1107. tr->expect_past--;
  1108. }
  1109. if((word_length == 1) && (tr->translator_name == L('e','n')) && iswalpha(first_char) && (first_char != 'i'))
  1110. {
  1111. // English Specific !!!!
  1112. // any single letter before a dot is an abbreviation, except 'I'
  1113. dictionary_flags[0] |= FLAG_ALLOW_DOT;
  1114. }
  1115. if((tr->langopts.param[LOPT_ALT] & 2) && ((dictionary_flags[0] & (FLAG_ALT_TRANS | FLAG_ALT2_TRANS)) != 0))
  1116. {
  1117. ApplySpecialAttribute2(tr,word_phonemes,dictionary_flags[0]);
  1118. }
  1119. return(dictionary_flags[0]);
  1120. } // end of TranslateWord
  1121. static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode)
  1122. {//==========================================================
  1123. p->phcode = phcode;
  1124. p->stresslevel = 0;
  1125. p->tone_ph = 0;
  1126. p->synthflags = embedded_flag;
  1127. p->sourceix = 0;
  1128. embedded_flag = 0;
  1129. }
  1130. static int CountSyllables(unsigned char *phonemes)
  1131. {//===============================================
  1132. int count = 0;
  1133. int phon;
  1134. while((phon = *phonemes++) != 0)
  1135. {
  1136. if(phoneme_tab[phon]->type == phVOWEL)
  1137. count++;
  1138. }
  1139. return(count);
  1140. }
  1141. int SetTranslator2(const char *new_language)
  1142. {//=========================================
  1143. // Set translator2 to a second language
  1144. int new_phoneme_tab;
  1145. if((new_phoneme_tab = SelectPhonemeTableName(new_language)) >= 0)
  1146. {
  1147. if((translator2 != NULL) && (strcmp(new_language,translator2_language) != 0))
  1148. {
  1149. // we already have an alternative translator, but not for the required language, delete it
  1150. DeleteTranslator(translator2);
  1151. translator2 = NULL;
  1152. }
  1153. if(translator2 == NULL)
  1154. {
  1155. translator2 = SelectTranslator(new_language);
  1156. strcpy(translator2_language,new_language);
  1157. if(LoadDictionary(translator2, new_language, 0) != 0)
  1158. {
  1159. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  1160. new_phoneme_tab = -1;
  1161. translator2_language[0] = 0;
  1162. }
  1163. }
  1164. }
  1165. return(new_phoneme_tab);
  1166. } // end of SetTranslator2
  1167. static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pause, int next_pause)
  1168. {//=================================================================================================
  1169. int flags=0;
  1170. int stress;
  1171. int next_stress;
  1172. int next_tone=0;
  1173. unsigned char *p;
  1174. int srcix;
  1175. int embedded_cmd;
  1176. int value;
  1177. int found_dict_flag;
  1178. unsigned char ph_code;
  1179. PHONEME_LIST2 *plist2;
  1180. PHONEME_TAB *ph;
  1181. int max_stress;
  1182. int max_stress_ix=0;
  1183. int prev_vowel = -1;
  1184. int pitch_raised = 0;
  1185. int switch_phonemes = -1;
  1186. int first_phoneme = 1;
  1187. int source_ix;
  1188. int len;
  1189. int ix;
  1190. int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
  1191. const char *new_language;
  1192. unsigned char bad_phoneme[4];
  1193. int word_flags;
  1194. int word_copy_len;
  1195. char word_copy[N_WORD_BYTES+1];
  1196. len = wtab->length;
  1197. if(len > 31) len = 31;
  1198. source_ix = (wtab->sourceix & 0x7ff) | (len << 11); // bits 0-10 sourceix, bits 11-15 word length
  1199. word_flags = wtab[0].flags;
  1200. if(word_flags & FLAG_EMBEDDED)
  1201. {
  1202. embedded_flag = SFLAG_EMBEDDED;
  1203. do
  1204. {
  1205. embedded_cmd = embedded_list[embedded_read++];
  1206. value = embedded_cmd >> 8;
  1207. switch(embedded_cmd & 0x1f)
  1208. {
  1209. case EMBED_Y:
  1210. option_sayas = value;
  1211. break;
  1212. case EMBED_F:
  1213. option_emphasis = value;
  1214. break;
  1215. case EMBED_B:
  1216. // break command
  1217. if(value == 0)
  1218. pre_pause = 0; // break=none
  1219. else
  1220. pre_pause += value;
  1221. break;
  1222. }
  1223. } while((embedded_cmd & 0x80) == 0);
  1224. }
  1225. if(word[0] == 0)
  1226. {
  1227. // nothing to translate
  1228. word_phonemes[0] = 0;
  1229. return(0);
  1230. }
  1231. // after a $pause word attribute, ignore a $pause attribute on the next two words
  1232. if(tr->prepause_timeout > 0)
  1233. tr->prepause_timeout--;
  1234. if((option_sayas & 0xf0) == 0x10)
  1235. {
  1236. if(!(word_flags & FLAG_FIRST_WORD))
  1237. {
  1238. // SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
  1239. pre_pause += 4;
  1240. }
  1241. }
  1242. if(word_flags & FLAG_FIRST_UPPER)
  1243. {
  1244. if((option_capitals > 2) && (embedded_ix < N_EMBEDDED_LIST-6))
  1245. {
  1246. // indicate capital letter by raising pitch
  1247. if(embedded_flag)
  1248. embedded_list[embedded_ix-1] &= ~0x80; // already embedded command before this word, remove terminator
  1249. if((pitch_raised = option_capitals) == 3)
  1250. pitch_raised = 20; // default pitch raise for capitals
  1251. embedded_list[embedded_ix++] = EMBED_P+0x40+0x80 + (pitch_raised << 8); // raise pitch
  1252. embedded_flag = SFLAG_EMBEDDED;
  1253. }
  1254. }
  1255. p = (unsigned char *)word_phonemes;
  1256. if(word_flags & FLAG_PHONEMES)
  1257. {
  1258. // The input is in phoneme mnemonics, not language text
  1259. int c1;
  1260. char lang_name[12];
  1261. if(memcmp(word,"_^_",3)==0)
  1262. {
  1263. // switch languages
  1264. word+=3;
  1265. for(ix=0;;)
  1266. {
  1267. c1 = *word++;
  1268. if((c1==' ') || (c1==0))
  1269. break;
  1270. lang_name[ix++] = tolower(c1);
  1271. }
  1272. lang_name[ix] = 0;
  1273. if((ix = LookupPhonemeTable(lang_name)) > 0)
  1274. {
  1275. SelectPhonemeTable(ix);
  1276. word_phonemes[0] = phonSWITCH;
  1277. word_phonemes[1] = ix;
  1278. word_phonemes[2] = 0;
  1279. }
  1280. }
  1281. else
  1282. {
  1283. EncodePhonemes(word,word_phonemes,bad_phoneme);
  1284. }
  1285. flags = FLAG_FOUND;
  1286. }
  1287. else
  1288. {
  1289. int c2;
  1290. ix = 0;
  1291. while(((c2 = word_copy[ix] = word[ix]) != ' ') && (c2 != 0) && (ix < N_WORD_BYTES)) ix++;
  1292. word_copy_len = ix;
  1293. flags = TranslateWord(translator, word, next_pause, wtab);
  1294. if(flags & FLAG_SPELLWORD)
  1295. {
  1296. // re-translate the word as individual letters, separated by spaces
  1297. memcpy(word, word_copy, word_copy_len);
  1298. return(flags);
  1299. }
  1300. if(flags & FLAG_COMBINE)
  1301. {
  1302. char *p2;
  1303. int ok = 1;
  1304. int flags2;
  1305. int c_word2;
  1306. char ph_buf[N_WORD_PHONEMES];
  1307. sylimit = tr->langopts.param[LOPT_COMBINE_WORDS];
  1308. // LANG=cs,sk
  1309. // combine a preposition with the following word
  1310. p2 = word;
  1311. while(*p2 != ' ') p2++;
  1312. utf8_in(&c_word2, p2+1); // first character of the next word;
  1313. if(!iswalpha(c_word2))
  1314. {
  1315. ok =0;
  1316. }
  1317. if(ok != 0)
  1318. {
  1319. if(sylimit & 0x100)
  1320. {
  1321. // only if the second word has $alt attribute
  1322. strcpy(ph_buf,word_phonemes);
  1323. flags2 = TranslateWord(translator, p2+1, 0, wtab+1);
  1324. if((flags2 & FLAG_ALT_TRANS) == 0)
  1325. {
  1326. ok = 0;
  1327. strcpy(word_phonemes,ph_buf);
  1328. }
  1329. }
  1330. if((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD))
  1331. {
  1332. // not if the next word is end-of-sentence
  1333. ok = 0;
  1334. }
  1335. }
  1336. if(ok)
  1337. {
  1338. *p2 = '-'; // replace next space by hyphen
  1339. flags = TranslateWord(translator, word, next_pause, wtab); // translate the combined word
  1340. if((sylimit > 0) && (CountSyllables(p) > (sylimit & 0x1f)))
  1341. {
  1342. // revert to separate words
  1343. *p2 = ' ';
  1344. flags = TranslateWord(translator, word, next_pause, wtab);
  1345. }
  1346. else
  1347. {
  1348. flags |= FLAG_SKIPWORDS;
  1349. dictionary_skipwords = 1;
  1350. }
  1351. }
  1352. }
  1353. if(p[0] == phonSWITCH)
  1354. {
  1355. // this word uses a different language
  1356. memcpy(word, word_copy, word_copy_len);
  1357. new_language = (char *)(&p[1]);
  1358. if(new_language[0]==0)
  1359. new_language = "en";
  1360. switch_phonemes = SetTranslator2(new_language);
  1361. if(switch_phonemes >= 0)
  1362. {
  1363. // re-translate the word using the new translator
  1364. flags = TranslateWord(translator2, word, next_pause, wtab);
  1365. // strcpy((char *)p,translator2->word_phonemes);
  1366. if(p[0] == phonSWITCH)
  1367. {
  1368. // the second translator doesn't want to process this word
  1369. switch_phonemes = -1;
  1370. }
  1371. }
  1372. if(switch_phonemes < 0)
  1373. {
  1374. // language code is not recognised or 2nd translator won't translate it
  1375. p[0] = phonSCHWA; // just say something
  1376. p[1] = phonSCHWA;
  1377. p[2] = 0;
  1378. }
  1379. }
  1380. if(!(word_flags & FLAG_HYPHEN))
  1381. {
  1382. if(flags & FLAG_PAUSE1)
  1383. {
  1384. if(pre_pause < 1)
  1385. pre_pause = 1;
  1386. }
  1387. if((flags & FLAG_PREPAUSE) && ((word_flags && FLAG_LAST_WORD) == 0) && (tr->prepause_timeout == 0))
  1388. {
  1389. // the word is marked in the dictionary list with $pause
  1390. if(pre_pause < 4) pre_pause = 4;
  1391. tr->prepause_timeout = 3;
  1392. }
  1393. }
  1394. if((option_emphasis >= 3) && (pre_pause < 1))
  1395. pre_pause = 1;
  1396. }
  1397. plist2 = &ph_list2[n_ph_list2];
  1398. stress = 0;
  1399. next_stress = 1;
  1400. srcix = 0;
  1401. max_stress = -1;
  1402. found_dict_flag = 0;
  1403. if((flags & FLAG_FOUND) && !(flags & FLAG_TEXTMODE))
  1404. found_dict_flag = SFLAG_DICTIONARY;
  1405. while((pre_pause > 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1406. {
  1407. // add pause phonemes here. Either because of punctuation (brackets or quotes) in the
  1408. // text, or because the word is marked in the dictionary lookup as a conjunction
  1409. if(pre_pause > 1)
  1410. {
  1411. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE);
  1412. pre_pause -= 2;
  1413. }
  1414. else
  1415. {
  1416. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_NOLINK);
  1417. pre_pause--;
  1418. }
  1419. tr->end_stressed_vowel = 0; // forget about the previous word
  1420. tr->prev_dict_flags = 0;
  1421. }
  1422. if((option_capitals==1) && (word_flags & FLAG_FIRST_UPPER))
  1423. {
  1424. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1425. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1426. if((word_flags & FLAG_ALL_UPPER) && IsAlpha(word[1]))
  1427. {
  1428. // word > 1 letter and all capitals
  1429. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1430. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1431. }
  1432. }
  1433. if(switch_phonemes >= 0)
  1434. {
  1435. // this word uses a different phoneme table
  1436. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1437. ph_list2[n_ph_list2++].tone_ph = switch_phonemes; // temporary phoneme table number
  1438. }
  1439. // remove initial pause from a word if it follows a hyphen
  1440. if((word_flags & FLAG_HYPHEN) && (phoneme_tab[*p]->type == phPAUSE))
  1441. p++;
  1442. while(((ph_code = *p++) != 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1443. {
  1444. if(ph_code == 255)
  1445. continue; // unknown phoneme
  1446. // Add the phonemes to the first stage phoneme list (ph_list2)
  1447. ph = phoneme_tab[ph_code];
  1448. if(ph_code == phonSWITCH)
  1449. {
  1450. ph_list2[n_ph_list2].phcode = ph_code;
  1451. ph_list2[n_ph_list2].sourceix = 0;
  1452. ph_list2[n_ph_list2].synthflags = embedded_flag;
  1453. ph_list2[n_ph_list2++].tone_ph = *p++;
  1454. }
  1455. else
  1456. if(ph->type == phSTRESS)
  1457. {
  1458. // don't add stress phonemes codes to the list, but give their stress
  1459. // value to the next vowel phoneme
  1460. // std_length is used to hold stress number or (if >10) a tone number for a tone language
  1461. if(ph->program == 0)
  1462. next_stress = ph->std_length;
  1463. else
  1464. {
  1465. // for tone languages, the tone number for a syllable follows the vowel
  1466. if(prev_vowel >= 0)
  1467. {
  1468. ph_list2[prev_vowel].tone_ph = ph_code;
  1469. }
  1470. else
  1471. {
  1472. next_tone = ph_code; // no previous vowel, apply to the next vowel
  1473. }
  1474. }
  1475. }
  1476. else
  1477. if(ph_code == phonSYLLABIC)
  1478. {
  1479. // mark the previous phoneme as a syllabic consonant
  1480. prev_vowel = n_ph_list2-1;
  1481. ph_list2[prev_vowel].synthflags |= SFLAG_SYLLABLE;
  1482. ph_list2[prev_vowel].stresslevel = next_stress;
  1483. }
  1484. else
  1485. if(ph_code == phonLENGTHEN)
  1486. {
  1487. ph_list2[n_ph_list2-1].synthflags |= SFLAG_LENGTHEN;
  1488. }
  1489. else
  1490. if(ph_code == phonEND_WORD)
  1491. {
  1492. // a || symbol in a phoneme string was used to indicate a word boundary
  1493. // Don't add this phoneme to the list, but make sure the next phoneme has
  1494. // a newword indication
  1495. srcix = source_ix+1;
  1496. }
  1497. else
  1498. if(ph_code == phonX1)
  1499. {
  1500. // a language specific action
  1501. if(tr->langopts.param[LOPT_IT_DOUBLING])
  1502. {
  1503. flags |= FLAG_DOUBLING;
  1504. }
  1505. }
  1506. else
  1507. {
  1508. ph_list2[n_ph_list2].phcode = ph_code;
  1509. ph_list2[n_ph_list2].tone_ph = 0;
  1510. ph_list2[n_ph_list2].synthflags = embedded_flag | found_dict_flag;
  1511. embedded_flag = 0;
  1512. ph_list2[n_ph_list2].sourceix = srcix;
  1513. srcix = 0;
  1514. if(ph->type == phVOWEL)
  1515. {
  1516. stress = next_stress;
  1517. next_stress = 1; // default is 'unstressed'
  1518. if(stress >= 4)
  1519. {
  1520. any_stressed_words = 1;
  1521. }
  1522. if((prev_vowel >= 0) && (n_ph_list2-1) != prev_vowel)
  1523. ph_list2[n_ph_list2-1].stresslevel = stress; // set stress for previous consonant
  1524. ph_list2[n_ph_list2].synthflags |= SFLAG_SYLLABLE;
  1525. prev_vowel = n_ph_list2;
  1526. if(stress > max_stress)
  1527. {
  1528. max_stress = stress;
  1529. max_stress_ix = n_ph_list2;
  1530. }
  1531. if(next_tone != 0)
  1532. {
  1533. ph_list2[n_ph_list2].tone_ph = next_tone;
  1534. next_tone=0;
  1535. }
  1536. }
  1537. else
  1538. {
  1539. if(first_phoneme && tr->langopts.param[LOPT_IT_DOUBLING])
  1540. {
  1541. if(((tr->prev_dict_flags & FLAG_DOUBLING) && (tr->langopts.param[LOPT_IT_DOUBLING] & 1)) ||
  1542. (tr->end_stressed_vowel && (tr->langopts.param[LOPT_IT_DOUBLING] & 2)))
  1543. {
  1544. // italian, double the initial consonant if the previous word ends with a
  1545. // stressed vowel, or is marked with a flag
  1546. ph_list2[n_ph_list2].synthflags |= SFLAG_LENGTHEN;
  1547. }
  1548. }
  1549. }
  1550. ph_list2[n_ph_list2].stresslevel = stress;
  1551. n_ph_list2++;
  1552. first_phoneme = 0;
  1553. }
  1554. }
  1555. if(word_flags & FLAG_COMMA_AFTER)
  1556. {
  1557. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_CLAUSE);
  1558. }
  1559. // don't set new-word if there is a hyphen before it
  1560. if((word_flags & FLAG_HYPHEN) == 0)
  1561. {
  1562. plist2->sourceix = source_ix;
  1563. }
  1564. tr->end_stressed_vowel = 0;
  1565. if((stress >= 4) && (phoneme_tab[ph_list2[n_ph_list2-1].phcode]->type == phVOWEL))
  1566. {
  1567. tr->end_stressed_vowel = 1; // word ends with a stressed vowel
  1568. }
  1569. if(switch_phonemes >= 0)
  1570. {
  1571. // this word uses a different phoneme table, now switch back
  1572. SelectPhonemeTable(voice->phoneme_tab_ix);
  1573. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1574. ph_list2[n_ph_list2++].tone_ph = voice->phoneme_tab_ix; // original phoneme table number
  1575. }
  1576. if(pitch_raised > 0)
  1577. {
  1578. embedded_list[embedded_ix++] = EMBED_P+0x60+0x80 + (pitch_raised << 8); // lower pitch
  1579. SetPlist2(&ph_list2[n_ph_list2],phonPAUSE_SHORT);
  1580. ph_list2[n_ph_list2++].synthflags = SFLAG_EMBEDDED;
  1581. }
  1582. if(flags & FLAG_STRESS_END2)
  1583. {
  1584. // this's word's stress could be increased later
  1585. ph_list2[max_stress_ix].synthflags |= SFLAG_PROMOTE_STRESS;
  1586. }
  1587. tr->prev_dict_flags = flags;
  1588. return(flags);
  1589. } // end of TranslateWord2
  1590. static int EmbeddedCommand(unsigned int &source_index)
  1591. {//===================================================
  1592. // An embedded command to change the pitch, volume, etc.
  1593. // returns number of commands added to embedded_list
  1594. // pitch,speed,amplitude,expression,reverb,tone,voice,sayas
  1595. const char *commands = "PSARHTIVYMUBF";
  1596. int value = -1;
  1597. int sign = 0;
  1598. unsigned char c;
  1599. char *p;
  1600. int cmd;
  1601. c = source[source_index];
  1602. if(c == '+')
  1603. {
  1604. sign = 0x40;
  1605. source_index++;
  1606. }
  1607. else
  1608. if(c == '-')
  1609. {
  1610. sign = 0x60;
  1611. source_index++;
  1612. }
  1613. if(isdigit(source[source_index]))
  1614. {
  1615. value = atoi(&source[source_index]);
  1616. while(isdigit(source[source_index]))
  1617. source_index++;
  1618. }
  1619. c = source[source_index++];
  1620. if(embedded_ix >= (N_EMBEDDED_LIST - 2))
  1621. return(0); // list is full
  1622. if((p = strchr_w(commands,c)) == NULL)
  1623. return(0);
  1624. cmd = (p - commands)+1;
  1625. if(value == -1)
  1626. {
  1627. value = embedded_default[cmd];
  1628. sign = 0;
  1629. }
  1630. if(cmd == EMBED_Y)
  1631. {
  1632. option_sayas2 = value;
  1633. count_sayas_digits = 0;
  1634. }
  1635. if(cmd == EMBED_F)
  1636. {
  1637. if(value >= 3)
  1638. word_emphasis = FLAG_EMPHASIZED;
  1639. else
  1640. word_emphasis = 0;
  1641. }
  1642. embedded_list[embedded_ix++] = cmd + sign + (value << 8);
  1643. return(1);
  1644. } // end of EmbeddedCommand
  1645. static int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, int *insert)
  1646. {//=========================================================================================
  1647. int ix;
  1648. unsigned int word;
  1649. unsigned int new_c, c2, c_lower;
  1650. int upper_case = 0;
  1651. static int ignore_next = 0;
  1652. const unsigned int *replace_chars;
  1653. if(ignore_next)
  1654. {
  1655. ignore_next = 0;
  1656. return(8);
  1657. }
  1658. if(c == 0) return(0);
  1659. if((replace_chars = tr->langopts.replace_chars) == NULL)
  1660. return(c);
  1661. // there is a list of character codes to be substituted with alternative codes
  1662. if(iswupper(c_lower = c))
  1663. {
  1664. c_lower = towlower(c);
  1665. upper_case = 1;
  1666. }
  1667. new_c = 0;
  1668. for(ix=0; (word = replace_chars[ix]) != 0; ix+=2)
  1669. {
  1670. if(c_lower == (word & 0xffff))
  1671. {
  1672. if((word >> 16) == 0)
  1673. {
  1674. new_c = replace_chars[ix+1];
  1675. break;
  1676. }
  1677. if((word >> 16) == (unsigned int)towlower(next_in))
  1678. {
  1679. new_c = replace_chars[ix+1];
  1680. ignore_next = 1;
  1681. break;
  1682. }
  1683. }
  1684. }
  1685. if(new_c == 0)
  1686. return(c); // no substitution
  1687. if(new_c & 0xffe00000)
  1688. {
  1689. // there is a second character to be inserted
  1690. // don't convert the case of the second character unless the next letter is also upper case
  1691. c2 = new_c >> 16;
  1692. if(upper_case && iswupper(next_in))
  1693. c2 = towupper(c2);
  1694. *insert = c2;
  1695. new_c &= 0xffff;
  1696. }
  1697. if(upper_case)
  1698. new_c = towupper(new_c);
  1699. return(new_c);
  1700. }
  1701. static int TranslateChar(Translator *tr, char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert)
  1702. {//================================================================================================================
  1703. // To allow language specific examination and replacement of characters
  1704. int code;
  1705. int initial;
  1706. int medial;
  1707. int final;
  1708. int next2;
  1709. static const unsigned char hangul_compatibility[0x34] = {
  1710. 0, 0x00,0x01,0xaa,0x02,0xac,0xad,0x03,
  1711. 0x04,0x05,0xb0,0xb1,0xb2,0xb3,0xb4,0xb4,
  1712. 0xb6,0x06,0x07,0x08,0xb9,0x09,0x0a,0xbc,
  1713. 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x61,
  1714. 0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
  1715. 0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,
  1716. 0x72,0x73,0x74,0x75 };
  1717. switch(tr->translator_name)
  1718. {
  1719. case L('a','f'):
  1720. // look for 'n and replace by a special character (unicode: schwa)
  1721. utf8_in(&next2, &ptr[1]);
  1722. if(!iswalpha(prev_in))
  1723. {
  1724. if((c == '\'') && (next_in == 'n') && IsSpace(next2))
  1725. {
  1726. // n preceded by either apostrophe or U2019 "right single quotation mark"
  1727. ptr[0] = ' '; // delete the n
  1728. return(0x0259); // replace ' by unicode schwa character
  1729. }
  1730. }
  1731. break;
  1732. case L('k','o'):
  1733. if(((code = c - 0xac00) >= 0) && (c <= 0xd7af))
  1734. {
  1735. // break a syllable hangul into 2 or 3 individual jamo
  1736. initial = (code/28)/21;
  1737. medial = (code/28) % 21;
  1738. final = code % 28;
  1739. if(initial == 11)
  1740. {
  1741. // null initial
  1742. c = medial + 0x1161;
  1743. if(final > 0)
  1744. *insert = final + 0x11a7;
  1745. }
  1746. else
  1747. {
  1748. // extact the initial and insert the remainder with a null initial
  1749. c = initial + 0x1100;
  1750. *insert = (11*28*21) + (medial*28) + final + 0xac00;
  1751. }
  1752. return(c);
  1753. }
  1754. else
  1755. if(((code = c - 0x3130) >= 0) && (code < 0x34))
  1756. {
  1757. // Hangul compatibility jamo
  1758. return(hangul_compatibility[code] + 0x1100);
  1759. }
  1760. break;
  1761. }
  1762. return(SubstituteChar(tr,c,next_in,insert));
  1763. }
  1764. void *TranslateClause(Translator *tr, FILE *f_text, const void *vp_input, int *tone_out, char **voice_change)
  1765. {//==========================================================================================================
  1766. int ix;
  1767. int c;
  1768. int cc;
  1769. unsigned int source_index=0;
  1770. unsigned int prev_source_index=0;
  1771. int prev_in;
  1772. int prev_out=' ';
  1773. int prev_out2;
  1774. int prev_in2=0;
  1775. int prev_in_save=0;
  1776. int next_in;
  1777. int next_in_nbytes;
  1778. int char_inserted=0;
  1779. int clause_pause;
  1780. int pre_pause_add=0;
  1781. int word_mark = 0;
  1782. int all_upper_case=FLAG_ALL_UPPER;
  1783. int finished;
  1784. int single_quoted;
  1785. int phoneme_mode = 0;
  1786. int dict_flags = 0; // returned from dictionary lookup
  1787. int word_flags; // set here
  1788. int next_word_flags;
  1789. int embedded_count = 0;
  1790. int letter_count = 0;
  1791. int space_inserted = 0;
  1792. int syllable_marked = 0;
  1793. int decimal_sep_count = 0;
  1794. char *word;
  1795. char *p;
  1796. int j, k;
  1797. int n_digits;
  1798. int charix_top=0;
  1799. short charix[N_TR_SOURCE+4];
  1800. WORD_TAB words[N_CLAUSE_WORDS];
  1801. int word_count=0; // index into words
  1802. char sbuf[N_TR_SOURCE];
  1803. int terminator;
  1804. int tone;
  1805. int tone2;
  1806. p_textinput = (unsigned char *)vp_input;
  1807. p_wchar_input = (wchar_t *)vp_input;
  1808. embedded_ix = 0;
  1809. embedded_read = 0;
  1810. option_phoneme_input &= ~2; // clear bit 1 (temporary indication)
  1811. pre_pause = 0;
  1812. any_stressed_words = 0;
  1813. if((clause_start_char = count_characters) < 0)
  1814. clause_start_char = 0;
  1815. clause_start_word = count_words + 1;
  1816. for(ix=0; ix<N_TR_SOURCE; ix++)
  1817. charix[ix] = 0;
  1818. terminator = ReadClause(tr, f_text, source, charix, &charix_top, N_TR_SOURCE, &tone2);
  1819. charix[charix_top+1] = 0;
  1820. charix[charix_top+2] = 0x7fff;
  1821. charix[charix_top+3] = 0;
  1822. clause_pause = (terminator & 0xfff) * 10; // mS
  1823. tone = (terminator >> 12) & 0xf;
  1824. if(tone2 != 0)
  1825. {
  1826. // override the tone type
  1827. tone = tone2;
  1828. }
  1829. for(p=source; *p != 0; p++)
  1830. {
  1831. if(!isspace2(*p))
  1832. {
  1833. break;
  1834. }
  1835. }
  1836. if(*p == 0)
  1837. {
  1838. // No characters except spaces. This is not a sentence.
  1839. // Don't add this pause, just make up the previous pause to this value;
  1840. clause_pause -= max_clause_pause;
  1841. if(clause_pause < 0)
  1842. clause_pause = 0;
  1843. terminator &= ~CLAUSE_BIT_SENTENCE; // clear sentence bit
  1844. max_clause_pause += clause_pause;
  1845. }
  1846. else
  1847. {
  1848. max_clause_pause = clause_pause;
  1849. }
  1850. if(new_sentence)
  1851. {
  1852. count_sentences++;
  1853. if(skip_sentences > 0)
  1854. {
  1855. skip_sentences--;
  1856. if(skip_sentences == 0)
  1857. skipping_text = 0;
  1858. }
  1859. }
  1860. memset(&ph_list2[0],0,sizeof(ph_list2[0]));
  1861. ph_list2[0].phcode = phonPAUSE_SHORT;
  1862. n_ph_list2 = 1;
  1863. tr->prev_last_stress = 0;
  1864. tr->prepause_timeout = 0;
  1865. tr->expect_verb=0;
  1866. tr->expect_noun=0;
  1867. tr->expect_past=0;
  1868. tr->expect_verb_s=0;
  1869. tr->phonemes_repeat_count = 0;
  1870. tr->end_stressed_vowel=0;
  1871. tr->prev_dict_flags = 0;
  1872. word_count = 0;
  1873. single_quoted = 0;
  1874. word_flags = 0;
  1875. next_word_flags = 0;
  1876. sbuf[0] = 0;
  1877. sbuf[1] = ' ';
  1878. sbuf[2] = ' ';
  1879. ix = 3;
  1880. prev_in = ' ';
  1881. words[0].start = ix;
  1882. words[0].flags = 0;
  1883. finished = 0;
  1884. for(j=0; charix[j]==0; j++);
  1885. words[0].sourceix = charix[j];
  1886. k = 0;
  1887. while(charix[j] != 0)
  1888. {
  1889. // count the number of characters (excluding multibyte continuation bytes)
  1890. if(charix[j++] != -1)
  1891. k++;
  1892. }
  1893. words[0].length = k;
  1894. while(!finished && (ix < (int)sizeof(sbuf))&& (n_ph_list2 < N_PHONEME_LIST-4))
  1895. {
  1896. prev_out2 = prev_out;
  1897. utf8_in2(&prev_out,&sbuf[ix-1],1); // prev_out = sbuf[ix-1];
  1898. if(tr->langopts.tone_numbers && IsDigit09(prev_out) && IsAlpha(prev_out2))
  1899. {
  1900. // tone numbers can be part of a word, consider them as alphabetic
  1901. prev_out = 'a';
  1902. }
  1903. if(prev_in_save != 0)
  1904. {
  1905. prev_in = prev_in_save;
  1906. prev_in_save = 0;
  1907. }
  1908. else
  1909. if(source_index > 0)
  1910. {
  1911. prev_in2 = prev_in;
  1912. utf8_in2(&prev_in,&source[source_index-1],1); // prev_in = source[source_index-1];
  1913. }
  1914. prev_source_index = source_index;
  1915. if(char_inserted)
  1916. {
  1917. c = char_inserted;
  1918. char_inserted = 0;
  1919. }
  1920. else
  1921. {
  1922. source_index += utf8_in(&cc,&source[source_index]); // cc = source[source_index++];
  1923. c = cc;
  1924. }
  1925. next_in_nbytes = utf8_in(&next_in,&source[source_index]);
  1926. if((c == CTRL_EMBEDDED) || (c == ctrl_embedded))
  1927. {
  1928. // start of embedded command in the text
  1929. int srcix = source_index-1;
  1930. if(prev_in != ' ')
  1931. {
  1932. c = ' ';
  1933. prev_in_save = c;
  1934. source_index--;
  1935. }
  1936. else
  1937. {
  1938. embedded_count += EmbeddedCommand(source_index);
  1939. prev_in_save = prev_in;
  1940. // replace the embedded command by spaces
  1941. memset(&source[srcix],' ',source_index-srcix);
  1942. source_index = srcix;
  1943. continue;
  1944. }
  1945. }
  1946. if((option_sayas2 == SAYAS_KEY) && (c != ' '))
  1947. {
  1948. if((prev_in == ' ') && (next_in == ' '))
  1949. option_sayas2 = SAYAS_SINGLE_CHARS; // single character, speak its name
  1950. c = towlower2(c);
  1951. }
  1952. if(phoneme_mode)
  1953. {
  1954. all_upper_case = FLAG_PHONEMES;
  1955. if((c == ']') && (next_in == ']'))
  1956. {
  1957. phoneme_mode = 0;
  1958. source_index++;
  1959. c = ' ';
  1960. }
  1961. }
  1962. else
  1963. if((option_sayas2 & 0xf0) == SAYAS_DIGITS)
  1964. {
  1965. if(iswdigit(c))
  1966. {
  1967. count_sayas_digits++;
  1968. if(count_sayas_digits > (option_sayas2 & 0xf))
  1969. {
  1970. // break after the specified number of digits
  1971. c = ' ';
  1972. space_inserted = 1;
  1973. count_sayas_digits = 0;
  1974. }
  1975. }
  1976. else
  1977. {
  1978. count_sayas_digits = 0;
  1979. if(iswdigit(prev_out))
  1980. {
  1981. c = ' ';
  1982. space_inserted = 1;
  1983. }
  1984. }
  1985. }
  1986. else
  1987. if((option_sayas2 & 0x10) == 0)
  1988. {
  1989. // speak as words
  1990. #ifdef deleted
  1991. if((c == '/') && (tr->langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_out))
  1992. {
  1993. // TESTING, explicit indication of stressed syllable by /2 after the word
  1994. word_mark = next_in-'0';
  1995. source_index++;
  1996. c = ' ';
  1997. }
  1998. #endif
  1999. if((c == 0x92) || (c == 0xb4) || (c == 0x2019) || (c == 0x2032))
  2000. c = '\''; // 'microsoft' quote or sexed closing single quote, or prime - possibly used as apostrophe
  2001. if(((c == 0x2018) || (c == '?')) && IsAlpha(prev_out) && IsAlpha(next_in))
  2002. {
  2003. // ? between two letters may be a smart-quote replaced by ?
  2004. c = '\'';
  2005. }
  2006. if(c == CHAR_EMPHASIS)
  2007. {
  2008. // this character is a marker that the previous word is the focus of the clause
  2009. c = ' ';
  2010. word_flags |= FLAG_FOCUS;
  2011. }
  2012. if(c == CHAR_COMMA_BREAK)
  2013. {
  2014. c = ' ';
  2015. word_flags |= FLAG_COMMA_AFTER;
  2016. }
  2017. c = TranslateChar(tr, &source[source_index], prev_in,c, next_in, &char_inserted); // optional language specific function
  2018. if(c == 8)
  2019. continue; // ignore this character
  2020. if(char_inserted)
  2021. next_in = char_inserted;
  2022. // allow certain punctuation within a word (usually only apostrophe)
  2023. if(!IsAlpha(c) && !IsSpace(c) && (wcschr(tr->punct_within_word,c) == 0))
  2024. {
  2025. if(IsAlpha(prev_out))
  2026. {
  2027. if(tr->langopts.tone_numbers && IsDigit09(c) && !IsDigit09(next_in))
  2028. {
  2029. // allow a tone number as part of the word
  2030. }
  2031. else
  2032. {
  2033. c = ' '; // ensure we have an end-of-word terminator
  2034. space_inserted = 1;
  2035. }
  2036. }
  2037. }
  2038. if(iswdigit(prev_out))
  2039. {
  2040. if(!iswdigit(c) && (c != '.') && (c != ',') && (c != ' '))
  2041. {
  2042. c = ' '; // terminate digit string with a space
  2043. space_inserted = 1;
  2044. }
  2045. }
  2046. else
  2047. {
  2048. if(prev_in != ',')
  2049. {
  2050. decimal_sep_count = 0;
  2051. }
  2052. }
  2053. if((c == '[') && (next_in == '[') && option_phoneme_input)
  2054. {
  2055. phoneme_mode = FLAG_PHONEMES;
  2056. source_index++;
  2057. continue;
  2058. }
  2059. if(c == 0)
  2060. {
  2061. finished = 1;
  2062. c = ' ';
  2063. }
  2064. else
  2065. if(IsAlpha(c))
  2066. {
  2067. if(!IsAlpha(prev_out) || (tr->langopts.ideographs && ((c > 0x3040) || (prev_out > 0x3040))))
  2068. {
  2069. if(wcschr(tr->punct_within_word,prev_out) == 0)
  2070. letter_count = 0; // don't reset count for an apostrophy within a word
  2071. if((prev_out != ' ') && (wcschr(tr->punct_within_word,prev_out) == 0))
  2072. {
  2073. // start of word, insert space if not one there already
  2074. c = ' ';
  2075. space_inserted = 1;
  2076. if(!IsBracket(prev_out)) // ?? perhaps only set FLAG_NOSPACE for . - / (hyphenated words, URLs, etc)
  2077. {
  2078. next_word_flags |= FLAG_NOSPACE;
  2079. }
  2080. }
  2081. else
  2082. {
  2083. if(iswupper(c))
  2084. word_flags |= FLAG_FIRST_UPPER;
  2085. if((prev_out == ' ') && iswdigit(sbuf[ix-2]) && !iswdigit(prev_in))
  2086. {
  2087. // word, following a number, but with a space between
  2088. // Add an extra space, to distinguish "2 a" from "2a"
  2089. sbuf[ix++] = ' ';
  2090. words[word_count].start++;
  2091. }
  2092. }
  2093. }
  2094. letter_count++;
  2095. if(iswupper(c))
  2096. {
  2097. c = towlower2(c);
  2098. if((j = tr->langopts.param[LOPT_CAPS_IN_WORD]) > 0)
  2099. {
  2100. if((j == 2) && (syllable_marked == 0))
  2101. {
  2102. char_inserted = c;
  2103. c = 0x2c8; // stress marker
  2104. syllable_marked = 1;
  2105. }
  2106. }
  2107. else
  2108. {
  2109. if(iswlower(prev_in))
  2110. {
  2111. c = ' '; // lower case followed by upper case, treat as new word
  2112. space_inserted = 1;
  2113. prev_in_save = c;
  2114. }
  2115. else
  2116. if((c != ' ') && iswupper(prev_in) && iswlower(next_in))
  2117. {
  2118. int next2_in;
  2119. utf8_in(&next2_in,&source[source_index + next_in_nbytes]);
  2120. if(IsAlpha(next2_in))
  2121. {
  2122. // changing from upper to lower case, start new word at the last uppercase, if 3 or more letters
  2123. c = ' ';
  2124. space_inserted = 1;
  2125. prev_in_save = c;
  2126. next_word_flags |= FLAG_NOSPACE;
  2127. }
  2128. }
  2129. }
  2130. }
  2131. else
  2132. {
  2133. if((all_upper_case) && (letter_count > 2))
  2134. {
  2135. if((c == 's') && (next_in==' '))
  2136. {
  2137. c = ' ';
  2138. all_upper_case |= FLAG_HAS_PLURAL;
  2139. if(sbuf[ix-1] == '\'')
  2140. sbuf[ix-1] = ' ';
  2141. }
  2142. else
  2143. all_upper_case = 0; // current word contains lower case letters, not "'s"
  2144. }
  2145. else
  2146. all_upper_case = 0;
  2147. }
  2148. }
  2149. else
  2150. if(c=='-')
  2151. {
  2152. if(!IsSpace(prev_in) && IsAlpha(next_in))
  2153. {
  2154. if(prev_out != ' ')
  2155. {
  2156. // previous 'word' not yet ended (not alpha or numeric), start new word now.
  2157. c = ' ';
  2158. space_inserted = 1;
  2159. }
  2160. else
  2161. {
  2162. // '-' between two letters is a hyphen, treat as a space
  2163. word_flags |= FLAG_HYPHEN;
  2164. words[word_count-1].flags |= FLAG_HYPHEN_AFTER;
  2165. c = ' ';
  2166. }
  2167. }
  2168. else
  2169. if((prev_in==' ') && (next_in==' '))
  2170. {
  2171. // ' - ' dash between two spaces, treat as pause
  2172. c = ' ';
  2173. pre_pause_add = 4;
  2174. }
  2175. else
  2176. if(next_in=='-')
  2177. {
  2178. // double hyphen, treat as pause
  2179. source_index++;
  2180. c = ' ';
  2181. pre_pause_add = 4;
  2182. }
  2183. else
  2184. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  2185. {
  2186. // insert extra space between a word + space + hyphen, to distinguish 'a -2' from 'a-2'
  2187. sbuf[ix++] = ' ';
  2188. words[word_count].start++;
  2189. }
  2190. }
  2191. else
  2192. if(c == '.')
  2193. {
  2194. if(!(words[word_count-1].flags & FLAG_NOSPACE) && IsAlpha(prev_in))
  2195. {
  2196. // dot after a word, with space following, probably an abbreviation
  2197. words[word_count-1].flags |= FLAG_HAS_DOT;
  2198. if(IsSpace(next_in))
  2199. c = ' '; // remove the dot if it's followed by a space, so that it's not pronounced
  2200. }
  2201. }
  2202. else
  2203. if(c == '\'')
  2204. {
  2205. if(iswalnum(prev_in) && IsAlpha(next_in))
  2206. {
  2207. // between two letters, consider apostrophe as part of the word
  2208. single_quoted = 0;
  2209. }
  2210. else
  2211. if((wcschr(tr->char_plus_apostrophe,prev_in) != 0) && (prev_out2 == ' '))
  2212. {
  2213. // consider single character plus apostrophe as a word
  2214. single_quoted = 0;
  2215. if(next_in == ' ')
  2216. {
  2217. source_index++; // skip following space
  2218. }
  2219. }
  2220. else
  2221. {
  2222. if((prev_out == 's') && (single_quoted==0))
  2223. {
  2224. // looks like apostrophe after an 's'
  2225. c = ' ';
  2226. }
  2227. else
  2228. {
  2229. if(IsSpace(prev_out))
  2230. single_quoted = 1;
  2231. else
  2232. single_quoted = 0;
  2233. pre_pause_add = 4; // single quote
  2234. c = ' ';
  2235. }
  2236. }
  2237. }
  2238. else
  2239. #ifdef deleted
  2240. // Brackets are now recognised in TranslateRules()
  2241. if(IsBracket(c))
  2242. {
  2243. pre_pause_add = 4;
  2244. c = ' ';
  2245. }
  2246. else
  2247. #endif
  2248. if(lookupwchar(breaks,c) != 0)
  2249. {
  2250. c = ' '; // various characters to treat as space
  2251. }
  2252. else
  2253. if(iswdigit(c))
  2254. {
  2255. if(tr->langopts.tone_numbers && IsAlpha(prev_out) && !IsDigit(next_in))
  2256. {
  2257. }
  2258. else
  2259. if((prev_out != ' ') && !iswdigit(prev_out))
  2260. {
  2261. if((prev_out != tr->langopts.decimal_sep) || ((decimal_sep_count > 0) && (tr->langopts.decimal_sep == ',')))
  2262. {
  2263. c = ' ';
  2264. space_inserted = 1;
  2265. }
  2266. else
  2267. {
  2268. decimal_sep_count = 1;
  2269. }
  2270. }
  2271. else
  2272. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  2273. {
  2274. // insert extra space between a word and a number, to distinguish 'a 2' from 'a2'
  2275. sbuf[ix++] = ' ';
  2276. words[word_count].start++;
  2277. }
  2278. }
  2279. }
  2280. if(IsSpace(c))
  2281. {
  2282. if(prev_out == ' ')
  2283. {
  2284. word_flags |= FLAG_MULTIPLE_SPACES;
  2285. continue; // multiple spaces
  2286. }
  2287. if((cc == 0x09) || (cc == 0x0a))
  2288. {
  2289. next_word_flags |= FLAG_MULTIPLE_SPACES; // tab or newline, not a simple space
  2290. }
  2291. if(space_inserted)
  2292. {
  2293. words[word_count].length = source_index - words[word_count].sourceix;
  2294. }
  2295. // end of 'word'
  2296. sbuf[ix++] = ' ';
  2297. if((ix > words[word_count].start) && (word_count < N_CLAUSE_WORDS-1))
  2298. {
  2299. if(embedded_count > 0)
  2300. {
  2301. // there are embedded commands before this word
  2302. embedded_list[embedded_ix-1] |= 0x80; // terminate list of commands for this word
  2303. words[word_count].flags |= FLAG_EMBEDDED;
  2304. embedded_count = 0;
  2305. }
  2306. words[word_count].pre_pause = pre_pause;
  2307. words[word_count].flags |= (all_upper_case | word_flags | word_emphasis);
  2308. words[word_count].wmark = word_mark;
  2309. if(pre_pause > 0)
  2310. {
  2311. // insert an extra space before the word, to prevent influence from previous word across the pause
  2312. for(j=ix; j>words[word_count].start; j--)
  2313. {
  2314. sbuf[j] = sbuf[j-1];
  2315. }
  2316. sbuf[j] = ' ';
  2317. words[word_count].start++;
  2318. ix++;
  2319. }
  2320. word_count++;
  2321. words[word_count].start = ix;
  2322. words[word_count].flags = 0;
  2323. for(j=source_index; charix[j] <= 0; j++); // skip blanks
  2324. words[word_count].sourceix = charix[j];
  2325. k = 0;
  2326. while(charix[j] != 0)
  2327. {
  2328. // count the number of characters (excluding multibyte continuation bytes)
  2329. if(charix[j++] != -1)
  2330. k++;
  2331. }
  2332. words[word_count].length = k;
  2333. word_flags = next_word_flags;
  2334. next_word_flags = 0;
  2335. pre_pause = 0;
  2336. word_mark = 0;
  2337. all_upper_case = FLAG_ALL_UPPER;
  2338. syllable_marked = 0;
  2339. }
  2340. if(space_inserted)
  2341. {
  2342. source_index = prev_source_index; // rewind to the previous character
  2343. char_inserted = 0;
  2344. space_inserted = 0;
  2345. }
  2346. }
  2347. else
  2348. {
  2349. ix += utf8_out(c,&sbuf[ix]); // sbuf[ix++] = c;
  2350. }
  2351. if(pre_pause_add > pre_pause)
  2352. pre_pause = pre_pause_add;
  2353. pre_pause_add = 0;
  2354. }
  2355. if((word_count==0) && (embedded_count > 0))
  2356. {
  2357. // add a null 'word' to carry the embedded command flag
  2358. embedded_list[embedded_ix-1] |= 0x80;
  2359. words[word_count].flags |= FLAG_EMBEDDED;
  2360. word_count = 1;
  2361. }
  2362. tr->clause_end = &sbuf[ix-1];
  2363. sbuf[ix] = 0;
  2364. words[0].pre_pause = 0; // don't add extra pause at beginning of clause
  2365. words[word_count].pre_pause = 8;
  2366. if(word_count > 0)
  2367. {
  2368. words[word_count-1].flags |= FLAG_LAST_WORD;
  2369. // FLAG_NOSPACE check to avoid recognizing .mr -mr
  2370. if((terminator & CLAUSE_DOT) && !(words[word_count-1].flags & FLAG_NOSPACE))
  2371. words[word_count-1].flags |= FLAG_HAS_DOT;
  2372. }
  2373. words[0].flags |= FLAG_FIRST_WORD;
  2374. for(ix=0; ix<word_count; ix++)
  2375. {
  2376. int nx;
  2377. int c_temp;
  2378. char *pn;
  2379. char *pw;
  2380. int nw;
  2381. char number_buf[60];
  2382. WORD_TAB num_wtab[15]; // copy of 'words', when splitting numbers into parts
  2383. // start speaking at a specified word position in the text?
  2384. count_words++;
  2385. if(skip_words > 0)
  2386. {
  2387. skip_words--;
  2388. if(skip_words == 0)
  2389. skipping_text = 0;
  2390. }
  2391. if(skipping_text)
  2392. continue;
  2393. // digits should have been converted to Latin alphabet ('0' to '9')
  2394. word = pw = &sbuf[words[ix].start];
  2395. if(iswdigit(word[0]) && (tr->langopts.break_numbers != BREAK_THOUSANDS))
  2396. {
  2397. // Languages with 100000 numbers. Remove thousands separators so that we can insert them again later
  2398. pn = number_buf;
  2399. while(pn < &number_buf[sizeof(number_buf)-3])
  2400. {
  2401. if(iswdigit(*pw))
  2402. {
  2403. *pn++ = *pw++;
  2404. }
  2405. else
  2406. if((*pw == tr->langopts.thousands_sep) && (pw[1] == ' ') && iswdigit(pw[2]))
  2407. {
  2408. pw += 2;
  2409. ix++; // skip "word"
  2410. }
  2411. else
  2412. {
  2413. nx = pw - word;
  2414. memset(word,' ',nx);
  2415. nx = pn - number_buf;
  2416. memcpy(word,number_buf,nx);
  2417. break;
  2418. }
  2419. }
  2420. pw = word;
  2421. }
  2422. for(n_digits=0; iswdigit(word[n_digits]); n_digits++); // count consecutive digits
  2423. if((n_digits > 4) && (word[0] != '0'))
  2424. {
  2425. // word is entirely digits, insert commas and break into 3 digit "words"
  2426. number_buf[0] = ' ';
  2427. pn = &number_buf[1];
  2428. nx = n_digits;
  2429. nw = 0;
  2430. while(pn < &number_buf[sizeof(number_buf)-3])
  2431. {
  2432. if(!isdigit(c = *pw++) && (c != tr->langopts.decimal_sep))
  2433. break;
  2434. *pn++ = c;
  2435. if((--nx > 0) && (tr->langopts.break_numbers & (1 << nx)))
  2436. {
  2437. memcpy(&num_wtab[nw++], &words[ix], sizeof(WORD_TAB)); // copy the 'words' entry for each word of numbers
  2438. if(tr->langopts.thousands_sep != ' ')
  2439. {
  2440. *pn++ = tr->langopts.thousands_sep;
  2441. }
  2442. *pn++ = ' ';
  2443. if(tr->langopts.break_numbers & (1 << (nx-1)))
  2444. {
  2445. // the next group only has 1 digits (i.e. NUM2_10000), make it three
  2446. *pn++ = '0';
  2447. *pn++ = '0';
  2448. }
  2449. if(tr->langopts.break_numbers & (1 << (nx-2)))
  2450. {
  2451. // the next group only has 2 digits (i.e. NUM2_10000), make it three
  2452. *pn++ = '0';
  2453. }
  2454. }
  2455. }
  2456. pw--;
  2457. memcpy(&num_wtab[nw], &words[ix], sizeof(WORD_TAB)*2); // the original number word, and the word after it
  2458. // include the next few characters, in case there are an ordinal indicator or other suffix
  2459. memcpy(pn, pw, 16);
  2460. pn[16] = 0;
  2461. nw = 0;
  2462. for(pw = &number_buf[1]; pw < pn;)
  2463. {
  2464. // keep wflags for each part, for FLAG_HYPHEN_AFTER
  2465. dict_flags = TranslateWord2(tr, pw, &num_wtab[nw++], words[ix].pre_pause,0 );
  2466. while(*pw++ != ' ');
  2467. words[ix].pre_pause = 0;
  2468. }
  2469. }
  2470. else
  2471. {
  2472. pre_pause = 0;
  2473. dict_flags = TranslateWord2(tr, word, &words[ix], words[ix].pre_pause, words[ix+1].pre_pause);
  2474. if(pre_pause > words[ix+1].pre_pause)
  2475. {
  2476. words[ix+1].pre_pause = pre_pause;
  2477. pre_pause = 0;
  2478. }
  2479. if(dict_flags & FLAG_SPELLWORD)
  2480. {
  2481. // redo the word, speaking single letters
  2482. for(pw = word; *pw != ' ';)
  2483. {
  2484. memset(number_buf,' ',9);
  2485. nx = utf8_in(&c_temp, pw);
  2486. memcpy(&number_buf[2],pw,nx);
  2487. TranslateWord2(tr, &number_buf[2], &words[ix], 0, 0 );
  2488. pw += nx;
  2489. }
  2490. }
  2491. if((dict_flags & (FLAG_ALLOW_DOT | FLAG_NEEDS_DOT)) && (ix == word_count-1) && (terminator & CLAUSE_DOT))
  2492. {
  2493. // probably an abbreviation such as Mr. or B. rather than end of sentence
  2494. clause_pause = 10;
  2495. tone = 4;
  2496. }
  2497. }
  2498. if(dict_flags & FLAG_SKIPWORDS)
  2499. {
  2500. ix += dictionary_skipwords; // dictionary indicates skip next word(s)
  2501. }
  2502. }
  2503. for(ix=0; ix<2; ix++)
  2504. {
  2505. // terminate the clause with 2 PAUSE phonemes
  2506. PHONEME_LIST2 *p2;
  2507. p2 = &ph_list2[n_ph_list2 + ix];
  2508. p2->phcode = phonPAUSE;
  2509. p2->stresslevel = 0;
  2510. p2->sourceix = source_index;
  2511. p2->synthflags = 0;
  2512. }
  2513. n_ph_list2 += 2;
  2514. if(count_words == 0)
  2515. {
  2516. clause_pause = 0;
  2517. }
  2518. if(Eof() && ((word_count == 0) || (option_endpause==0)))
  2519. {
  2520. clause_pause = 10;
  2521. }
  2522. MakePhonemeList(tr, clause_pause, new_sentence);
  2523. if(embedded_count) // ???? is this needed
  2524. {
  2525. phoneme_list[n_phoneme_list-2].synthflags = SFLAG_EMBEDDED;
  2526. embedded_list[embedded_ix-1] |= 0x80;
  2527. }
  2528. prev_clause_pause = clause_pause;
  2529. *tone_out = tone;
  2530. new_sentence = 0;
  2531. if(terminator & CLAUSE_BIT_SENTENCE)
  2532. {
  2533. new_sentence = 1; // next clause is a new sentence
  2534. }
  2535. if(voice_change != NULL)
  2536. {
  2537. // return new voice name if an embedded voice change command terminated the clause
  2538. if(terminator & CLAUSE_BIT_VOICE)
  2539. *voice_change = &source[source_index];
  2540. else
  2541. *voice_change = NULL;
  2542. }
  2543. if(Eof() || (vp_input==NULL))
  2544. return(NULL);
  2545. if(option_multibyte == espeakCHARS_WCHAR)
  2546. return((void *)p_wchar_input);
  2547. else
  2548. return((void *)p_textinput);
  2549. } // end of TranslateClause
  2550. void InitText(int control)
  2551. {//=======================
  2552. count_sentences = 0;
  2553. count_words = 0;
  2554. end_character_position = 0;
  2555. skip_sentences = 0;
  2556. skip_marker[0] = 0;
  2557. skip_words = 0;
  2558. skip_characters = 0;
  2559. skipping_text = 0;
  2560. new_sentence = 1;
  2561. prev_clause_pause = 0;
  2562. option_sayas = 0;
  2563. option_sayas2 = 0;
  2564. option_emphasis = 0;
  2565. word_emphasis = 0;
  2566. embedded_flag = 0;
  2567. InitText2();
  2568. if((control & espeakKEEP_NAMEDATA) == 0)
  2569. {
  2570. InitNamedata();
  2571. }
  2572. }