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

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