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

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