eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

translate.c 94KB

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