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

translate.cpp 94KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2014 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #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 == 2)
  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 == 2)
  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. WORD_TAB wtab_null[8];
  733. // translate these to get pronunciations of plural 's' suffix (different forms depending on
  734. // the preceding letter
  735. static char word_zz[4] = {0,'z','z',0};
  736. static char word_iz[4] = {0,'i','z',0};
  737. static char word_ss[4] = {0,'s','s',0};
  738. if(wtab == NULL)
  739. {
  740. memset(wtab_null, 0, sizeof(wtab_null));
  741. wtab = wtab_null;
  742. }
  743. wflags = wtab->flags;
  744. wmark = wtab->wmark;
  745. dictionary_flags[0] = 0;
  746. dictionary_flags[1] = 0;
  747. dictionary_flags2[0] = 0;
  748. dictionary_flags2[1] = 0;
  749. dictionary_skipwords = 0;
  750. phonemes[0] = 0;
  751. unpron_phonemes[0] = 0;
  752. prefix_phonemes[0] = 0;
  753. end_phonemes[0] = 0;
  754. if(tr->data_dictlist == NULL)
  755. {
  756. // dictionary is not loaded
  757. word_phonemes[0] = 0;
  758. return(0);
  759. }
  760. // count the length of the word
  761. word1 = word_start;
  762. if(*word1 == ' ') word1++; // possibly a dot was replaced by space: $dot
  763. wordx = word1;
  764. utf8_in(&first_char,wordx);
  765. word_length = 0;
  766. while((*wordx != 0) && (*wordx != ' '))
  767. {
  768. wordx += utf8_in(&last_char,wordx);
  769. word_length++;
  770. }
  771. word_copy_length = wordx - word_start;
  772. if(word_copy_length >= N_WORD_BYTES)
  773. word_copy_length = N_WORD_BYTES-1;
  774. memcpy(word_copy2, word_start, word_copy_length);
  775. spell_word = 0;
  776. if((word_length == 1) && (wflags & FLAG_TRANSLATOR2))
  777. {
  778. // retranslating a 1-character word using a different language, say its name
  779. utf8_in(&c_temp, wordx+1); // the next character
  780. if(!IsAlpha(c_temp) || (AlphabetFromChar(last_char) != AlphabetFromChar(c_temp)))
  781. spell_word = 1;
  782. }
  783. if(option_sayas == SAYAS_KEY)
  784. {
  785. if(word_length == 1)
  786. spell_word = 4;
  787. else
  788. {
  789. // is there a translation for this keyname ?
  790. word1--;
  791. *word1 = '_'; // prefix keyname with '_'
  792. found = LookupDictList(tr, &word1, phonemes, dictionary_flags, 0, wtab);
  793. }
  794. }
  795. // try an initial lookup in the dictionary list, we may find a pronunciation specified, or
  796. // we may just find some flags
  797. if(option_sayas & 0x10)
  798. {
  799. // SAYAS_CHAR, SAYAS_GYLPH, or SAYAS_SINGLE_CHAR
  800. spell_word = option_sayas & 0xf; // 2,3,4
  801. }
  802. else
  803. {
  804. if(!found)
  805. found = LookupDictList(tr, &word1, phonemes, dictionary_flags, FLAG_ALLOW_TEXTMODE, wtab); // the original word
  806. if((dictionary_flags[0] & (FLAG_ALLOW_DOT | FLAG_NEEDS_DOT)) && (wordx[1] == '.'))
  807. {
  808. wordx[1] = ' '; // remove a Dot after this word
  809. }
  810. if(dictionary_flags[0] & FLAG_TEXTMODE)
  811. {
  812. if(word_out != NULL)
  813. strcpy(word_out, word1);
  814. first_char = word1[0];
  815. stress_bits = dictionary_flags[0] & 0x7f;
  816. found = LookupDictList(tr, &word1, phonemes, dictionary_flags2, 0, wtab); // the text replacement
  817. if(dictionary_flags2[0]!=0)
  818. {
  819. dictionary_flags[0] = dictionary_flags2[0];
  820. dictionary_flags[1] = dictionary_flags2[1];
  821. if(stress_bits != 0)
  822. {
  823. // keep any stress information from the original word
  824. dictionary_flags[0] = (dictionary_flags[0] & ~0x7f) | stress_bits;
  825. }
  826. }
  827. }
  828. else if((found==0) && (dictionary_flags[0] & FLAG_SKIPWORDS) && !(dictionary_flags[0] & FLAG_ABBREV))
  829. {
  830. // grouped words, but no translation. Join the words with hyphens.
  831. wordx = word1;
  832. ix = 0;
  833. while(ix < dictionary_skipwords)
  834. {
  835. if(*wordx == ' ')
  836. {
  837. *wordx = '-';
  838. ix++;
  839. }
  840. wordx++;
  841. }
  842. }
  843. if((word_length == 1) && (dictionary_skipwords == 0))
  844. {
  845. // is this a series of single letters separated by dots?
  846. if(CheckDottedAbbrev(word1, wtab))
  847. {
  848. dictionary_flags[0] = 0;
  849. dictionary_flags[1] = 0;
  850. spell_word = 1;
  851. if(dictionary_skipwords)
  852. dictionary_flags[0] = FLAG_SKIPWORDS;
  853. }
  854. }
  855. // if textmode, LookupDictList() replaces word1 by the new text and returns found=0
  856. if(phonemes[0] == phonSWITCH)
  857. {
  858. // change to another language in order to translate this word
  859. strcpy(word_phonemes,phonemes);
  860. return(0);
  861. }
  862. if((wmark > 0) && (wmark < 8))
  863. {
  864. // the stressed syllable has been specified in the text (TESTING)
  865. dictionary_flags[0] = (dictionary_flags[0] & ~0xf) | wmark;
  866. }
  867. if(!found && (dictionary_flags[0] & FLAG_ABBREV))
  868. {
  869. // the word has $abbrev flag, but no pronunciation specified. Speak as individual letters
  870. spell_word = 1;
  871. }
  872. if(!found && iswdigit(first_char))
  873. {
  874. Lookup(tr,"_0lang",word_phonemes);
  875. if(word_phonemes[0] == phonSWITCH)
  876. return(0);
  877. if((tr->langopts.numbers2 & NUM2_ENGLISH_NUMERALS) && !(wtab->flags & FLAG_CHAR_REPLACED))
  878. {
  879. // for this language, speak English numerals (0-9) with the English voice
  880. sprintf(word_phonemes,"%c",phonSWITCH);
  881. return(0);
  882. }
  883. found = TranslateNumber(tr, word1, phonemes, dictionary_flags, wtab, 0);
  884. }
  885. if(!found && ((wflags & FLAG_UPPERS) != FLAG_FIRST_UPPER))
  886. {
  887. // either all upper or all lower case
  888. if((tr->langopts.numbers & NUM_ROMAN) || ((tr->langopts.numbers & NUM_ROMAN_CAPITALS) && (wflags & FLAG_ALL_UPPER)))
  889. {
  890. if((wflags & FLAG_LAST_WORD) || !(wtab[1].flags & FLAG_NOSPACE))
  891. {
  892. // don't use Roman number if this word is not separated from the next word (eg. "XLTest")
  893. if((found = TranslateRoman(tr, word1, phonemes, wtab)) != 0)
  894. dictionary_flags[0] |= FLAG_ABBREV; // prevent emphasis if capitals
  895. }
  896. }
  897. }
  898. if((wflags & FLAG_ALL_UPPER) && (word_length > 1)&& iswalpha2(first_char))
  899. {
  900. if((option_tone_flags & OPTION_EMPHASIZE_ALLCAPS) && !(dictionary_flags[0] & FLAG_ABBREV))
  901. {
  902. // emphasize words which are in capitals
  903. emphasize_allcaps = FLAG_EMPHASIZED;
  904. }
  905. else if(!found && !(dictionary_flags[0] & FLAG_SKIPWORDS) && (word_length<4) && (tr->clause_lower_count > 3)
  906. && (tr->clause_upper_count <= tr->clause_lower_count))
  907. {
  908. // An upper case word in a lower case clause. This could be an abbreviation.
  909. spell_word = 1;
  910. }
  911. }
  912. }
  913. if(spell_word > 0)
  914. {
  915. // Speak as individual letters
  916. phonemes[0] = 0;
  917. end_type = 0;
  918. if(SpeakIndividualLetters(tr, word1, phonemes, spell_word) == NULL)
  919. {
  920. if(word_length > 1)
  921. return(FLAG_SPELLWORD); // a mixture of languages, retranslate as individual letters, separated by spaces
  922. if(phonemes[0] == phonSWITCH)
  923. {
  924. // problem with espeak -vbg "b.c.d.e.f"
  925. }
  926. return(0);
  927. }
  928. strcpy(word_phonemes, phonemes);
  929. if(wflags & FLAG_TRANSLATOR2)
  930. return(0);
  931. return(dictionary_flags[0] & FLAG_SKIPWORDS); // for "b.c.d"
  932. }
  933. else if(found == 0)
  934. {
  935. int posn;
  936. int non_initial;
  937. int length;
  938. // word's pronunciation is not given in the dictionary list, although
  939. // dictionary_flags may have ben set there
  940. posn = 0;
  941. non_initial = 0;
  942. length = 999;
  943. wordx = word1;
  944. while(((length < 3) && (length > 0))|| (word_length > 1 && Unpronouncable(tr, wordx, posn)))
  945. {
  946. // This word looks "unpronouncable", so speak letters individually until we
  947. // find a remainder that we can pronounce.
  948. was_unpronouncable = FLAG_WAS_UNPRONOUNCABLE;
  949. emphasize_allcaps = 0;
  950. if(wordx[0] == '\'')
  951. break;
  952. if(posn > 0)
  953. non_initial = 1;
  954. wordx += TranslateLetter(tr, wordx, unpron_phonemes, non_initial);
  955. posn++;
  956. if(unpron_phonemes[0] == phonSWITCH)
  957. {
  958. // change to another language in order to translate this word
  959. strcpy(word_phonemes,unpron_phonemes);
  960. if(strcmp(&unpron_phonemes[1],"en")==0)
  961. return(FLAG_SPELLWORD); // _^_en must have been set in TranslateLetter(), not *_rules which uses only _^_
  962. return(0);
  963. }
  964. #ifdef deleted
  965. p = &wordx[word_length-3]; // this looks wrong. Doesn't consider multi-byte chars.
  966. if(memcmp(p,"'s ",3) == 0)
  967. {
  968. // remove a 's suffix and pronounce this separately (not as an individual letter)
  969. add_plural_suffix = 1;
  970. p[0] = ' ';
  971. p[1] = ' ';
  972. last_char = p[-1];
  973. }
  974. #endif
  975. length=0;
  976. while(wordx[length] != ' ') length++;
  977. }
  978. SetSpellingStress(tr,unpron_phonemes,0,posn);
  979. // anything left ?
  980. if(*wordx != ' ')
  981. {
  982. if((unpron_phonemes[0] != 0) && (wordx[0] != '\''))
  983. {
  984. // letters which have been spoken individually from affecting the pronunciation of the pronuncable part
  985. wordx[-1] = ' ';
  986. }
  987. // Translate the stem
  988. end_type = TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags);
  989. if(phonemes[0] == phonSWITCH)
  990. {
  991. // change to another language in order to translate this word
  992. strcpy(word_phonemes,phonemes);
  993. return(0);
  994. }
  995. #ifdef deleted
  996. // ?? allow $unpr while translating rules, not just on initial FLAG_UNPRON_TEST
  997. if(end_type & SUFX_UNPRON)
  998. {
  999. phonemes[0] = 0; // discard and retranslate as individual letters
  1000. SpeakIndividualLetters(tr, wordx, phonemes, 0);
  1001. strcpy(word_phonemes, phonemes);
  1002. return(0);
  1003. }
  1004. #endif
  1005. if((phonemes[0] == 0) && (end_phonemes[0] == 0))
  1006. {
  1007. int wc;
  1008. // characters not recognised, speak them individually
  1009. // ?? should we say super/sub-script numbers and letters here?
  1010. utf8_in(&wc, wordx);
  1011. if((word_length == 1) && (IsAlpha(wc) || IsSuperscript(wc)))
  1012. {
  1013. if((wordx = SpeakIndividualLetters(tr, wordx, phonemes, spell_word)) == NULL)
  1014. {
  1015. return(0);
  1016. }
  1017. strcpy(word_phonemes, phonemes);
  1018. return(0);
  1019. }
  1020. }
  1021. c_temp = wordx[-1];
  1022. found = 0;
  1023. confirm_prefix = 1;
  1024. for (loopcount = 0; (loopcount < 50) && (end_type & SUFX_P); loopcount++)
  1025. {
  1026. // Found a standard prefix, remove it and retranslate
  1027. // loopcount guards against an endless loop
  1028. if(confirm_prefix && !(end_type & SUFX_B))
  1029. {
  1030. int end2;
  1031. char end_phonemes2[N_WORD_PHONEMES];
  1032. // remove any standard suffix and confirm that the prefix is still recognised
  1033. phonemes2[0] = 0;
  1034. end2 = TranslateRules(tr, wordx, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags);
  1035. if(end2)
  1036. {
  1037. RemoveEnding(tr, wordx, end2, word_copy);
  1038. end_type = TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags);
  1039. memcpy(wordx,word_copy,strlen(word_copy));
  1040. if((end_type & SUFX_P) == 0)
  1041. {
  1042. // after removing the suffix, the prefix is no longer recognised.
  1043. // Keep the suffix, but don't use the prefix
  1044. end_type = end2;
  1045. strcpy(phonemes,phonemes2);
  1046. strcpy(end_phonemes,end_phonemes2);
  1047. if(option_phonemes == 2)
  1048. {
  1049. DecodePhonemes(end_phonemes,end_phonemes2);
  1050. fprintf(f_trans," suffix [%s]\n\n",end_phonemes2);
  1051. }
  1052. }
  1053. confirm_prefix = 0;
  1054. continue;
  1055. }
  1056. }
  1057. prefix_type = end_type;
  1058. if(prefix_type & SUFX_V)
  1059. {
  1060. tr->expect_verb = 1; // use the verb form of the word
  1061. }
  1062. wordx[-1] = c_temp;
  1063. if((prefix_type & SUFX_B) == 0)
  1064. {
  1065. for(ix=(prefix_type & 0xf); ix>0; ix--) // num. of characters to remove
  1066. {
  1067. wordx++;
  1068. while((*wordx & 0xc0) == 0x80) wordx++; // for multibyte characters
  1069. }
  1070. }
  1071. else
  1072. {
  1073. pfix = 1;
  1074. prefix_chars[0] = 0;
  1075. n_chars = prefix_type & 0x3f;
  1076. for(ix=0; ix < n_chars; ix++) // num. of bytes to remove
  1077. {
  1078. prefix_chars[pfix++] = *wordx++;
  1079. if((prefix_type & SUFX_B) && (ix == (n_chars-1)))
  1080. {
  1081. prefix_chars[pfix-1] = 0; // discard the last character of the prefix, this is the separator character
  1082. }
  1083. }
  1084. prefix_chars[pfix] = 0;
  1085. }
  1086. c_temp = wordx[-1];
  1087. wordx[-1] = ' ';
  1088. confirm_prefix = 1;
  1089. wflags |= FLAG_PREFIX_REMOVED;
  1090. if(prefix_type & SUFX_B)
  1091. {
  1092. // SUFX_B is used for Turkish, tr_rules contains " ' (Pb"
  1093. // examine the prefix part
  1094. char *wordpf;
  1095. char prefix_phonemes2[12];
  1096. strncpy0(prefix_phonemes2,end_phonemes,sizeof(prefix_phonemes2));
  1097. wordpf = &prefix_chars[1];
  1098. strcpy(prefix_phonemes, phonemes);
  1099. // look for stress marker or $abbrev
  1100. found = LookupDictList(tr, &wordpf, phonemes, dictionary_flags, 0, wtab);
  1101. if(found)
  1102. {
  1103. strcpy(prefix_phonemes, phonemes);
  1104. }
  1105. if(dictionary_flags[0] & FLAG_ABBREV)
  1106. {
  1107. prefix_phonemes[0] = 0;
  1108. SpeakIndividualLetters(tr, wordpf, prefix_phonemes, 1);
  1109. }
  1110. }
  1111. else
  1112. {
  1113. strcat(prefix_phonemes,end_phonemes);
  1114. }
  1115. end_phonemes[0] = 0;
  1116. end_type = 0;
  1117. found = LookupDictList(tr, &wordx, phonemes, dictionary_flags2, SUFX_P, wtab); // without prefix
  1118. if(dictionary_flags[0]==0)
  1119. {
  1120. dictionary_flags[0] = dictionary_flags2[0];
  1121. dictionary_flags[1] = dictionary_flags2[1];
  1122. }
  1123. else
  1124. prefix_flags = 1;
  1125. if(found == 0)
  1126. {
  1127. end_type = TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags & (FLAG_HYPHEN_AFTER | FLAG_PREFIX_REMOVED), dictionary_flags);
  1128. if(phonemes[0] == phonSWITCH)
  1129. {
  1130. // change to another language in order to translate this word
  1131. wordx[-1] = c_temp;
  1132. strcpy(word_phonemes,phonemes);
  1133. return(0);
  1134. }
  1135. }
  1136. }
  1137. if((end_type != 0) && !(end_type & SUFX_P))
  1138. {
  1139. end_type1 = end_type;
  1140. strcpy(phonemes2,phonemes);
  1141. // The word has a standard ending, re-translate without this ending
  1142. end_flags = RemoveEnding(tr, wordx, end_type, word_copy);
  1143. more_suffixes = 1;
  1144. while(more_suffixes)
  1145. {
  1146. more_suffixes = 0;
  1147. phonemes[0] = 0;
  1148. if(prefix_phonemes[0] != 0)
  1149. {
  1150. // lookup the stem without the prefix removed
  1151. wordx[-1] = c_temp;
  1152. found = LookupDictList(tr, &word1, phonemes, dictionary_flags2, end_flags, wtab); // include prefix, but not suffix
  1153. wordx[-1] = ' ';
  1154. if(phonemes[0] == phonSWITCH)
  1155. {
  1156. // change to another language in order to translate this word
  1157. memcpy(wordx,word_copy,strlen(word_copy));
  1158. strcpy(word_phonemes,phonemes);
  1159. return(0);
  1160. }
  1161. if(dictionary_flags[0]==0)
  1162. {
  1163. dictionary_flags[0] = dictionary_flags2[0];
  1164. dictionary_flags[1] = dictionary_flags2[1];
  1165. }
  1166. if(found)
  1167. prefix_phonemes[0] = 0; // matched whole word, don't need prefix now
  1168. if((found==0) && (dictionary_flags2[0] != 0))
  1169. prefix_flags = 1;
  1170. }
  1171. if(found == 0)
  1172. {
  1173. found = LookupDictList(tr, &wordx, phonemes, dictionary_flags2, end_flags, wtab); // without prefix and suffix
  1174. if(phonemes[0] == phonSWITCH)
  1175. {
  1176. // change to another language in order to translate this word
  1177. memcpy(wordx,word_copy,strlen(word_copy));
  1178. strcpy(word_phonemes,phonemes);
  1179. return(0);
  1180. }
  1181. if(dictionary_flags2[0] & FLAG_ABBREV)
  1182. {
  1183. // Removing the suffix leaves a word which should be spoken as individual letters
  1184. // Not yet implemented
  1185. }
  1186. if(dictionary_flags[0]==0)
  1187. {
  1188. dictionary_flags[0] = dictionary_flags2[0];
  1189. dictionary_flags[1] = dictionary_flags2[1];
  1190. }
  1191. }
  1192. if(found == 0)
  1193. {
  1194. if(end_type & SUFX_Q)
  1195. {
  1196. // don't retranslate, use the original lookup result
  1197. strcpy(phonemes,phonemes2);
  1198. }
  1199. else
  1200. {
  1201. if(end_flags & FLAG_SUFX)
  1202. wflags |= FLAG_SUFFIX_REMOVED;
  1203. if(end_type & SUFX_A)
  1204. wflags |= FLAG_SUFFIX_VOWEL;
  1205. if(end_type & SUFX_M)
  1206. {
  1207. // allow more suffixes before this suffix
  1208. strcpy(end_phonemes2, end_phonemes);
  1209. end_type = TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags);
  1210. strcat(end_phonemes, end_phonemes2); // add the phonemes for the previous suffixes after this one
  1211. if((end_type != 0) && !(end_type & SUFX_P))
  1212. {
  1213. // there is another suffix
  1214. end_flags = RemoveEnding(tr, wordx, end_type, NULL);
  1215. more_suffixes = 1;
  1216. }
  1217. }
  1218. else
  1219. {
  1220. // don't remove any previous suffix
  1221. TranslateRules(tr, wordx, phonemes, N_WORD_PHONEMES, NULL, wflags, dictionary_flags);
  1222. end_type = 0;
  1223. }
  1224. if(phonemes[0] == phonSWITCH)
  1225. {
  1226. // change to another language in order to translate this word
  1227. strcpy(word_phonemes,phonemes);
  1228. memcpy(wordx,word_copy,strlen(word_copy));
  1229. wordx[-1] = c_temp;
  1230. return(0);
  1231. }
  1232. }
  1233. }
  1234. }
  1235. if((end_type1 & SUFX_T) == 0)
  1236. {
  1237. // the default is to add the suffix and then determine the word's stress pattern
  1238. AppendPhonemes(tr,phonemes, N_WORD_PHONEMES, end_phonemes);
  1239. end_phonemes[0] = 0;
  1240. }
  1241. memcpy(wordx,word_copy,strlen(word_copy));
  1242. }
  1243. wordx[-1] = c_temp;
  1244. }
  1245. }
  1246. if((add_plural_suffix) || (wflags & FLAG_HAS_PLURAL))
  1247. {
  1248. // s or 's suffix, append [s], [z] or [Iz] depending on previous letter
  1249. if(last_char == 'f')
  1250. TranslateRules(tr, &word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
  1251. else if((last_char==0) || (strchr_w("hsx",last_char)==NULL))
  1252. TranslateRules(tr, &word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
  1253. else
  1254. TranslateRules(tr, &word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, NULL);
  1255. }
  1256. wflags |= emphasize_allcaps;
  1257. /* determine stress pattern for this word */
  1258. /******************************************/
  1259. prefix_stress = 0;
  1260. for(p = prefix_phonemes; *p != 0; p++)
  1261. {
  1262. if((*p == phonSTRESS_P) || (*p == phonSTRESS_P2))
  1263. {
  1264. prefix_stress = *p;
  1265. }
  1266. }
  1267. if(prefix_flags || (prefix_stress != 0))
  1268. {
  1269. if((tr->langopts.param[LOPT_PREFIXES]) || (prefix_type & SUFX_T))
  1270. {
  1271. char *p;
  1272. // German, keep a secondary stress on the stem
  1273. SetWordStress(tr, phonemes, dictionary_flags, 3, 0);
  1274. // reduce all but the first primary stress
  1275. ix=0;
  1276. for(p=prefix_phonemes; *p != 0; p++)
  1277. {
  1278. if(*p == phonSTRESS_P)
  1279. {
  1280. if(ix==0)
  1281. ix=1;
  1282. else
  1283. *p = phonSTRESS_3;
  1284. }
  1285. }
  1286. #ifdef PLATFORM_WINDOWS
  1287. sprintf(word_phonemes, "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1288. #else
  1289. snprintf(word_phonemes, sizeof(word_phonemes), "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1290. #endif
  1291. word_phonemes[N_WORD_PHONEMES-1] = 0;
  1292. SetWordStress(tr, word_phonemes, dictionary_flags, -1, 0);
  1293. }
  1294. else
  1295. {
  1296. // stress position affects the whole word, including prefix
  1297. #ifdef PLATFORM_WINDOWS
  1298. sprintf(word_phonemes, "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1299. #else
  1300. snprintf(word_phonemes, sizeof(word_phonemes), "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1301. #endif
  1302. word_phonemes[N_WORD_PHONEMES-1] = 0;
  1303. SetWordStress(tr, word_phonemes, dictionary_flags, -1, 0);
  1304. }
  1305. }
  1306. else
  1307. {
  1308. if(prefix_phonemes[0] == 0)
  1309. SetWordStress(tr, phonemes, dictionary_flags, -1, 0);
  1310. else
  1311. SetWordStress(tr, phonemes, dictionary_flags, -1, 0);
  1312. #ifdef PLATFORM_WINDOWS
  1313. sprintf(word_phonemes, "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1314. #else
  1315. snprintf(word_phonemes, sizeof(word_phonemes), "%s%s%s", unpron_phonemes, prefix_phonemes, phonemes);
  1316. #endif
  1317. word_phonemes[N_WORD_PHONEMES-1] = 0;
  1318. }
  1319. if(end_phonemes[0] != 0)
  1320. {
  1321. // a suffix had the SUFX_T option set, add the suffix after the stress pattern has been determined
  1322. ix = strlen(word_phonemes);
  1323. end_phonemes[N_WORD_PHONEMES-1-ix] = 0; // ensure no buffer overflow
  1324. strcpy(&word_phonemes[ix], end_phonemes);
  1325. }
  1326. if(wflags & FLAG_LAST_WORD)
  1327. {
  1328. // don't use $brk pause before the last word of a sentence
  1329. // (but allow it for emphasis, see below
  1330. dictionary_flags[0] &= ~FLAG_PAUSE1;
  1331. }
  1332. #ifdef deleted
  1333. // but it causes problems if these are not a person name
  1334. if(tr->translator_name == L('h','u'))
  1335. {
  1336. // lang=hu, If the last two words of a clause have capital letters (eg. a person name), unstress the last word.
  1337. if((wflags & (FLAG_LAST_WORD | FLAG_FIRST_UPPER | FLAG_ALL_UPPER | FLAG_FIRST_WORD)) == (FLAG_LAST_WORD | FLAG_FIRST_UPPER))
  1338. {
  1339. if(((wtab[-1].flags & (FLAG_FIRST_UPPER | FLAG_ALL_UPPER)) == FLAG_FIRST_UPPER) && ((tr->clause_terminator != 0x90028) || (wflags & FLAG_HAS_DOT)))
  1340. {
  1341. ChangeWordStress(tr,word_phonemes,3);
  1342. }
  1343. }
  1344. }
  1345. #endif
  1346. if((wflags & FLAG_HYPHEN) && (tr->langopts.stress_flags & S_HYPEN_UNSTRESS))
  1347. {
  1348. ChangeWordStress(tr,word_phonemes,3);
  1349. }
  1350. else if(wflags & FLAG_EMPHASIZED2)
  1351. {
  1352. // A word is indicated in the source text as stressed
  1353. // Give it stress level 6 (for the intonation module)
  1354. ChangeWordStress(tr,word_phonemes,6);
  1355. if(wflags & FLAG_EMPHASIZED)
  1356. dictionary_flags[0] |= FLAG_PAUSE1; // precede by short pause
  1357. }
  1358. else if(wtab[dictionary_skipwords].flags & FLAG_LAST_WORD)
  1359. {
  1360. // the word has attribute to stress or unstress when at end of clause
  1361. if(dictionary_flags[0] & (FLAG_STRESS_END | FLAG_STRESS_END2))
  1362. ChangeWordStress(tr,word_phonemes,4);
  1363. else if((dictionary_flags[0] & FLAG_UNSTRESS_END) && (any_stressed_words))
  1364. ChangeWordStress(tr,word_phonemes,3);
  1365. }
  1366. // dictionary flags for this word give a clue about which alternative pronunciations of
  1367. // following words to use.
  1368. if(end_type1 & SUFX_F)
  1369. {
  1370. // expect a verb form, with or without -s suffix
  1371. tr->expect_verb = 2;
  1372. tr->expect_verb_s = 2;
  1373. }
  1374. if(dictionary_flags[1] & FLAG_PASTF)
  1375. {
  1376. /* expect perfect tense in next two words */
  1377. tr->expect_past = 3;
  1378. tr->expect_verb = 0;
  1379. tr->expect_noun = 0;
  1380. }
  1381. else if(dictionary_flags[1] & FLAG_VERBF)
  1382. {
  1383. /* expect a verb in the next word */
  1384. tr->expect_verb = 2;
  1385. tr->expect_verb_s = 0; /* verb won't have -s suffix */
  1386. tr->expect_noun = 0;
  1387. }
  1388. else if(dictionary_flags[1] & FLAG_VERBSF)
  1389. {
  1390. // expect a verb, must have a -s suffix
  1391. tr->expect_verb = 0;
  1392. tr->expect_verb_s = 2;
  1393. tr->expect_past = 0;
  1394. tr->expect_noun = 0;
  1395. }
  1396. else if(dictionary_flags[1] & FLAG_NOUNF)
  1397. {
  1398. /* not expecting a verb next */
  1399. tr->expect_noun = 2;
  1400. tr->expect_verb = 0;
  1401. tr->expect_verb_s = 0;
  1402. tr->expect_past = 0;
  1403. }
  1404. if((wordx[0] != 0) && (!(dictionary_flags[1] & FLAG_VERB_EXT)))
  1405. {
  1406. if(tr->expect_verb > 0)
  1407. tr->expect_verb--;
  1408. if(tr->expect_verb_s > 0)
  1409. tr->expect_verb_s--;
  1410. if(tr->expect_noun >0)
  1411. tr->expect_noun--;
  1412. if(tr->expect_past > 0)
  1413. tr->expect_past--;
  1414. }
  1415. if((word_length == 1) && (tr->translator_name == L('e','n')) && iswalpha2(first_char) && (first_char != 'i'))
  1416. {
  1417. // English Specific !!!!
  1418. // any single letter before a dot is an abbreviation, except 'I'
  1419. dictionary_flags[0] |= FLAG_ALLOW_DOT;
  1420. }
  1421. if((tr->langopts.param[LOPT_ALT] & 2) && ((dictionary_flags[0] & (FLAG_ALT_TRANS | FLAG_ALT2_TRANS)) != 0))
  1422. {
  1423. ApplySpecialAttribute2(tr,word_phonemes,dictionary_flags[0]);
  1424. }
  1425. dictionary_flags[0] |= was_unpronouncable;
  1426. memcpy(word_start, word_copy2, word_copy_length);
  1427. return(dictionary_flags[0]);
  1428. } // end of TranslateWord
  1429. static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode)
  1430. {//==========================================================
  1431. p->phcode = phcode;
  1432. p->stresslevel = 0;
  1433. p->tone_ph = 0;
  1434. p->synthflags = embedded_flag;
  1435. p->sourceix = 0;
  1436. embedded_flag = 0;
  1437. }
  1438. static int CountSyllables(unsigned char *phonemes)
  1439. {//===============================================
  1440. int count = 0;
  1441. int phon;
  1442. while((phon = *phonemes++) != 0)
  1443. {
  1444. if(phoneme_tab[phon]->type == phVOWEL)
  1445. count++;
  1446. }
  1447. return(count);
  1448. }
  1449. void Word_EmbeddedCmd()
  1450. {//====================
  1451. // Process embedded commands for emphasis, sayas, and break
  1452. int embedded_cmd;
  1453. int value;
  1454. do
  1455. {
  1456. embedded_cmd = embedded_list[embedded_read++];
  1457. value = embedded_cmd >> 8;
  1458. switch(embedded_cmd & 0x1f)
  1459. {
  1460. case EMBED_Y:
  1461. option_sayas = value;
  1462. break;
  1463. case EMBED_F:
  1464. option_emphasis = value;
  1465. break;
  1466. case EMBED_B:
  1467. // break command
  1468. if(value == 0)
  1469. pre_pause = 0; // break=none
  1470. else
  1471. pre_pause += value;
  1472. break;
  1473. }
  1474. } while(((embedded_cmd & 0x80) == 0) && (embedded_read < embedded_ix));
  1475. } // end of Word_EmbeddedCmd
  1476. int SetTranslator2(const char *new_language)
  1477. {//=========================================
  1478. // Set translator2 to a second language
  1479. int new_phoneme_tab;
  1480. const char *new_phtab_name;
  1481. int bitmap;
  1482. int dialect = 0;
  1483. new_phtab_name = new_language;
  1484. if((bitmap = translator->langopts.dict_dialect) != 0)
  1485. {
  1486. if((bitmap & (1 << DICTDIALECT_EN_US)) && (strcmp(new_language, "en") == 0))
  1487. {
  1488. new_phtab_name = "en-us";
  1489. dialect = DICTDIALECT_EN_US;
  1490. }
  1491. if((bitmap & (1 << DICTDIALECT_ES_LA)) && (strcmp(new_language, "es") == 0))
  1492. {
  1493. new_phtab_name = "es-la";
  1494. dialect = DICTDIALECT_ES_LA;
  1495. }
  1496. }
  1497. if((new_phoneme_tab = SelectPhonemeTableName(new_phtab_name)) >= 0)
  1498. {
  1499. if((translator2 != NULL) && (strcmp(new_language,translator2_language) != 0))
  1500. {
  1501. // we already have an alternative translator, but not for the required language, delete it
  1502. DeleteTranslator(translator2);
  1503. translator2 = NULL;
  1504. }
  1505. if(translator2 == NULL)
  1506. {
  1507. translator2 = SelectTranslator(new_language);
  1508. strcpy(translator2_language,new_language);
  1509. if(LoadDictionary(translator2, translator2->dictionary_name, 0) != 0)
  1510. {
  1511. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  1512. new_phoneme_tab = -1;
  1513. translator2_language[0] = 0;
  1514. }
  1515. else
  1516. {
  1517. if(dialect == DICTDIALECT_EN_US)
  1518. {
  1519. // en-us
  1520. translator2->dict_condition = 0x48; // bits 3, 6
  1521. translator2->langopts.param[LOPT_REDUCE_T] = 1;
  1522. }
  1523. if(dialect == DICTDIALECT_ES_LA)
  1524. {
  1525. translator2->dict_condition = 0x04; // bit 2
  1526. }
  1527. }
  1528. translator2->phoneme_tab_ix = new_phoneme_tab;
  1529. }
  1530. }
  1531. if(translator2 != NULL)
  1532. translator2->phonemes_repeat[0] = 0;
  1533. return(new_phoneme_tab);
  1534. } // end of SetTranslator2
  1535. static int TranslateWord2(Translator *tr, char *word, WORD_TAB *wtab, int pre_pause, int next_pause)
  1536. {//=================================================================================================
  1537. int flags=0;
  1538. int stress;
  1539. int next_stress;
  1540. int next_tone=0;
  1541. unsigned char *p;
  1542. int srcix;
  1543. int found_dict_flag;
  1544. unsigned char ph_code;
  1545. PHONEME_LIST2 *plist2;
  1546. PHONEME_TAB *ph;
  1547. int max_stress;
  1548. int max_stress_ix=0;
  1549. int prev_vowel = -1;
  1550. int pitch_raised = 0;
  1551. int switch_phonemes = -1;
  1552. int first_phoneme = 1;
  1553. int source_ix;
  1554. int len;
  1555. int ix;
  1556. int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
  1557. const char *new_language;
  1558. int bad_phoneme;
  1559. int word_flags;
  1560. int word_copy_len;
  1561. char word_copy[N_WORD_BYTES+1];
  1562. char word_replaced[N_WORD_BYTES+1];
  1563. char old_dictionary_name[40];
  1564. if((f_logespeak != NULL) && (logging_type & 8))
  1565. {
  1566. fprintf(f_logespeak,"WORD: flg=%.5x len=%d '",wtab->flags,wtab->length);
  1567. for(ix=0; ix<40; ix++)
  1568. {
  1569. if(word[ix]==0) break;
  1570. fputc(word[ix], f_logespeak);
  1571. }
  1572. fprintf(f_logespeak,"'\n");
  1573. }
  1574. len = wtab->length;
  1575. if(len > 31) len = 31;
  1576. source_ix = (wtab->sourceix & 0x7ff) | (len << 11); // bits 0-10 sourceix, bits 11-15 word length
  1577. word_flags = wtab[0].flags;
  1578. if(word_flags & FLAG_EMBEDDED)
  1579. {
  1580. wtab[0].flags &= ~FLAG_EMBEDDED; // clear it in case we call TranslateWord2() again for the same word
  1581. embedded_flag = SFLAG_EMBEDDED;
  1582. Word_EmbeddedCmd();
  1583. }
  1584. if((word[0] == 0) || (word_flags & FLAG_DELETE_WORD))
  1585. {
  1586. // nothing to translate. Add a dummy phoneme to carry any embedded commands
  1587. if(embedded_flag)
  1588. {
  1589. ph_list2[n_ph_list2].phcode = phonEND_WORD;
  1590. ph_list2[n_ph_list2].stresslevel = 0;
  1591. ph_list2[n_ph_list2].wordstress = 0;
  1592. ph_list2[n_ph_list2].tone_ph = 0;
  1593. ph_list2[n_ph_list2].synthflags = embedded_flag;
  1594. ph_list2[n_ph_list2].sourceix = 0;
  1595. n_ph_list2++;
  1596. embedded_flag = 0;
  1597. }
  1598. word_phonemes[0] = 0;
  1599. return(0);
  1600. }
  1601. // after a $pause word attribute, ignore a $pause attribute on the next two words
  1602. if(tr->prepause_timeout > 0)
  1603. tr->prepause_timeout--;
  1604. if((option_sayas & 0xf0) == 0x10)
  1605. {
  1606. if(!(word_flags & FLAG_FIRST_WORD))
  1607. {
  1608. // SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
  1609. pre_pause += 4;
  1610. }
  1611. }
  1612. if(word_flags & FLAG_FIRST_UPPER)
  1613. {
  1614. if((option_capitals > 2) && (embedded_ix < N_EMBEDDED_LIST-6))
  1615. {
  1616. // indicate capital letter by raising pitch
  1617. if(embedded_flag)
  1618. embedded_list[embedded_ix-1] &= ~0x80; // already embedded command before this word, remove terminator
  1619. if((pitch_raised = option_capitals) == 3)
  1620. pitch_raised = 20; // default pitch raise for capitals
  1621. embedded_list[embedded_ix++] = EMBED_P+0x40+0x80 + (pitch_raised << 8); // raise pitch
  1622. embedded_flag = SFLAG_EMBEDDED;
  1623. }
  1624. }
  1625. p = (unsigned char *)word_phonemes;
  1626. if(word_flags & FLAG_PHONEMES)
  1627. {
  1628. // The input is in phoneme mnemonics, not language text
  1629. int c1;
  1630. char lang_name[12];
  1631. if(memcmp(word,"_^_",3)==0)
  1632. {
  1633. // switch languages
  1634. word+=3;
  1635. for(ix=0;;)
  1636. {
  1637. c1 = *word++;
  1638. if((c1==' ') || (c1==0))
  1639. break;
  1640. lang_name[ix++] = tolower(c1);
  1641. }
  1642. lang_name[ix] = 0;
  1643. if((ix = LookupPhonemeTable(lang_name)) > 0)
  1644. {
  1645. SelectPhonemeTable(ix);
  1646. word_phonemes[0] = phonSWITCH;
  1647. word_phonemes[1] = ix;
  1648. word_phonemes[2] = 0;
  1649. }
  1650. }
  1651. else
  1652. {
  1653. EncodePhonemes(word,word_phonemes,&bad_phoneme);
  1654. }
  1655. flags = FLAG_FOUND;
  1656. }
  1657. else
  1658. {
  1659. int c2;
  1660. ix = 0;
  1661. while(((c2 = word_copy[ix] = word[ix]) != ' ') && (c2 != 0) && (ix < N_WORD_BYTES)) ix++;
  1662. word_copy_len = ix;
  1663. word_replaced[2] = 0;
  1664. flags = TranslateWord(translator, word, next_pause, wtab, &word_replaced[2]);
  1665. if(flags & FLAG_SPELLWORD)
  1666. {
  1667. // re-translate the word as individual letters, separated by spaces
  1668. memcpy(word, word_copy, word_copy_len);
  1669. return(flags);
  1670. }
  1671. if((flags & FLAG_COMBINE) && !(wtab[1].flags & FLAG_PHONEMES))
  1672. {
  1673. char *p2;
  1674. int ok = 1;
  1675. unsigned int flags2[2];
  1676. int c_word2;
  1677. char ph_buf[N_WORD_PHONEMES];
  1678. flags2[0] = 0;
  1679. sylimit = tr->langopts.param[LOPT_COMBINE_WORDS];
  1680. // LANG=cs,sk
  1681. // combine a preposition with the following word
  1682. p2 = word;
  1683. while(*p2 != ' ') p2++;
  1684. utf8_in(&c_word2, p2+1); // first character of the next word;
  1685. if(!iswalpha2(c_word2))
  1686. {
  1687. ok =0;
  1688. }
  1689. if(ok != 0)
  1690. {
  1691. strcpy(ph_buf,word_phonemes);
  1692. flags2[0] = TranslateWord(translator, p2+1, 0, wtab+1, NULL);
  1693. if((flags2[0] & FLAG_WAS_UNPRONOUNCABLE) || (word_phonemes[0] == phonSWITCH))
  1694. ok = 0;
  1695. if(sylimit & 0x100)
  1696. {
  1697. // only if the second word has $alt attribute
  1698. if((flags2[0] & FLAG_ALT_TRANS) == 0)
  1699. {
  1700. ok = 0;
  1701. }
  1702. }
  1703. if((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD))
  1704. {
  1705. // not if the next word is end-of-sentence
  1706. ok = 0;
  1707. }
  1708. if(ok == 0)
  1709. {
  1710. strcpy(word_phonemes,ph_buf);
  1711. }
  1712. }
  1713. if(ok)
  1714. {
  1715. *p2 = '-'; // replace next space by hyphen
  1716. wtab[0].flags &= ~FLAG_ALL_UPPER; // prevent it being considered an abbreviation
  1717. flags = TranslateWord(translator, word, next_pause, wtab, NULL); // translate the combined word
  1718. if((sylimit > 0) && (CountSyllables(p) > (sylimit & 0x1f)))
  1719. {
  1720. // revert to separate words
  1721. *p2 = ' ';
  1722. flags = TranslateWord(translator, word, next_pause, wtab, NULL);
  1723. }
  1724. else
  1725. {
  1726. if(flags == 0)
  1727. flags = flags2[0]; // no flags for the combined word, so use flags from the second word eg. lang-hu "nem december 7-e"
  1728. flags |= FLAG_SKIPWORDS;
  1729. dictionary_skipwords = 1;
  1730. }
  1731. }
  1732. }
  1733. if(p[0]==phonSWITCH)
  1734. {
  1735. int switch_attempt;
  1736. strcpy(old_dictionary_name, dictionary_name);
  1737. for(switch_attempt=0; switch_attempt < 2; switch_attempt++)
  1738. {
  1739. // this word uses a different language
  1740. memcpy(word, word_copy, word_copy_len);
  1741. new_language = (char *)(&p[1]);
  1742. if(new_language[0]==0)
  1743. new_language = "en";
  1744. switch_phonemes = SetTranslator2(new_language);
  1745. if(switch_phonemes >= 0)
  1746. {
  1747. // re-translate the word using the new translator
  1748. wtab[0].flags |= FLAG_TRANSLATOR2;
  1749. if(word_replaced[2] != 0)
  1750. {
  1751. word_replaced[0] = 0; // byte before the start of the word
  1752. word_replaced[1] = ' ';
  1753. flags = TranslateWord(translator2, &word_replaced[1], next_pause, wtab, NULL);
  1754. }
  1755. else
  1756. flags = TranslateWord(translator2, word, next_pause, wtab, &word_replaced[2]);
  1757. }
  1758. if(p[0] != phonSWITCH)
  1759. break;
  1760. }
  1761. // strcpy((char *)p,translator2->word_phonemes);
  1762. if(p[0] == phonSWITCH)
  1763. return(FLAG_SPELLWORD);
  1764. if(switch_phonemes < 0)
  1765. {
  1766. // language code is not recognised or 2nd translator won't translate it
  1767. p[0] = phonSCHWA; // just say something
  1768. p[1] = phonSCHWA;
  1769. p[2] = 0;
  1770. }
  1771. // ?? Option to convert from language2 phonemes to the equivalent language1 phonemes
  1772. // ?? Option to set the word-stress according to language1 rules eg. lang=fr)
  1773. if(ChangeEquivalentPhonemes(tr, switch_phonemes, (char *)p))
  1774. {
  1775. // Phonemes have been converted from the foreign language to the native language
  1776. switch_phonemes = -1;
  1777. }
  1778. if(switch_phonemes == -1)
  1779. {
  1780. strcpy(dictionary_name, old_dictionary_name);
  1781. SelectPhonemeTable(voice->phoneme_tab_ix);
  1782. // leave switch_phonemes set, but use the original phoneme table number.
  1783. // This will suppress LOPT_REGRESSIVE_VOICING
  1784. switch_phonemes = voice->phoneme_tab_ix; // original phoneme table
  1785. }
  1786. }
  1787. if(!(word_flags & FLAG_HYPHEN))
  1788. {
  1789. if(flags & FLAG_PAUSE1)
  1790. {
  1791. if(pre_pause < 1)
  1792. pre_pause = 1;
  1793. }
  1794. if((flags & FLAG_PREPAUSE) && !(word_flags & (FLAG_LAST_WORD | FLAG_FIRST_WORD)) && !(wtab[-1].flags & FLAG_FIRST_WORD) && (tr->prepause_timeout == 0))
  1795. {
  1796. // the word is marked in the dictionary list with $pause
  1797. if(pre_pause < 4) pre_pause = 4;
  1798. tr->prepause_timeout = 3;
  1799. }
  1800. }
  1801. if((option_emphasis >= 3) && (pre_pause < 1))
  1802. pre_pause = 1;
  1803. }
  1804. stress = 0;
  1805. next_stress = 1;
  1806. srcix = 0;
  1807. max_stress = -1;
  1808. found_dict_flag = 0;
  1809. if((flags & FLAG_FOUND) && !(flags & FLAG_TEXTMODE))
  1810. found_dict_flag = SFLAG_DICTIONARY;
  1811. while((pre_pause > 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1812. {
  1813. // add pause phonemes here. Either because of punctuation (brackets or quotes) in the
  1814. // text, or because the word is marked in the dictionary lookup as a conjunction
  1815. if(pre_pause > 1)
  1816. {
  1817. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE);
  1818. pre_pause -= 2;
  1819. }
  1820. else
  1821. {
  1822. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_NOLINK);
  1823. pre_pause--;
  1824. }
  1825. tr->end_stressed_vowel = 0; // forget about the previous word
  1826. tr->prev_dict_flags[0] = 0;
  1827. tr->prev_dict_flags[1] = 0;
  1828. }
  1829. plist2 = &ph_list2[n_ph_list2];
  1830. if((option_capitals==1) && (word_flags & FLAG_FIRST_UPPER))
  1831. {
  1832. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1833. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1834. if((word_flags & FLAG_ALL_UPPER) && IsAlpha(word[1]))
  1835. {
  1836. // word > 1 letter and all capitals
  1837. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1838. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1839. }
  1840. }
  1841. if(switch_phonemes >= 0)
  1842. {
  1843. if((p[0] == phonPAUSE) && (p[1] == phonSWITCH))
  1844. {
  1845. // the new word starts with a phoneme table switch, so there's no need to switch before it.
  1846. if(ph_list2[n_ph_list2-1].phcode == phonSWITCH)
  1847. {
  1848. //previous phoneme is also a phonSWITCH, delete it
  1849. n_ph_list2--;
  1850. }
  1851. }
  1852. else
  1853. {
  1854. // this word uses a different phoneme table
  1855. if(ph_list2[n_ph_list2-1].phcode == phonSWITCH)
  1856. {
  1857. //previous phoneme is also a phonSWITCH, just change its phoneme table number
  1858. n_ph_list2--;
  1859. }
  1860. else
  1861. {
  1862. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1863. }
  1864. ph_list2[n_ph_list2++].tone_ph = switch_phonemes; // temporary phoneme table number
  1865. }
  1866. }
  1867. // remove initial pause from a word if it follows a hyphen
  1868. if((word_flags & FLAG_HYPHEN) && (phoneme_tab[*p]->type == phPAUSE))
  1869. p++;
  1870. if((p[0] == 0) && (embedded_flag))
  1871. {
  1872. // no phonemes. Insert a very short pause to carry an embedded command
  1873. p[0] = phonPAUSE_VSHORT;
  1874. p[1] = 0;
  1875. }
  1876. while(((ph_code = *p++) != 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1877. {
  1878. if(ph_code == 255)
  1879. continue; // unknown phoneme
  1880. // Add the phonemes to the first stage phoneme list (ph_list2)
  1881. ph = phoneme_tab[ph_code];
  1882. if(ph_code == phonSWITCH)
  1883. {
  1884. ph_list2[n_ph_list2].phcode = ph_code;
  1885. ph_list2[n_ph_list2].sourceix = 0;
  1886. ph_list2[n_ph_list2].synthflags = 0;
  1887. ph_list2[n_ph_list2++].tone_ph = *p;
  1888. SelectPhonemeTable(*p);
  1889. p++;
  1890. }
  1891. else if(ph->type == phSTRESS)
  1892. {
  1893. // don't add stress phonemes codes to the list, but give their stress
  1894. // value to the next vowel phoneme
  1895. // std_length is used to hold stress number or (if >10) a tone number for a tone language
  1896. if(ph->program == 0)
  1897. next_stress = ph->std_length;
  1898. else
  1899. {
  1900. // for tone languages, the tone number for a syllable follows the vowel
  1901. if(prev_vowel >= 0)
  1902. {
  1903. ph_list2[prev_vowel].tone_ph = ph_code;
  1904. }
  1905. else
  1906. {
  1907. next_tone = ph_code; // no previous vowel, apply to the next vowel
  1908. }
  1909. }
  1910. }
  1911. else if(ph_code == phonSYLLABIC)
  1912. {
  1913. // mark the previous phoneme as a syllabic consonant
  1914. prev_vowel = n_ph_list2-1;
  1915. ph_list2[prev_vowel].synthflags |= SFLAG_SYLLABLE;
  1916. ph_list2[prev_vowel].stresslevel = next_stress;
  1917. }
  1918. else if(ph_code == phonLENGTHEN)
  1919. {
  1920. ph_list2[n_ph_list2-1].synthflags |= SFLAG_LENGTHEN;
  1921. }
  1922. else if(ph_code == phonEND_WORD)
  1923. {
  1924. // a || symbol in a phoneme string was used to indicate a word boundary
  1925. // Don't add this phoneme to the list, but make sure the next phoneme has
  1926. // a newword indication
  1927. srcix = source_ix+1;
  1928. }
  1929. else if(ph_code == phonX1)
  1930. {
  1931. // a language specific action
  1932. if(tr->langopts.param[LOPT_IT_DOUBLING])
  1933. {
  1934. flags |= FLAG_DOUBLING;
  1935. }
  1936. }
  1937. else
  1938. {
  1939. ph_list2[n_ph_list2].phcode = ph_code;
  1940. ph_list2[n_ph_list2].tone_ph = 0;
  1941. ph_list2[n_ph_list2].synthflags = embedded_flag | found_dict_flag;
  1942. embedded_flag = 0;
  1943. ph_list2[n_ph_list2].sourceix = srcix;
  1944. srcix = 0;
  1945. if(ph->type == phVOWEL)
  1946. {
  1947. stress = next_stress;
  1948. next_stress = 1; // default is 'unstressed'
  1949. if(stress >= 4)
  1950. {
  1951. any_stressed_words = 1;
  1952. }
  1953. if((prev_vowel >= 0) && (n_ph_list2-1) != prev_vowel)
  1954. ph_list2[n_ph_list2-1].stresslevel = stress; // set stress for previous consonant
  1955. ph_list2[n_ph_list2].synthflags |= SFLAG_SYLLABLE;
  1956. prev_vowel = n_ph_list2;
  1957. if(stress > max_stress)
  1958. {
  1959. max_stress = stress;
  1960. max_stress_ix = n_ph_list2;
  1961. }
  1962. if(next_tone != 0)
  1963. {
  1964. ph_list2[n_ph_list2].tone_ph = next_tone;
  1965. next_tone=0;
  1966. }
  1967. }
  1968. else
  1969. {
  1970. if(first_phoneme && tr->langopts.param[LOPT_IT_DOUBLING])
  1971. {
  1972. if(((tr->prev_dict_flags[0] & FLAG_DOUBLING) && (tr->langopts.param[LOPT_IT_DOUBLING] & 1)) ||
  1973. (tr->end_stressed_vowel && (tr->langopts.param[LOPT_IT_DOUBLING] & 2)))
  1974. {
  1975. // italian, double the initial consonant if the previous word ends with a
  1976. // stressed vowel, or is marked with a flag
  1977. ph_list2[n_ph_list2].synthflags |= SFLAG_LENGTHEN;
  1978. }
  1979. }
  1980. }
  1981. ph_list2[n_ph_list2].stresslevel = stress;
  1982. n_ph_list2++;
  1983. first_phoneme = 0;
  1984. }
  1985. }
  1986. if(word_flags & FLAG_COMMA_AFTER)
  1987. {
  1988. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_CLAUSE);
  1989. }
  1990. // don't set new-word if there is a hyphen before it
  1991. if((word_flags & FLAG_HYPHEN) == 0)
  1992. {
  1993. plist2->sourceix = source_ix;
  1994. }
  1995. tr->end_stressed_vowel = 0;
  1996. if((stress >= 4) && (phoneme_tab[ph_list2[n_ph_list2-1].phcode]->type == phVOWEL))
  1997. {
  1998. tr->end_stressed_vowel = 1; // word ends with a stressed vowel
  1999. }
  2000. if(switch_phonemes >= 0)
  2001. {
  2002. // this word uses a different phoneme table, now switch back
  2003. strcpy(dictionary_name, old_dictionary_name);
  2004. SelectPhonemeTable(voice->phoneme_tab_ix);
  2005. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  2006. ph_list2[n_ph_list2++].tone_ph = voice->phoneme_tab_ix; // original phoneme table number
  2007. }
  2008. if(pitch_raised > 0)
  2009. {
  2010. embedded_list[embedded_ix++] = EMBED_P+0x60+0x80 + (pitch_raised << 8); // lower pitch
  2011. SetPlist2(&ph_list2[n_ph_list2],phonPAUSE_SHORT);
  2012. ph_list2[n_ph_list2++].synthflags = SFLAG_EMBEDDED;
  2013. }
  2014. if(flags & FLAG_STRESS_END2)
  2015. {
  2016. // this's word's stress could be increased later
  2017. ph_list2[max_stress_ix].synthflags |= SFLAG_PROMOTE_STRESS;
  2018. }
  2019. tr->prev_dict_flags[0] = flags;
  2020. return(flags);
  2021. } // end of TranslateWord2
  2022. static int EmbeddedCommand(unsigned int *source_index_out)
  2023. {//=======================================================
  2024. // An embedded command to change the pitch, volume, etc.
  2025. // returns number of commands added to embedded_list
  2026. // pitch,speed,amplitude,expression,reverb,tone,voice,sayas
  2027. const char *commands = "PSARHTIVYMUBF";
  2028. int value = -1;
  2029. int sign = 0;
  2030. unsigned char c;
  2031. char *p;
  2032. int cmd;
  2033. int source_index = *source_index_out;
  2034. c = source[source_index];
  2035. if(c == '+')
  2036. {
  2037. sign = 0x40;
  2038. source_index++;
  2039. }
  2040. else if(c == '-')
  2041. {
  2042. sign = 0x60;
  2043. source_index++;
  2044. }
  2045. if(IsDigit09(source[source_index]))
  2046. {
  2047. value = atoi(&source[source_index]);
  2048. while(IsDigit09(source[source_index]))
  2049. source_index++;
  2050. }
  2051. c = source[source_index++];
  2052. if(embedded_ix >= (N_EMBEDDED_LIST - 2))
  2053. return(0); // list is full
  2054. if((p = strchr_w(commands,c)) == NULL)
  2055. return(0);
  2056. cmd = (p - commands)+1;
  2057. if(value == -1)
  2058. {
  2059. value = embedded_default[cmd];
  2060. sign = 0;
  2061. }
  2062. if(cmd == EMBED_Y)
  2063. {
  2064. option_sayas2 = value;
  2065. count_sayas_digits = 0;
  2066. }
  2067. if(cmd == EMBED_F)
  2068. {
  2069. if(value >= 3)
  2070. word_emphasis = FLAG_EMPHASIZED;
  2071. else
  2072. word_emphasis = 0;
  2073. }
  2074. embedded_list[embedded_ix++] = cmd + sign + (value << 8);
  2075. *source_index_out = source_index;
  2076. return(1);
  2077. } // end of EmbeddedCommand
  2078. static int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, int *insert, int *wordflags)
  2079. {//=========================================================================================
  2080. int ix;
  2081. unsigned int word;
  2082. unsigned int new_c, c2, c_lower;
  2083. int upper_case = 0;
  2084. static int ignore_next = 0;
  2085. const unsigned int *replace_chars;
  2086. if(ignore_next)
  2087. {
  2088. ignore_next = 0;
  2089. return(8);
  2090. }
  2091. if(c == 0) return(0);
  2092. if((replace_chars = tr->langopts.replace_chars) == NULL)
  2093. return(c);
  2094. // there is a list of character codes to be substituted with alternative codes
  2095. if(iswupper2(c_lower = c))
  2096. {
  2097. c_lower = towlower2(c);
  2098. upper_case = 1;
  2099. }
  2100. new_c = 0;
  2101. for(ix=0; (word = replace_chars[ix]) != 0; ix+=2)
  2102. {
  2103. if(c_lower == (word & 0xffff))
  2104. {
  2105. if((word >> 16) == 0)
  2106. {
  2107. new_c = replace_chars[ix+1];
  2108. break;
  2109. }
  2110. if((word >> 16) == (unsigned int)towlower2(next_in))
  2111. {
  2112. new_c = replace_chars[ix+1];
  2113. ignore_next = 1;
  2114. break;
  2115. }
  2116. }
  2117. }
  2118. if(new_c == 0)
  2119. return(c); // no substitution
  2120. if(new_c & 0xffe00000)
  2121. {
  2122. // there is a second character to be inserted
  2123. // don't convert the case of the second character unless the next letter is also upper case
  2124. c2 = new_c >> 16;
  2125. if(upper_case && iswupper2(next_in))
  2126. c2 = towupper2(c2);
  2127. *insert = c2;
  2128. new_c &= 0xffff;
  2129. }
  2130. if(upper_case)
  2131. new_c = towupper2(new_c);
  2132. *wordflags |= FLAG_CHAR_REPLACED;
  2133. return(new_c);
  2134. }
  2135. static int TranslateChar(Translator *tr, char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert, int *wordflags)
  2136. {//================================================================================================================
  2137. // To allow language specific examination and replacement of characters
  2138. int code;
  2139. int initial;
  2140. int medial;
  2141. int final;
  2142. int next2;
  2143. static const unsigned char hangul_compatibility[0x34] = {
  2144. 0, 0x00,0x01,0xaa,0x02,0xac,0xad,0x03,
  2145. 0x04,0x05,0xb0,0xb1,0xb2,0xb3,0xb4,0xb4,
  2146. 0xb6,0x06,0x07,0x08,0xb9,0x09,0x0a,0xbc,
  2147. 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x61,
  2148. 0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
  2149. 0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,
  2150. 0x72,0x73,0x74,0x75
  2151. };
  2152. // check for Korean Hangul letters
  2153. if(((code = c - 0xac00) >= 0) && (c <= 0xd7af))
  2154. {
  2155. // break a syllable hangul into 2 or 3 individual jamo
  2156. initial = (code/28)/21;
  2157. medial = (code/28) % 21;
  2158. final = code % 28;
  2159. if(initial == 11)
  2160. {
  2161. // null initial
  2162. c = medial + 0x1161;
  2163. if(final > 0)
  2164. *insert = final + 0x11a7;
  2165. }
  2166. else
  2167. {
  2168. // extact the initial and insert the remainder with a null initial
  2169. c = initial + 0x1100;
  2170. *insert = (11*28*21) + (medial*28) + final + 0xac00;
  2171. }
  2172. return(c);
  2173. }
  2174. else if(((code = c - 0x3130) >= 0) && (code < 0x34))
  2175. {
  2176. // Hangul compatibility jamo
  2177. return(hangul_compatibility[code] + 0x1100);
  2178. }
  2179. switch(tr->translator_name)
  2180. {
  2181. case L('a','f'):
  2182. case L('n','l'):
  2183. // look for 'n and replace by a special character (unicode: schwa)
  2184. if(!iswalpha2(prev_in))
  2185. {
  2186. utf8_in(&next2, &ptr[1]);
  2187. if((c == '\'') && IsSpace(next2))
  2188. {
  2189. if((next_in == 'n') && (tr->translator_name == L('a','f')))
  2190. {
  2191. // n preceded by either apostrophe or U2019 "right single quotation mark"
  2192. ptr[0] = ' '; // delete the n
  2193. return(0x0259); // replace ' by unicode schwa character
  2194. }
  2195. if((next_in == 'n') || (next_in == 't'))
  2196. {
  2197. // Dutch, [@n] and [@t]
  2198. return(0x0259); // replace ' by unicode schwa character
  2199. }
  2200. }
  2201. }
  2202. break;
  2203. }
  2204. return(SubstituteChar(tr, c, next_in, insert, wordflags));
  2205. }
  2206. static const char *UCase_ga[] = {"bp","bhf","dt","gc","hA","mb","nd","ng","ts","tA","nA",NULL};
  2207. int UpperCaseInWord(Translator *tr, char *word, int c)
  2208. {//=====================================================
  2209. int ix;
  2210. int len;
  2211. const char *p;
  2212. if(tr->translator_name == L('g','a'))
  2213. {
  2214. // Irish
  2215. for(ix=0; ; ix++)
  2216. {
  2217. if((p = UCase_ga[ix]) == NULL)
  2218. break;
  2219. len = strlen(p);
  2220. if((word[-len]==' ') && (memcmp(&word[-len+1], p, len-1) == 0))
  2221. {
  2222. if((c == p[len-1]) || ((p[len-1]=='A') && IsVowel(tr, c)))
  2223. return(1);
  2224. }
  2225. }
  2226. }
  2227. return(0);
  2228. }
  2229. void *TranslateClause(Translator *tr, FILE *f_text, const void *vp_input, int *tone_out, char **voice_change)
  2230. {//==========================================================================================================
  2231. int ix;
  2232. int c;
  2233. int cc;
  2234. unsigned int source_index=0;
  2235. unsigned int prev_source_index=0;
  2236. int source_index_word=0;
  2237. int prev_in;
  2238. int prev_out=' ';
  2239. int prev_out2;
  2240. int prev_in_save=0;
  2241. int next_in;
  2242. int next_in_nbytes;
  2243. int char_inserted=0;
  2244. int clause_pause;
  2245. int pre_pause_add=0;
  2246. int word_mark = 0;
  2247. int all_upper_case=FLAG_ALL_UPPER;
  2248. int finished;
  2249. int single_quoted;
  2250. int phoneme_mode = 0;
  2251. int dict_flags = 0; // returned from dictionary lookup
  2252. int word_flags; // set here
  2253. int next_word_flags;
  2254. int new_sentence2;
  2255. int embedded_count = 0;
  2256. int letter_count = 0;
  2257. int space_inserted = 0;
  2258. int syllable_marked = 0;
  2259. int decimal_sep_count = 0;
  2260. char *word;
  2261. char *p;
  2262. int j, k;
  2263. int n_digits;
  2264. int charix_top=0;
  2265. short charix[N_TR_SOURCE+4];
  2266. WORD_TAB words[N_CLAUSE_WORDS];
  2267. static char voice_change_name[40];
  2268. int word_count=0; // index into words
  2269. char sbuf[N_TR_SOURCE];
  2270. int terminator;
  2271. int tone;
  2272. int tone2;
  2273. if(tr==NULL)
  2274. {
  2275. return(NULL);
  2276. }
  2277. p_textinput = (unsigned char *)vp_input;
  2278. p_wchar_input = (wchar_t *)vp_input;
  2279. embedded_ix = 0;
  2280. embedded_read = 0;
  2281. pre_pause = 0;
  2282. any_stressed_words = 0;
  2283. if((clause_start_char = count_characters) < 0)
  2284. clause_start_char = 0;
  2285. clause_start_word = count_words + 1;
  2286. for(ix=0; ix<N_TR_SOURCE; ix++)
  2287. charix[ix] = 0;
  2288. terminator = ReadClause(tr, f_text, source, charix, &charix_top, N_TR_SOURCE, &tone2, voice_change_name);
  2289. if((f_logespeak != NULL) && (logging_type & 4))
  2290. {
  2291. fprintf(f_logespeak,"CLAUSE %x:\n",terminator);
  2292. for(p=source; *p != 0; p++)
  2293. fputc(*p, f_logespeak);
  2294. fprintf(f_logespeak,"ENDCLAUSE\n");
  2295. fflush(f_logespeak);
  2296. }
  2297. p = source;
  2298. charix[charix_top+1] = 0;
  2299. charix[charix_top+2] = 0x7fff;
  2300. charix[charix_top+3] = 0;
  2301. clause_pause = (terminator & 0xfff) * 10; // mS
  2302. if(terminator & CLAUSE_PAUSE_LONG)
  2303. clause_pause = clause_pause * 32 ; // pause value is *320mS not *10mS
  2304. tone = (terminator >> 12) & 0x7;
  2305. if(tone2 != 0)
  2306. {
  2307. // override the tone type
  2308. tone = tone2;
  2309. }
  2310. for(p=source; *p != 0; p++)
  2311. {
  2312. if(!isspace2(*p))
  2313. {
  2314. break;
  2315. }
  2316. }
  2317. if(*p == 0)
  2318. {
  2319. // No characters except spaces. This is not a sentence.
  2320. // Don't add this pause, just make up the previous pause to this value;
  2321. clause_pause -= max_clause_pause;
  2322. if(clause_pause < 0)
  2323. clause_pause = 0;
  2324. if(new_sentence)
  2325. terminator |= CLAUSE_BIT_SENTENCE; // carry forward an end-of-sentence indicator
  2326. max_clause_pause += clause_pause;
  2327. new_sentence2 = 0;
  2328. }
  2329. else
  2330. {
  2331. max_clause_pause = clause_pause;
  2332. new_sentence2 = new_sentence;
  2333. }
  2334. tr->clause_terminator = terminator;
  2335. if(new_sentence2)
  2336. {
  2337. count_sentences++;
  2338. if(skip_sentences > 0)
  2339. {
  2340. skip_sentences--;
  2341. if(skip_sentences == 0)
  2342. skipping_text = 0;
  2343. }
  2344. }
  2345. memset(&ph_list2[0],0,sizeof(ph_list2[0]));
  2346. ph_list2[0].phcode = phonPAUSE_SHORT;
  2347. n_ph_list2 = 1;
  2348. tr->prev_last_stress = 0;
  2349. tr->prepause_timeout = 0;
  2350. tr->expect_verb=0;
  2351. tr->expect_noun=0;
  2352. tr->expect_past=0;
  2353. tr->expect_verb_s=0;
  2354. tr->phonemes_repeat_count = 0;
  2355. tr->end_stressed_vowel=0;
  2356. tr->prev_dict_flags[0] = 0;
  2357. tr->prev_dict_flags[1] = 0;
  2358. word_count = 0;
  2359. single_quoted = 0;
  2360. word_flags = 0;
  2361. next_word_flags = 0;
  2362. sbuf[0] = 0;
  2363. sbuf[1] = ' ';
  2364. sbuf[2] = ' ';
  2365. ix = 3;
  2366. prev_in = ' ';
  2367. words[0].start = ix;
  2368. words[0].flags = 0;
  2369. finished = 0;
  2370. for(j=0; charix[j]<=0; j++);
  2371. words[0].sourceix = charix[j];
  2372. k = 0;
  2373. while(charix[j] != 0)
  2374. {
  2375. // count the number of characters (excluding multibyte continuation bytes)
  2376. if(charix[j++] != -1)
  2377. k++;
  2378. }
  2379. words[0].length = k;
  2380. while(!finished && (ix < (int)sizeof(sbuf))&& (n_ph_list2 < N_PHONEME_LIST-4))
  2381. {
  2382. prev_out2 = prev_out;
  2383. utf8_in2(&prev_out,&sbuf[ix-1],1); // prev_out = sbuf[ix-1];
  2384. if(tr->langopts.tone_numbers && IsDigit09(prev_out) && IsAlpha(prev_out2))
  2385. {
  2386. // tone numbers can be part of a word, consider them as alphabetic
  2387. prev_out = 'a';
  2388. }
  2389. if(prev_in_save != 0)
  2390. {
  2391. prev_in = prev_in_save;
  2392. prev_in_save = 0;
  2393. }
  2394. else if(source_index > 0)
  2395. {
  2396. utf8_in2(&prev_in,&source[source_index-1],1); // prev_in = source[source_index-1];
  2397. }
  2398. prev_source_index = source_index;
  2399. if(char_inserted)
  2400. {
  2401. c = char_inserted;
  2402. char_inserted = 0;
  2403. }
  2404. else
  2405. {
  2406. source_index += utf8_in(&cc,&source[source_index]); // cc = source[source_index++];
  2407. c = cc;
  2408. }
  2409. next_in_nbytes = utf8_in(&next_in,&source[source_index]);
  2410. if(c == 0)
  2411. {
  2412. finished = 1;
  2413. c = ' ';
  2414. }
  2415. if((c == CTRL_EMBEDDED) || (c == ctrl_embedded))
  2416. {
  2417. // start of embedded command in the text
  2418. int srcix = source_index-1;
  2419. if(prev_in != ' ')
  2420. {
  2421. c = ' ';
  2422. prev_in_save = c;
  2423. source_index--;
  2424. }
  2425. else
  2426. {
  2427. embedded_count += EmbeddedCommand(&source_index);
  2428. prev_in_save = prev_in;
  2429. // replace the embedded command by spaces
  2430. memset(&source[srcix],' ',source_index-srcix);
  2431. source_index = srcix;
  2432. continue;
  2433. }
  2434. }
  2435. if((option_sayas2 == SAYAS_KEY) && (c != ' '))
  2436. {
  2437. if((prev_in == ' ') && (next_in == ' '))
  2438. option_sayas2 = SAYAS_SINGLE_CHARS; // single character, speak its name
  2439. c = towlower2(c);
  2440. }
  2441. if(phoneme_mode)
  2442. {
  2443. all_upper_case = FLAG_PHONEMES;
  2444. if((c == ']') && (next_in == ']'))
  2445. {
  2446. phoneme_mode = 0;
  2447. source_index++;
  2448. c = ' ';
  2449. }
  2450. }
  2451. else if((option_sayas2 & 0xf0) == SAYAS_DIGITS)
  2452. {
  2453. if(iswdigit(c))
  2454. {
  2455. count_sayas_digits++;
  2456. if(count_sayas_digits > (option_sayas2 & 0xf))
  2457. {
  2458. // break after the specified number of digits
  2459. c = ' ';
  2460. space_inserted = 1;
  2461. count_sayas_digits = 0;
  2462. }
  2463. }
  2464. else
  2465. {
  2466. count_sayas_digits = 0;
  2467. if(iswdigit(prev_out))
  2468. {
  2469. c = ' ';
  2470. space_inserted = 1;
  2471. }
  2472. }
  2473. }
  2474. else if((option_sayas2 & 0x10) == 0)
  2475. {
  2476. // speak as words
  2477. #ifdef deleted
  2478. if((c == '/') && (tr->langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_out))
  2479. {
  2480. // TESTING, explicit indication of stressed syllable by /2 after the word
  2481. word_mark = next_in-'0';
  2482. source_index++;
  2483. c = ' ';
  2484. }
  2485. #endif
  2486. if((c == 0x92) || (c == 0xb4) || (c == 0x2019) || (c == 0x2032))
  2487. c = '\''; // 'microsoft' quote or sexed closing single quote, or prime - possibly used as apostrophe
  2488. if(((c == 0x2018) || (c == '?')) && IsAlpha(prev_out) && IsAlpha(next_in))
  2489. {
  2490. // ? between two letters may be a smart-quote replaced by ?
  2491. c = '\'';
  2492. }
  2493. if(c == CHAR_EMPHASIS)
  2494. {
  2495. // this character is a marker that the previous word is the focus of the clause
  2496. c = ' ';
  2497. word_flags |= FLAG_FOCUS;
  2498. }
  2499. if(c == CHAR_COMMA_BREAK)
  2500. {
  2501. c = ' ';
  2502. word_flags |= FLAG_COMMA_AFTER;
  2503. }
  2504. c = TranslateChar(tr, &source[source_index], prev_in,c, next_in, &char_inserted, &word_flags); // optional language specific function
  2505. if(c == 8)
  2506. continue; // ignore this character
  2507. if(char_inserted)
  2508. next_in = char_inserted;
  2509. // allow certain punctuation within a word (usually only apostrophe)
  2510. if(!IsAlpha(c) && !IsSpace(c) && (wcschr(tr->punct_within_word,c) == 0))
  2511. {
  2512. if(IsAlpha(prev_out))
  2513. {
  2514. if(tr->langopts.tone_numbers && IsDigit09(c) && !IsDigit09(next_in))
  2515. {
  2516. // allow a tone number as part of the word
  2517. }
  2518. else
  2519. {
  2520. c = ' '; // ensure we have an end-of-word terminator
  2521. space_inserted = 1;
  2522. }
  2523. }
  2524. }
  2525. if(iswdigit(prev_out))
  2526. {
  2527. if(!iswdigit(c) && (c != '.') && (c != ',') && (c != ' '))
  2528. {
  2529. c = ' '; // terminate digit string with a space
  2530. space_inserted = 1;
  2531. }
  2532. }
  2533. else
  2534. {
  2535. if(prev_in != ',')
  2536. {
  2537. decimal_sep_count = 0;
  2538. }
  2539. }
  2540. if(c == '[')
  2541. {
  2542. if((next_in == '\002') || ((next_in == '[') && option_phoneme_input))
  2543. {
  2544. // "[\002" is used internally to start phoneme mode
  2545. phoneme_mode = FLAG_PHONEMES;
  2546. source_index++;
  2547. continue;
  2548. }
  2549. }
  2550. if(IsAlpha(c))
  2551. {
  2552. if(!IsAlpha(prev_out) || (tr->langopts.ideographs && ((c > 0x3040) || (prev_out > 0x3040))))
  2553. {
  2554. if(wcschr(tr->punct_within_word,prev_out) == 0)
  2555. letter_count = 0; // don't reset count for an apostrophy within a word
  2556. if((prev_out != ' ') && (wcschr(tr->punct_within_word,prev_out) == 0))
  2557. {
  2558. // start of word, insert space if not one there already
  2559. c = ' ';
  2560. space_inserted = 1;
  2561. if(!IsBracket(prev_out)) // ?? perhaps only set FLAG_NOSPACE for . - / (hyphenated words, URLs, etc)
  2562. {
  2563. next_word_flags |= FLAG_NOSPACE;
  2564. }
  2565. }
  2566. else
  2567. {
  2568. if(iswupper2(c))
  2569. word_flags |= FLAG_FIRST_UPPER;
  2570. if((prev_out == ' ') && iswdigit(sbuf[ix-2]) && !iswdigit(prev_in))
  2571. {
  2572. // word, following a number, but with a space between
  2573. // Add an extra space, to distinguish "2 a" from "2a"
  2574. sbuf[ix++] = ' ';
  2575. words[word_count].start++;
  2576. }
  2577. }
  2578. }
  2579. if(c != ' ')
  2580. {
  2581. letter_count++;
  2582. if(tr->letter_bits_offset > 0)
  2583. {
  2584. if(((c < 0x250) && (prev_out >= tr->letter_bits_offset)) ||
  2585. ((c >= tr->letter_bits_offset) && (letter_count > 1) && (prev_out < 0x250)))
  2586. {
  2587. // Don't mix native and Latin characters in the same word
  2588. // Break into separate words
  2589. if(IsAlpha(prev_out))
  2590. {
  2591. c = ' ';
  2592. space_inserted = 1;
  2593. word_flags |= FLAG_HYPHEN_AFTER;
  2594. next_word_flags |= FLAG_HYPHEN;
  2595. }
  2596. }
  2597. }
  2598. }
  2599. if(iswupper2(c))
  2600. {
  2601. c = towlower2(c);
  2602. if((j = tr->langopts.param[LOPT_CAPS_IN_WORD]) > 0)
  2603. {
  2604. if((j == 2) && (syllable_marked == 0))
  2605. {
  2606. char_inserted = c;
  2607. c = 0x2c8; // stress marker
  2608. syllable_marked = 1;
  2609. }
  2610. }
  2611. else
  2612. {
  2613. if(iswlower2(prev_in))
  2614. {
  2615. // lower case followed by upper case in a word
  2616. if(UpperCaseInWord(tr, &sbuf[ix], c) == 1)
  2617. {
  2618. // convert to lower case and continue
  2619. c = towlower2(c);
  2620. }
  2621. else
  2622. {
  2623. c = ' '; // lower case followed by upper case, treat as new word
  2624. space_inserted = 1;
  2625. prev_in_save = c;
  2626. // next_word_flags |= FLAG_NOSPACE; // problem: prevents FLAG_HAS_DOT being set
  2627. }
  2628. }
  2629. else if((c != ' ') && iswupper2(prev_in) && iswlower2(next_in))
  2630. {
  2631. int next2_in;
  2632. utf8_in(&next2_in,&source[source_index + next_in_nbytes]);
  2633. if((tr->translator_name == L('n','l')) && (letter_count==2) && (c == 'j') && (prev_in == 'I'))
  2634. {
  2635. // Dutch words may capitalise initial IJ, don't split
  2636. }
  2637. else
  2638. if(IsAlpha(next2_in))
  2639. {
  2640. // changing from upper to lower case, start new word at the last uppercase, if 3 or more letters
  2641. c = ' ';
  2642. space_inserted = 1;
  2643. prev_in_save = c;
  2644. next_word_flags |= FLAG_NOSPACE;
  2645. }
  2646. }
  2647. }
  2648. }
  2649. else
  2650. {
  2651. if((all_upper_case) && (letter_count > 2))
  2652. {
  2653. if((c == 's') && (next_in==' '))
  2654. {
  2655. c = ' ';
  2656. all_upper_case |= FLAG_HAS_PLURAL;
  2657. if(sbuf[ix-1] == '\'')
  2658. sbuf[ix-1] = ' ';
  2659. }
  2660. else
  2661. all_upper_case = 0; // current word contains lower case letters, not "'s"
  2662. }
  2663. else
  2664. all_upper_case = 0;
  2665. }
  2666. }
  2667. else if(c=='-')
  2668. {
  2669. if(!IsSpace(prev_in) && IsAlpha(next_in))
  2670. {
  2671. if(prev_out != ' ')
  2672. {
  2673. // previous 'word' not yet ended (not alpha or numeric), start new word now.
  2674. c = ' ';
  2675. space_inserted = 1;
  2676. }
  2677. else
  2678. {
  2679. // '-' between two letters is a hyphen, treat as a space
  2680. word_flags |= FLAG_HYPHEN;
  2681. if(word_count > 0)
  2682. words[word_count-1].flags |= FLAG_HYPHEN_AFTER;
  2683. c = ' ';
  2684. }
  2685. }
  2686. else if((prev_in==' ') && (next_in==' '))
  2687. {
  2688. // ' - ' dash between two spaces, treat as pause
  2689. c = ' ';
  2690. pre_pause_add = 4;
  2691. }
  2692. else if(next_in=='-')
  2693. {
  2694. // double hyphen, treat as pause
  2695. source_index++;
  2696. c = ' ';
  2697. pre_pause_add = 4;
  2698. }
  2699. else if((prev_out == ' ') && IsAlpha(prev_out2) && !IsAlpha(prev_in))
  2700. {
  2701. // insert extra space between a word + space + hyphen, to distinguish 'a -2' from 'a-2'
  2702. sbuf[ix++] = ' ';
  2703. words[word_count].start++;
  2704. }
  2705. }
  2706. else if(c == '.')
  2707. {
  2708. if(prev_out == '.')
  2709. {
  2710. // multiple dots, separate by spaces. Note >3 dots has been replaced by elipsis
  2711. c = ' ';
  2712. space_inserted = 1;
  2713. }
  2714. else if((word_count > 0) && !(words[word_count-1].flags & FLAG_NOSPACE) && IsAlpha(prev_in))
  2715. {
  2716. // dot after a word, with space following, probably an abbreviation
  2717. words[word_count-1].flags |= FLAG_HAS_DOT;
  2718. if(IsSpace(next_in) || (next_in == '-'))
  2719. c = ' '; // remove the dot if it's followed by a space or hyphen, so that it's not pronounced
  2720. }
  2721. }
  2722. else if(c == '\'')
  2723. {
  2724. if(((prev_in == '.') || iswalnum(prev_in)) && IsAlpha(next_in))
  2725. {
  2726. // between two letters, or in an abbreviation (eg. u.s.a.'s). Consider the apostrophe as part of the word
  2727. single_quoted = 0;
  2728. }
  2729. else if((tr->langopts.param[LOPT_APOSTROPHE] & 1) && IsAlpha(next_in))
  2730. {
  2731. single_quoted = 0; // apostrophe at start of word is part of the word
  2732. }
  2733. else if((tr->langopts.param[LOPT_APOSTROPHE] & 2) && IsAlpha(prev_in))
  2734. {
  2735. single_quoted = 0; // apostrophe at end of word is part of the word
  2736. }
  2737. else if((wcschr(tr->char_plus_apostrophe,prev_in) != 0) && (prev_out2 == ' '))
  2738. {
  2739. // consider single character plus apostrophe as a word
  2740. single_quoted = 0;
  2741. if(next_in == ' ')
  2742. {
  2743. source_index++; // skip following space
  2744. }
  2745. }
  2746. else
  2747. {
  2748. if((prev_out == 's') && (single_quoted==0))
  2749. {
  2750. // looks like apostrophe after an 's'
  2751. c = ' ';
  2752. }
  2753. else
  2754. {
  2755. if(IsSpace(prev_out))
  2756. single_quoted = 1;
  2757. else
  2758. single_quoted = 0;
  2759. pre_pause_add = 4; // single quote
  2760. c = ' ';
  2761. }
  2762. }
  2763. }
  2764. else
  2765. #ifdef deleted
  2766. // Brackets are now recognised in TranslateRules()
  2767. if(IsBracket(c))
  2768. {
  2769. pre_pause_add = 4;
  2770. c = ' ';
  2771. }
  2772. else
  2773. #endif
  2774. if(lookupwchar(breaks,c) != 0)
  2775. {
  2776. c = ' '; // various characters to treat as space
  2777. }
  2778. else if(iswdigit(c))
  2779. {
  2780. if(tr->langopts.tone_numbers && IsAlpha(prev_out) && !IsDigit(next_in))
  2781. {
  2782. }
  2783. else if((prev_out != ' ') && !iswdigit(prev_out))
  2784. {
  2785. if((prev_out != tr->langopts.decimal_sep) || ((decimal_sep_count > 0) && (tr->langopts.decimal_sep == ',')))
  2786. {
  2787. c = ' ';
  2788. space_inserted = 1;
  2789. }
  2790. else
  2791. {
  2792. decimal_sep_count = 1;
  2793. }
  2794. }
  2795. else if((prev_out == ' ') && IsAlpha(prev_out2) && !IsAlpha(prev_in))
  2796. {
  2797. // insert extra space between a word and a number, to distinguish 'a 2' from 'a2'
  2798. sbuf[ix++] = ' ';
  2799. words[word_count].start++;
  2800. }
  2801. }
  2802. }
  2803. if(IsSpace(c))
  2804. {
  2805. if(prev_out == ' ')
  2806. {
  2807. word_flags |= FLAG_MULTIPLE_SPACES;
  2808. continue; // multiple spaces
  2809. }
  2810. if((cc == 0x09) || (cc == 0x0a))
  2811. {
  2812. next_word_flags |= FLAG_MULTIPLE_SPACES; // tab or newline, not a simple space
  2813. }
  2814. if(space_inserted)
  2815. {
  2816. // count the number of characters since the start of the word
  2817. j = 0;
  2818. k = source_index - 1;
  2819. while((k >= source_index_word) && (charix[k] != 0))
  2820. {
  2821. if(charix[k] > 0) // don't count initial bytes of multi-byte character
  2822. j++;
  2823. k--;
  2824. }
  2825. words[word_count].length = j;
  2826. }
  2827. source_index_word = source_index;
  2828. // end of 'word'
  2829. sbuf[ix++] = ' ';
  2830. if((word_count < N_CLAUSE_WORDS-1) && (ix > words[word_count].start))
  2831. {
  2832. if(embedded_count > 0)
  2833. {
  2834. // there are embedded commands before this word
  2835. embedded_list[embedded_ix-1] |= 0x80; // terminate list of commands for this word
  2836. words[word_count].flags |= FLAG_EMBEDDED;
  2837. embedded_count = 0;
  2838. }
  2839. words[word_count].pre_pause = pre_pause;
  2840. words[word_count].flags |= (all_upper_case | word_flags | word_emphasis);
  2841. words[word_count].wmark = word_mark;
  2842. if(pre_pause > 0)
  2843. {
  2844. // insert an extra space before the word, to prevent influence from previous word across the pause
  2845. for(j=ix; j>words[word_count].start; j--)
  2846. {
  2847. sbuf[j] = sbuf[j-1];
  2848. }
  2849. sbuf[j] = ' ';
  2850. words[word_count].start++;
  2851. ix++;
  2852. }
  2853. word_count++;
  2854. words[word_count].start = ix;
  2855. words[word_count].flags = 0;
  2856. for(j=source_index; charix[j] <= 0; j++); // skip blanks
  2857. words[word_count].sourceix = charix[j];
  2858. k = 0;
  2859. while(charix[j] != 0)
  2860. {
  2861. // count the number of characters (excluding multibyte continuation bytes)
  2862. if(charix[j++] != -1)
  2863. k++;
  2864. }
  2865. words[word_count].length = k;
  2866. word_flags = next_word_flags;
  2867. next_word_flags = 0;
  2868. pre_pause = 0;
  2869. word_mark = 0;
  2870. all_upper_case = FLAG_ALL_UPPER;
  2871. syllable_marked = 0;
  2872. }
  2873. if(space_inserted)
  2874. {
  2875. source_index = prev_source_index; // rewind to the previous character
  2876. char_inserted = 0;
  2877. space_inserted = 0;
  2878. }
  2879. }
  2880. else
  2881. {
  2882. if((ix < (N_TR_SOURCE - 4)))
  2883. ix += utf8_out(c,&sbuf[ix]); // sbuf[ix++] = c;
  2884. }
  2885. if(pre_pause_add > pre_pause)
  2886. pre_pause = pre_pause_add;
  2887. pre_pause_add = 0;
  2888. }
  2889. if((word_count==0) && (embedded_count > 0))
  2890. {
  2891. // add a null 'word' to carry the embedded command flag
  2892. embedded_list[embedded_ix-1] |= 0x80;
  2893. words[word_count].flags |= FLAG_EMBEDDED;
  2894. word_count = 1;
  2895. }
  2896. tr->clause_end = &sbuf[ix-1];
  2897. sbuf[ix] = 0;
  2898. words[0].pre_pause = 0; // don't add extra pause at beginning of clause
  2899. words[word_count].pre_pause = 8;
  2900. if(word_count > 0)
  2901. {
  2902. ix = word_count-1;
  2903. while((ix > 0) && (IsBracket(sbuf[words[ix].start])))
  2904. ix--; // the last word is a bracket, mark the previous word as last
  2905. words[ix].flags |= FLAG_LAST_WORD;
  2906. // FLAG_NOSPACE check to avoid recognizing .mr -mr
  2907. if((terminator & CLAUSE_DOT) && !(words[word_count-1].flags & FLAG_NOSPACE))
  2908. words[word_count-1].flags |= FLAG_HAS_DOT;
  2909. }
  2910. words[0].flags |= FLAG_FIRST_WORD;
  2911. for(ix=0; ix < word_count; ix++)
  2912. {
  2913. int nx;
  2914. int c_temp;
  2915. char *pn;
  2916. char *pw;
  2917. int nw;
  2918. char number_buf[150];
  2919. WORD_TAB num_wtab[50]; // copy of 'words', when splitting numbers into parts
  2920. // start speaking at a specified word position in the text?
  2921. count_words++;
  2922. if(skip_words > 0)
  2923. {
  2924. skip_words--;
  2925. if(skip_words == 0)
  2926. skipping_text = 0;
  2927. }
  2928. if(skipping_text)
  2929. continue;
  2930. current_alphabet = NULL;
  2931. // digits should have been converted to Latin alphabet ('0' to '9')
  2932. word = pw = &sbuf[words[ix].start];
  2933. if(iswdigit(word[0]) && (tr->langopts.break_numbers != BREAK_THOUSANDS))
  2934. {
  2935. // Languages with 100000 numbers. Remove thousands separators so that we can insert them again later
  2936. pn = number_buf;
  2937. while(pn < &number_buf[sizeof(number_buf)-20])
  2938. {
  2939. if(iswdigit(*pw))
  2940. {
  2941. *pn++ = *pw++;
  2942. }
  2943. else if((*pw == tr->langopts.thousands_sep) && (pw[1] == ' ')
  2944. && iswdigit(pw[2]) && (pw[3] != ' ') && (pw[4] != ' ')) // don't allow only 1 or 2 digits in the final part
  2945. {
  2946. pw += 2;
  2947. ix++; // skip "word"
  2948. }
  2949. else
  2950. {
  2951. nx = pw - word;
  2952. memset(word,' ',nx);
  2953. nx = pn - number_buf;
  2954. memcpy(word,number_buf,nx);
  2955. break;
  2956. }
  2957. }
  2958. pw = word;
  2959. }
  2960. for(n_digits=0; iswdigit(word[n_digits]); n_digits++); // count consecutive digits
  2961. if(n_digits > 4)
  2962. {
  2963. // word is entirely digits, insert commas and break into 3 digit "words"
  2964. number_buf[0] = ' ';
  2965. pn = &number_buf[1];
  2966. nx = n_digits;
  2967. nw = 0;
  2968. if((n_digits > tr->langopts.max_digits) || (word[0] == '0'))
  2969. words[ix].flags |= FLAG_INDIVIDUAL_DIGITS;
  2970. while(pn < &number_buf[sizeof(number_buf)-20])
  2971. {
  2972. if(!IsDigit09(c = *pw++) && (c != tr->langopts.decimal_sep))
  2973. break;
  2974. *pn++ = c;
  2975. nx--;
  2976. if((nx > 0) && (tr->langopts.break_numbers & (1 << nx)))
  2977. {
  2978. memcpy(&num_wtab[nw++], &words[ix], sizeof(WORD_TAB)); // copy the 'words' entry for each word of numbers
  2979. if(tr->langopts.thousands_sep != ' ')
  2980. {
  2981. *pn++ = tr->langopts.thousands_sep;
  2982. }
  2983. *pn++ = ' ';
  2984. if((words[ix].flags & FLAG_INDIVIDUAL_DIGITS) == 0)
  2985. {
  2986. if(tr->langopts.break_numbers & (1 << (nx-1)))
  2987. {
  2988. // the next group only has 1 digits, make it three
  2989. *pn++ = '0';
  2990. *pn++ = '0';
  2991. }
  2992. if(tr->langopts.break_numbers & (1 << (nx-2)))
  2993. {
  2994. // the next group only has 2 digits (eg. Indian languages), make it three
  2995. *pn++ = '0';
  2996. }
  2997. }
  2998. }
  2999. }
  3000. pw--;
  3001. memcpy(&num_wtab[nw], &words[ix], sizeof(WORD_TAB)*2); // the original number word, and the word after it
  3002. for(j=1; j<=nw; j++)
  3003. {
  3004. num_wtab[j].flags &= ~(FLAG_MULTIPLE_SPACES | FLAG_EMBEDDED); // don't use these flags for subsequent parts when splitting a number
  3005. }
  3006. // include the next few characters, in case there are an ordinal indicator or other suffix
  3007. memcpy(pn, pw, 16);
  3008. pn[16] = 0;
  3009. nw = 0;
  3010. for(pw = &number_buf[1]; pw < pn;)
  3011. {
  3012. // keep wflags for each part, for FLAG_HYPHEN_AFTER
  3013. dict_flags = TranslateWord2(tr, pw, &num_wtab[nw++], words[ix].pre_pause,0 );
  3014. while(*pw++ != ' ');
  3015. words[ix].pre_pause = 0;
  3016. }
  3017. }
  3018. else
  3019. {
  3020. pre_pause = 0;
  3021. dict_flags = TranslateWord2(tr, word, &words[ix], words[ix].pre_pause, words[ix+1].pre_pause);
  3022. if(pre_pause > words[ix+1].pre_pause)
  3023. {
  3024. words[ix+1].pre_pause = pre_pause;
  3025. pre_pause = 0;
  3026. }
  3027. if(dict_flags & FLAG_SPELLWORD)
  3028. {
  3029. // redo the word, speaking single letters
  3030. for(pw = word; *pw != ' ';)
  3031. {
  3032. memset(number_buf,' ',9);
  3033. nx = utf8_in(&c_temp, pw);
  3034. memcpy(&number_buf[2],pw,nx);
  3035. TranslateWord2(tr, &number_buf[2], &words[ix], 0, 0 );
  3036. pw += nx;
  3037. }
  3038. }
  3039. if((dict_flags & (FLAG_ALLOW_DOT | FLAG_NEEDS_DOT)) && (ix == word_count - 1 - dictionary_skipwords) && (terminator & CLAUSE_DOT))
  3040. {
  3041. // probably an abbreviation such as Mr. or B. rather than end of sentence
  3042. clause_pause = 10;
  3043. tone = 4;
  3044. }
  3045. }
  3046. if(dict_flags & FLAG_SKIPWORDS)
  3047. {
  3048. // dictionary indicates skip next word(s)
  3049. while(dictionary_skipwords > 0)
  3050. {
  3051. words[ix+dictionary_skipwords].flags |= FLAG_DELETE_WORD;
  3052. dictionary_skipwords--;
  3053. }
  3054. }
  3055. }
  3056. if(embedded_read < embedded_ix)
  3057. {
  3058. // any embedded commands not yet processed?
  3059. Word_EmbeddedCmd();
  3060. }
  3061. for(ix=0; ix<2; ix++)
  3062. {
  3063. // terminate the clause with 2 PAUSE phonemes
  3064. PHONEME_LIST2 *p2;
  3065. p2 = &ph_list2[n_ph_list2 + ix];
  3066. p2->phcode = phonPAUSE;
  3067. p2->stresslevel = 0;
  3068. p2->sourceix = source_index;
  3069. p2->synthflags = 0;
  3070. }
  3071. n_ph_list2 += 2;
  3072. if(count_words == 0)
  3073. {
  3074. clause_pause = 0;
  3075. }
  3076. if(Eof() && ((word_count == 0) || (option_endpause==0)))
  3077. {
  3078. clause_pause = 10;
  3079. }
  3080. MakePhonemeList(tr, clause_pause, new_sentence2);
  3081. phoneme_list[N_PHONEME_LIST].ph = NULL; // recognize end of phoneme_list array, in Generate()
  3082. phoneme_list[N_PHONEME_LIST].sourceix = 1;
  3083. if(embedded_count) // ???? is this needed
  3084. {
  3085. phoneme_list[n_phoneme_list-2].synthflags = SFLAG_EMBEDDED;
  3086. embedded_list[embedded_ix-1] |= 0x80;
  3087. embedded_list[embedded_ix] = 0x80;
  3088. }
  3089. prev_clause_pause = clause_pause;
  3090. if(tone_out != NULL)
  3091. *tone_out = tone;
  3092. new_sentence = 0;
  3093. if(terminator & CLAUSE_BIT_SENTENCE)
  3094. {
  3095. new_sentence = 1; // next clause is a new sentence
  3096. }
  3097. if(voice_change != NULL)
  3098. {
  3099. // return new voice name if an embedded voice change command terminated the clause
  3100. if(terminator & CLAUSE_BIT_VOICE)
  3101. *voice_change = voice_change_name;
  3102. else
  3103. *voice_change = NULL;
  3104. }
  3105. if(Eof() || (vp_input==NULL))
  3106. return(NULL);
  3107. if(option_multibyte == espeakCHARS_WCHAR)
  3108. return((void *)p_wchar_input);
  3109. else
  3110. return((void *)p_textinput);
  3111. } // end of TranslateClause
  3112. void InitText(int control)
  3113. {//=======================
  3114. count_sentences = 0;
  3115. count_words = 0;
  3116. end_character_position = 0;
  3117. skip_sentences = 0;
  3118. skip_marker[0] = 0;
  3119. skip_words = 0;
  3120. skip_characters = 0;
  3121. skipping_text = 0;
  3122. new_sentence = 1;
  3123. prev_clause_pause = 0;
  3124. option_sayas = 0;
  3125. option_sayas2 = 0;
  3126. option_emphasis = 0;
  3127. word_emphasis = 0;
  3128. embedded_flag = 0;
  3129. InitText2();
  3130. if((control & espeakKEEP_NAMEDATA) == 0)
  3131. {
  3132. InitNamedata();
  3133. }
  3134. }