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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <wctype.h>
  25. #include <wchar.h>
  26. #include "speak_lib.h"
  27. #include "speech.h"
  28. #include "phoneme.h"
  29. #include "synthesize.h"
  30. #include "voice.h"
  31. #include "translate.h"
  32. #define WORD_STRESS_CHAR '*'
  33. Translator *translator = NULL; // the main translator
  34. static Translator *translator2 = NULL; // secondary translator for certain words
  35. static char translator2_language[20] = {0};
  36. FILE *f_trans = NULL; // phoneme output text
  37. int option_tone1 = 0;
  38. int option_tone2 = 0;
  39. int option_phonemes = 0;
  40. int option_phoneme_events = 0;
  41. int option_quiet = 0;
  42. int option_endpause = 0; // suppress pause after end of text
  43. int option_capitals = 0;
  44. int option_punctuation = 0;
  45. int option_sayas = 0;
  46. int option_sayas2 = 0; // used in translate_clause()
  47. int option_emphasis = 0;
  48. int option_ssml = 0;
  49. int option_phoneme_input = 1; // allow [[phonemes]] in input
  50. int option_phoneme_variants = 0; // 0= don't display phoneme variant mnemonics
  51. int count_sayas_digits;
  52. int skip_sentences;
  53. int skip_words;
  54. int skip_characters;
  55. char skip_marker[N_MARKER_LENGTH];
  56. int skipping_text; // waiting until word count, sentence count, or named marker is reached
  57. int end_character_position;
  58. int count_sentences;
  59. int count_words;
  60. int clause_start_char;
  61. int clause_start_word;
  62. int new_sentence;
  63. int prev_clause_pause=0;
  64. int max_clause_pause = 0;
  65. wchar_t option_punctlist[N_PUNCTLIST]={0};
  66. char ctrl_embedded = '\001'; // to allow an alternative CTRL for embedded commands
  67. int option_multibyte=espeakCHARS_AUTO; // 0=auto, 1=utf8, 2=8bit, 3=wchar
  68. // these are overridden by defaults set in the "speak" file
  69. int option_linelength = 0;
  70. #define N_EMBEDDED_LIST 250
  71. static int embedded_ix;
  72. static int embedded_read;
  73. unsigned int embedded_list[N_EMBEDDED_LIST];
  74. // the source text of a single clause
  75. #define N_TR_SOURCE 350
  76. static char source[N_TR_SOURCE+40]; // extra space for embedded command & voice change info at end
  77. int n_replace_phonemes;
  78. REPLACE_PHONEMES replace_phonemes[N_REPLACE_PHONEMES];
  79. // brackets, also 0x2014 to 0x021f which don't need to be in this list
  80. static const unsigned short brackets[] = {
  81. '(',')','[',']','{','}','<','>','"','\'','`',
  82. 0xab,0xbb, // double angle brackets
  83. 0x300a,0x300b, // double angle brackets (ideograph)
  84. 0};
  85. // other characters which break a word, but don't produce a pause
  86. static const unsigned short breaks[] = {'_', 0};
  87. // Translate character codes 0xA0 to 0xFF into their unicode values
  88. // ISO_8859_1 is set as default
  89. static const unsigned short ISO_8859_1[0x60] = {
  90. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0
  91. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8
  92. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0
  93. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8
  94. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  95. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  96. 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  97. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, // d8
  98. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  99. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  100. 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  101. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff, // f8
  102. };
  103. static const unsigned short ISO_8859_2[0x60] = {
  104. 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, // a0
  105. 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, // a8
  106. 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, // b0
  107. 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, // b8
  108. 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, // c0
  109. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, // c8
  110. 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, // d0
  111. 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, // d8
  112. 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, // e0
  113. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, // e8
  114. 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, // f0
  115. 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, // f8
  116. };
  117. static const unsigned short ISO_8859_3[0x60] = {
  118. 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, // a0
  119. 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b, // a8
  120. 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, // b0
  121. 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0x0000, 0x017c, // b8
  122. 0x00c0, 0x00c1, 0x00c2, 0x0000, 0x00c4, 0x010a, 0x0108, 0x00c7, // c0
  123. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  124. 0x0000, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, // d0
  125. 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df, // d8
  126. 0x00e0, 0x00e1, 0x00e2, 0x0000, 0x00e4, 0x010b, 0x0109, 0x00e7, // e0
  127. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  128. 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, // f0
  129. 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9, // f8
  130. };
  131. static const unsigned short ISO_8859_4[0x60] = {
  132. 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7, // a0
  133. 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, // a8
  134. 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, // b0
  135. 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, // b8
  136. 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, // c0
  137. 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, // c8
  138. 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  139. 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, // d8
  140. 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, // e0
  141. 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, // e8
  142. 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  143. 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9, // f8
  144. };
  145. static const unsigned short ISO_8859_5[0x60] = {
  146. 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, // a0 Cyrillic
  147. 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f, // a8
  148. 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, // b0
  149. 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, // b8
  150. 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, // c0
  151. 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, // c8
  152. 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, // d0
  153. 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, // d8
  154. 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, // e0
  155. 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, // e8
  156. 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, // f0
  157. 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f, // f8
  158. };
  159. static const unsigned short ISO_8859_7[0x60] = {
  160. 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, // a0 Greek
  161. 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015, // a8
  162. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7, // b0
  163. 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, // b8
  164. 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, // c0
  165. 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, // c8
  166. 0x03a0, 0x03a1, 0x0000, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, // d0
  167. 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, // d8
  168. 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, // e0
  169. 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, // e8
  170. 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, // f0
  171. 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000, // f8
  172. };
  173. static const unsigned short ISO_8859_9[0x60] = {
  174. 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, // a0
  175. 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, // a8
  176. 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, // b0
  177. 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, // b8
  178. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  179. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  180. 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, // d0
  181. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df, // d8
  182. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  183. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  184. 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, // f0
  185. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff, // f8
  186. };
  187. static const unsigned short ISO_8859_14[0x60] = {
  188. 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, // a0 Welsh
  189. 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178, // a8
  190. 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56, // b0
  191. 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, // b8
  192. 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, // c0
  193. 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, // c8
  194. 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a, // d0
  195. 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df, // d8
  196. 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, // e0
  197. 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, // e8
  198. 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, // f0
  199. 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff, // f8
  200. };
  201. static const unsigned short KOI8_R[0x60] = {
  202. 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, // a0 Russian
  203. 0x2557, 0x2558, 0x2559, 0x255a, 0x255b, 0x255c, 0x255d, 0x255e, // a8
  204. 0x255f, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, // b0
  205. 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b, 0x256c, 0x00a9, // b8
  206. 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, // c0
  207. 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, // c8
  208. 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, // d0
  209. 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, // d8
  210. 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, // e0
  211. 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, // e8
  212. 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, // f0
  213. 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a, // f8
  214. };
  215. static const unsigned short ISCII[0x60] = {
  216. 0x0020, 0x0901, 0x0902, 0x0903, 0x0905, 0x0906, 0x0907, 0x0908, // a0
  217. 0x0909, 0x090a, 0x090b, 0x090e, 0x090f, 0x0910, 0x090d, 0x0912, // a8
  218. 0x0913, 0x0914, 0x0911, 0x0915, 0x0916, 0x0917, 0x0918, 0x0919, // b0
  219. 0x091a, 0x091b, 0x091c, 0x091d, 0x091e, 0x091f, 0x0920, 0x0921, // b8
  220. 0x0922, 0x0923, 0x0924, 0x0925, 0x0926, 0x0927, 0x0928, 0x0929, // c0
  221. 0x092a, 0x092b, 0x092c, 0x092d, 0x092e, 0x092f, 0x095f, 0x0930, // c8
  222. 0x0931, 0x0932, 0x0933, 0x0934, 0x0935, 0x0936, 0x0937, 0x0938, // d0
  223. 0x0939, 0x0020, 0x093e, 0x093f, 0x0940, 0x0941, 0x0942, 0x0943, // d8
  224. 0x0946, 0x0947, 0x0948, 0x0945, 0x094a, 0x094b, 0x094c, 0x0949, // e0
  225. 0x094d, 0x093c, 0x0964, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, // e8
  226. 0x0020, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, // f0
  227. 0x0037, 0x0038, 0x0039, 0x20, 0x20, 0x20, 0x20, 0x20, // f8
  228. };
  229. const unsigned short *charsets[N_CHARSETS] = {
  230. ISO_8859_1,
  231. ISO_8859_1,
  232. ISO_8859_2,
  233. ISO_8859_3,
  234. ISO_8859_4,
  235. ISO_8859_5,
  236. ISO_8859_1,
  237. ISO_8859_7,
  238. ISO_8859_1,
  239. ISO_8859_9,
  240. ISO_8859_1,
  241. ISO_8859_1,
  242. ISO_8859_1,
  243. ISO_8859_1,
  244. ISO_8859_14,
  245. ISO_8859_1,
  246. ISO_8859_1,
  247. ISO_8859_1,
  248. KOI8_R, // 18
  249. ISCII };
  250. // Tables of the relative lengths of vowels, depending on the
  251. // type of the two phonemes that follow
  252. // indexes are the "length_mod" value for the following phonemes
  253. // use this table if vowel is not the last in the word
  254. static unsigned char length_mods_en[100] = {
  255. /* a , t s n d z r N <- next */
  256. 100,120,100,105,100,110,110,100, 95, 100, /* a <- next2 */
  257. 105,120,105,110,125,130,135,115,125, 100, /* , */
  258. 105,120, 75,100, 75,105,120, 85, 75, 100, /* t */
  259. 105,120, 85,105, 95,115,120,100, 95, 100, /* s */
  260. 110,120, 95,105,100,115,120,100,100, 100, /* n */
  261. 105,120,100,105, 95,115,120,110, 95, 100, /* d */
  262. 105,120,100,105,105,122,125,110,105, 100, /* z */
  263. 105,120,100,105,105,122,125,110,105, 100, /* r */
  264. 105,120, 95,105,100,115,120,110,100, 100, /* N */
  265. 100,120,100,100,100,100,100,100,100, 100 }; // SPARE
  266. // as above, but for the last syllable in a word
  267. static unsigned char length_mods_en0[100] = {
  268. /* a , t s n d z r N <- next */
  269. 100,150,100,105,110,115,110,110,110, 100, /* a <- next2 */
  270. 105,150,105,110,125,135,140,115,135, 100, /* , */
  271. 105,150, 90,105, 90,122,135,100, 90, 100, /* t */
  272. 105,150,100,105,100,122,135,100,100, 100, /* s */
  273. 105,150,100,105,105,115,135,110,105, 100, /* n */
  274. 105,150,100,105,105,122,130,120,125, 100, /* d */
  275. 105,150,100,105,110,122,125,115,110, 100, /* z */
  276. 105,150,100,105,105,122,135,120,105, 100, /* r */
  277. 105,150,100,105,105,115,135,110,105, 100, /* N */
  278. 100,100,100,100,100,100,100,100,100, 100 }; // SPARE
  279. static unsigned char length_mods_equal[100] = {
  280. /* a , t s n d z r N <- next */
  281. 110,110,110,110,110,110,110,110,110, 110, /* a <- next2 */
  282. 110,110,110,110,110,110,110,110,110, 110, /* , */
  283. 110,110,110,110,110,110,110,110,110, 110, /* t */
  284. 110,110,110,110,110,110,110,110,110, 110, /* s */
  285. 110,110,110,110,110,110,110,110,110, 110, /* n */
  286. 110,110,110,110,110,110,110,110,110, 110, /* d */
  287. 110,110,110,110,110,110,110,110,110, 110, /* z */
  288. 110,110,110,110,110,110,110,110,110, 110, /* r */
  289. 110,110,110,110,110,110,110,110,110, 110, /* N */
  290. 110,110,110,110,110,110,110,110,110, 110 }; // SPARE
  291. unsigned char *length_mod_tabs[6] = {
  292. length_mods_en,
  293. length_mods_en, // 1
  294. length_mods_en0, // 2
  295. length_mods_equal, // 3
  296. length_mods_equal, // 4
  297. length_mods_equal // 5
  298. };
  299. /* index by 0=. 1=, 2=?, 3=! 4=none */
  300. static unsigned char punctuation_to_tone[4][5] = {
  301. {0,1,1,2,0},
  302. {3,4,4,5,3},
  303. {6,7,7,8,6},
  304. {9,10,10,11,9} };
  305. void SetLengthMods(Translator *tr, int value)
  306. {//==========================================
  307. int value2;
  308. tr->langopts.length_mods0 = tr->langopts.length_mods = length_mod_tabs[value % 100];
  309. if((value2 = value / 100) != 0)
  310. {
  311. tr->langopts.length_mods0 = length_mod_tabs[value2];
  312. }
  313. }
  314. int IsAlpha(unsigned int c)
  315. {//========================
  316. // Replacement for iswalph() which also checks for some in-word symbols
  317. if(iswalpha(c))
  318. return(1);
  319. if((c >= 0x901) && (c <= 0x957))
  320. return(1); // Devanagari vowel signs and other signs
  321. return(0);
  322. }
  323. int IsDigit09(unsigned int c)
  324. {//=========================
  325. if((c >= '0') && (c <= '9'))
  326. return(1);
  327. return(0);
  328. }
  329. int IsDigit(unsigned int c)
  330. {//========================
  331. if(iswdigit(c))
  332. return(1);
  333. if((c >= 0x966) && (c <= 0x96f))
  334. return(1);
  335. return(0);
  336. }
  337. Translator::Translator()
  338. {//=====================
  339. int ix;
  340. static const unsigned char stress_amps2[] = {16,16, 20,20, 20,24, 24,21 };
  341. static const short stress_lengths2[8] = {182,140, 220,220, 220,240, 260,280};
  342. static const wchar_t empty_wstring[1] = {0};
  343. charset_a0 = charsets[1]; // ISO-8859-1, this is for when the input is not utf8
  344. dictionary_name[0] = 0;
  345. dict_condition=0;
  346. data_dictrules = NULL; // language_1 translation rules file
  347. data_dictlist = NULL; // language_2 dictionary lookup file
  348. transpose_offset = 0;
  349. // only need lower case
  350. letter_bits_offset = 0;
  351. memset(letter_bits,0,sizeof(letter_bits));
  352. memset(letter_groups,0,sizeof(letter_groups));
  353. // 0-5 sets of characters matched by A B C E F G in pronunciation rules
  354. // these may be set differently for different languages
  355. SetLetterBits(this,0,"aeiou"); // A vowels, except y
  356. SetLetterBits(this,1,"bcdfgjklmnpqstvxz"); // B hard consonants, excluding h,r,w
  357. SetLetterBits(this,2,"bcdfghjklmnpqrstvwxz"); // C all consonants
  358. SetLetterBits(this,3,"hlmnr"); // H 'soft' consonants
  359. SetLetterBits(this,4,"cfhkpqstx"); // F voiceless consonants
  360. SetLetterBits(this,5,"bdgjlmnrvwyz"); // G voiced
  361. SetLetterBits(this,6,"eiy"); // Letter group Y, front vowels
  362. SetLetterBits(this,7,"aeiouy"); // vowels, including y
  363. char_plus_apostrophe = empty_wstring;
  364. for(ix=0; ix<8; ix++)
  365. {
  366. stress_amps[ix] = stress_amps2[ix];
  367. stress_amps_r[ix] = stress_amps2[ix] - 1;
  368. stress_lengths[ix] = stress_lengths2[ix];
  369. }
  370. memset(&langopts,0,sizeof(langopts));
  371. langopts.stress_rule = 2;
  372. langopts.unstressed_wd1 = 1;
  373. langopts.unstressed_wd2 = 3;
  374. langopts.param[LOPT_SONORANT_MIN] = 95;
  375. langopts.param[LOPT_MAXAMP_EOC] = 19;
  376. langopts.param[LOPT_UNPRONOUNCABLE] = 's'; // don't count this character at start of word
  377. langopts.max_initial_consonants = 3;
  378. langopts.replace_chars = NULL;
  379. langopts.length_mods = length_mods_en;
  380. langopts.length_mods0 = length_mods_en0;
  381. langopts.long_stop = 100;
  382. langopts.max_roman = 49;
  383. langopts.thousands_sep = ',';
  384. langopts.decimal_sep = '.';
  385. memcpy(punct_to_tone,punctuation_to_tone,sizeof(punct_to_tone));
  386. punct_to_tone[0][3] = 0; // exclamation, use period until we can improve the exclamation intonation
  387. }
  388. Translator::~Translator(void)
  389. {//==========================
  390. if(data_dictlist != NULL)
  391. Free(data_dictlist);
  392. }
  393. int lookupwchar(const unsigned short *list,int c)
  394. {//==============================================
  395. // Is the character c in the list ?
  396. int ix;
  397. for(ix=0; list[ix] != 0; ix++)
  398. {
  399. if(list[ix] == c)
  400. return(ix+1);
  401. }
  402. return(0);
  403. }
  404. int IsBracket(int c)
  405. {//=================
  406. if((c >= 0x2014) && (c <= 0x201f))
  407. return(1);
  408. return(lookupwchar(brackets,c));
  409. }
  410. int utf8_out(unsigned int c, char *buf)
  411. {//====================================
  412. // write a unicode character into a buffer as utf8
  413. // returns the number of bytes written
  414. int n_bytes;
  415. int j;
  416. int shift;
  417. static char unsigned code[4] = {0,0xc0,0xe0,0xf0};
  418. if(c < 0x80)
  419. {
  420. buf[0] = c;
  421. return(1);
  422. }
  423. if(c >= 0x110000)
  424. {
  425. buf[0] = ' '; // out of range character code
  426. return(1);
  427. }
  428. if(c < 0x0800)
  429. n_bytes = 1;
  430. else
  431. if(c < 0x10000)
  432. n_bytes = 2;
  433. else
  434. n_bytes = 3;
  435. shift = 6*n_bytes;
  436. buf[0] = code[n_bytes] | (c >> shift);
  437. for(j=0; j<n_bytes; j++)
  438. {
  439. shift -= 6;
  440. buf[j+1] = 0x80 + ((c >> shift) & 0x3f);
  441. }
  442. return(n_bytes+1);
  443. } // end of utf8_out
  444. int utf8_in(int *c, const char *buf, int backwards)
  445. {//================================================
  446. int c1;
  447. int n_bytes;
  448. int ix;
  449. static const unsigned char mask[4] = {0xff,0x1f,0x0f,0x07};
  450. // find the start of the next/previous character
  451. while((*buf & 0xc0) == 0x80)
  452. {
  453. // skip over non-initial bytes of a multi-byte utf8 character
  454. if(backwards)
  455. buf--;
  456. else
  457. buf++;
  458. }
  459. n_bytes = 0;
  460. if((c1 = *buf++) & 0x80)
  461. {
  462. if((c1 & 0xe0) == 0xc0)
  463. n_bytes = 1;
  464. else
  465. if((c1 & 0xf0) == 0xe0)
  466. n_bytes = 2;
  467. else
  468. if((c1 & 0xf8) == 0xf0)
  469. n_bytes = 3;
  470. c1 &= mask[n_bytes];
  471. for(ix=0; ix<n_bytes; ix++)
  472. {
  473. c1 = (c1 << 6) + (*buf++ & 0x3f);
  474. }
  475. }
  476. *c = c1;
  477. return(n_bytes+1);
  478. }
  479. char *strchr_w(const char *s, int c)
  480. {//=================================
  481. // return NULL for any non-ascii character
  482. if(c >= 0x80)
  483. return(NULL);
  484. return(strchr((char *)s,c)); // (char *) is needed for Borland compiler
  485. }
  486. int PhonemeCode(unsigned int mnem)
  487. {//===============================
  488. int ix;
  489. for(ix=0; ix<n_phoneme_tab; ix++)
  490. {
  491. if(phoneme_tab[ix]->mnemonic == mnem)
  492. return(phoneme_tab[ix]->code);
  493. }
  494. return(phonSCHWA);
  495. }
  496. int Translator::TranslateWord(char *word1, int next_pause, WORD_TAB *wtab)
  497. {//=======================================================================
  498. // word1 is terminated by space (0x20) character
  499. int length;
  500. int word_length;
  501. int ix;
  502. int posn;
  503. unsigned int dictionary_flags=0;
  504. unsigned int dictionary_flags2=0;
  505. int end_type=0;
  506. int prefix_type=0;
  507. char *wordx;
  508. char phonemes[N_WORD_PHONEMES];
  509. char *ph_limit;
  510. char *phonemes_ptr;
  511. char prefix_phonemes[N_WORD_PHONEMES];
  512. char end_phonemes[N_WORD_PHONEMES];
  513. char word_copy[N_WORD_BYTES];
  514. int found=0;
  515. int end_flags;
  516. char c_temp; // save a character byte while we temporarily replace it with space
  517. int first_char;
  518. int last_char = 0;
  519. int unpron_length;
  520. int add_plural_suffix = 0;
  521. int prefix_flags = 0;
  522. int confirm_prefix;
  523. int spell_word;
  524. int wflags = wtab->flags;
  525. int wmark = wtab->wmark;
  526. // translate these to get pronunciations of plural 's' suffix (different forms depending on
  527. // the preceding letter
  528. static char word_zz[4] = {0,'z','z',0};
  529. static char word_iz[4] = {0,'i','z',0};
  530. static char word_ss[4] = {0,'s','s',0};
  531. prefix_phonemes[0] = 0;
  532. end_phonemes[0] = 0;
  533. ph_limit = &phonemes[N_WORD_PHONEMES];
  534. // count the length of the word
  535. wordx = word1;
  536. utf8_in(&first_char,wordx,0);
  537. word_length = 0;
  538. while((*wordx != 0) && (*wordx != ' '))
  539. {
  540. wordx += utf8_in(&last_char,wordx,0);
  541. word_length++;
  542. }
  543. // try an initial lookup in the dictionary list, we may find a pronunciation specified, or
  544. // we may just find some flags
  545. if((option_sayas & 0xf0) == 0x10)
  546. {
  547. // SAYAS_CHAR, SAYAS_GYLPH, or SAYAS_SINGLE_CHAR
  548. spell_word = option_sayas & 0xf; // 2,3,4
  549. }
  550. else
  551. {
  552. spell_word = 0;
  553. found = LookupDictList(&word1,phonemes,&dictionary_flags,FLAG_ALLOW_TEXTMODE | wflags << 16); // the original word
  554. if(phonemes[0] == phonSWITCH)
  555. {
  556. // change to another language in order to translate this word
  557. strcpy(word_phonemes,phonemes);
  558. return(0);
  559. }
  560. if((wmark > 0) && (wmark < 8))
  561. {
  562. // the stressed syllable has been specified in the text (TESTING)
  563. dictionary_flags = (dictionary_flags & ~0xf) | wmark;
  564. }
  565. if(!found && (dictionary_flags & FLAG_ABBREV))
  566. {
  567. // the word has $abbrev flag, but no pronunciation specified. Speak as individual letters
  568. spell_word = 1;
  569. }
  570. if(!found && iswdigit(first_char))
  571. {
  572. Lookup("_0lang",word_phonemes);
  573. if(word_phonemes[0] == phonSWITCH)
  574. return(0);
  575. found = TranslateNumber(word1,phonemes,&dictionary_flags,wflags);
  576. }
  577. if(!found & ((word_flags & FLAG_UPPERS) != FLAG_FIRST_UPPER))
  578. {
  579. // either all upper or all lower case
  580. if((langopts.numbers & NUM_ROMAN) || ((langopts.numbers & NUM_ROMAN_UC) && (word_flags & FLAG_ALL_UPPER)))
  581. {
  582. if((found = TranslateRoman(word1,phonemes)) != 0)
  583. dictionary_flags |= FLAG_ABBREV; // don't spell capital Roman numbers as individual letters
  584. }
  585. }
  586. if((wflags & FLAG_ALL_UPPER) && (clause_upper_count <= clause_lower_count) &&
  587. !(dictionary_flags & (FLAG_ABBREV | FLAG_SKIPWORDS)) && (word_length>1) && (word_length<4) && iswalpha(first_char))
  588. {
  589. // An upper case word in a lower case clause. This could be an abbreviation.
  590. spell_word = 1;
  591. }
  592. }
  593. if(spell_word > 0)
  594. {
  595. // Speak as individual letters
  596. wordx = word1;
  597. posn = 0;
  598. phonemes[0] = 0;
  599. end_type = 0;
  600. while(*wordx != ' ')
  601. {
  602. wordx += TranslateLetter(wordx, phonemes,spell_word);
  603. if(phonemes[0] == phonSWITCH)
  604. {
  605. // change to another language in order to translate this word
  606. strcpy(word_phonemes,phonemes);
  607. return(0);
  608. }
  609. }
  610. SetSpellingStress(phonemes,spell_word);
  611. }
  612. else
  613. if(found == 0)
  614. {
  615. // word's pronunciation is not given in the dictionary list, although
  616. // dictionary_flags may have ben set there
  617. posn = 0;
  618. length = 999;
  619. wordx = word1;
  620. while(((length < 3) && (length > 0))|| (word_length > 1 && Unpronouncable(wordx)))
  621. {
  622. char *p;
  623. // This word looks "unpronouncable", so speak letters individually until we
  624. // find a remainder that we can pronounce.
  625. wordx += TranslateLetter(wordx,phonemes,0);
  626. if(phonemes[0] == phonSWITCH)
  627. {
  628. // change to another language in order to translate this word
  629. strcpy(word_phonemes,phonemes);
  630. return(0);
  631. }
  632. p = &wordx[word_length-3];
  633. if(memcmp(p,"'s ",3) == 0)
  634. {
  635. // remove a 's suffix and pronounce this separately (not as an individual letter)
  636. add_plural_suffix = 1;
  637. p[0] = ' ';
  638. p[1] = ' ';
  639. last_char = p[-1];
  640. }
  641. length=0;
  642. while(wordx[length] != ' ') length++;
  643. if(length > 0)
  644. wordx[-1] = ' '; // prevent this affecting the pronunciation of the pronuncable part
  645. }
  646. SetSpellingStress(phonemes,0);
  647. // anything left ?
  648. if(*wordx != ' ')
  649. {
  650. // Translate the stem
  651. unpron_length = strlen(phonemes);
  652. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags);
  653. if(phonemes[0] == phonSWITCH)
  654. {
  655. // change to another language in order to translate this word
  656. strcpy(word_phonemes,phonemes);
  657. return(0);
  658. }
  659. c_temp = wordx[-1];
  660. found = 0;
  661. confirm_prefix = 1;
  662. while(end_type & SUFX_P)
  663. {
  664. // Found a standard prefix, remove it and retranslate
  665. if(confirm_prefix)
  666. {
  667. int end2;
  668. char phonemes2[N_WORD_PHONEMES];
  669. char end_phonemes2[N_WORD_PHONEMES];
  670. // remove any standard suffix and confirm that the prefix is still recognised
  671. phonemes2[0] = 0;
  672. end2 = TranslateRules(wordx, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags);
  673. if(end2)
  674. {
  675. RemoveEnding(wordx,end2,word_copy);
  676. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags);
  677. memcpy(wordx,word_copy,strlen(word_copy));
  678. if((end_type & SUFX_P) == 0)
  679. {
  680. // after removing the suffix, the prefix is no longer recognised.
  681. // Keep the suffix, but don't use the prefix
  682. end_type = end2;
  683. strcpy(phonemes,phonemes2);
  684. strcpy(end_phonemes,end_phonemes2);
  685. if(option_phonemes == 2)
  686. {
  687. DecodePhonemes(end_phonemes,end_phonemes2);
  688. fprintf(f_trans," suffix [%s]\n\n",end_phonemes2);
  689. }
  690. }
  691. confirm_prefix = 0;
  692. continue;
  693. }
  694. }
  695. strcat(prefix_phonemes,end_phonemes);
  696. end_phonemes[0] = 0;
  697. prefix_type = end_type;
  698. if(prefix_type & SUFX_V)
  699. {
  700. expect_verb = 1; // use the verb form of the word
  701. }
  702. wordx[-1] = c_temp;
  703. for(ix=(prefix_type & 0xf); ix>0; ix--) // num. of characters to remove
  704. {
  705. wordx++;
  706. while((*wordx & 0xc0) == 0x80) wordx++; // for multibyte characters
  707. }
  708. c_temp = wordx[-1];
  709. wordx[-1] = ' ';
  710. confirm_prefix = 1;
  711. end_type = 0;
  712. found = LookupDictList(&wordx,phonemes,&dictionary_flags2,SUFX_P | (wflags << 16)); // without prefix
  713. if(dictionary_flags==0)
  714. dictionary_flags = dictionary_flags2;
  715. else
  716. prefix_flags = 1;
  717. if(found == 0)
  718. {
  719. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags);
  720. if(phonemes[0] == phonSWITCH)
  721. {
  722. // change to another language in order to translate this word
  723. wordx[-1] = c_temp;
  724. strcpy(word_phonemes,phonemes);
  725. return(0);
  726. }
  727. }
  728. }
  729. if((end_type != 0) && !(end_type & SUFX_P))
  730. {
  731. char phonemes2[N_WORD_PHONEMES];
  732. strcpy(phonemes2,phonemes);
  733. // The word has a standard ending, re-translate without this ending
  734. end_flags = RemoveEnding(wordx,end_type,word_copy);
  735. phonemes_ptr = &phonemes[unpron_length];
  736. phonemes_ptr[0] = 0;
  737. if(prefix_phonemes[0] != 0)
  738. {
  739. // lookup the stem without the prefix removed
  740. wordx[-1] = c_temp;
  741. found = LookupDictList(&word1,phonemes_ptr,&dictionary_flags2,end_flags | (wflags << 16)); // include prefix, but not suffix
  742. wordx[-1] = ' ';
  743. if(dictionary_flags==0)
  744. dictionary_flags = dictionary_flags2;
  745. if(found)
  746. prefix_phonemes[0] = 0; // matched whole word, don't need prefix now
  747. if((found==0) && (dictionary_flags2 != 0))
  748. prefix_flags = 1;
  749. }
  750. if(found == 0)
  751. {
  752. found = LookupDictList(&wordx,phonemes_ptr,&dictionary_flags2,end_flags | (wflags << 16)); // without prefix and suffix
  753. if(phonemes_ptr[0] == phonSWITCH)
  754. {
  755. // change to another language in order to translate this word
  756. memcpy(wordx,word_copy,strlen(word_copy));
  757. strcpy(word_phonemes,phonemes_ptr);
  758. return(0);
  759. }
  760. if(dictionary_flags==0)
  761. dictionary_flags = dictionary_flags2;
  762. }
  763. if(found == 0)
  764. {
  765. if(end_type & SUFX_Q)
  766. {
  767. // don't retranslate, use the original lookup result
  768. strcpy(phonemes,phonemes2);
  769. // language specific changes
  770. ApplySpecialAttribute(phonemes,dictionary_flags);
  771. }
  772. else
  773. {
  774. if(end_flags & FLAG_SUFX)
  775. TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags | FLAG_SUFFIX_REMOVED, dictionary_flags);
  776. else
  777. TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags,dictionary_flags);
  778. if(phonemes[0] == phonSWITCH)
  779. {
  780. // change to another language in order to translate this word
  781. strcpy(word_phonemes,phonemes);
  782. memcpy(wordx,word_copy,strlen(word_copy));
  783. wordx[-1] = c_temp;
  784. return(0);
  785. }
  786. }
  787. }
  788. if((end_type & SUFX_T) == 0)
  789. {
  790. // the default is to add the suffix and then determine the word's stress pattern
  791. AppendPhonemes(phonemes, N_WORD_PHONEMES, end_phonemes);
  792. end_phonemes[0] = 0;
  793. }
  794. }
  795. wordx[-1] = c_temp;
  796. }
  797. }
  798. if((add_plural_suffix) || (wflags & FLAG_HAS_PLURAL))
  799. {
  800. // s or 's suffix, append [s], [z] or [Iz] depending on previous letter
  801. if(last_char == 'f')
  802. TranslateRules(&word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  803. else
  804. if((last_char==0) || (strchr_w("hsx",last_char)==NULL))
  805. TranslateRules(&word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  806. else
  807. TranslateRules(&word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  808. }
  809. /* determine stress pattern for this word */
  810. /******************************************/
  811. /* NOTE: this also adds a single PAUSE if the previous word ended
  812. in a primary stress, and this one starts with one */
  813. if(prefix_flags || (strchr(prefix_phonemes,phonSTRESS_P)!=NULL))
  814. {
  815. if((langopts.param[LOPT_PREFIXES]) || (prefix_type & SUFX_T))
  816. {
  817. char *p;
  818. // German, keep a secondary stress on the stem
  819. SetWordStress(phonemes,dictionary_flags,3,0);
  820. // reduce all but the first primary stress
  821. ix=0;
  822. for(p=prefix_phonemes; *p != 0; p++)
  823. {
  824. if(*p == phonSTRESS_P)
  825. {
  826. if(ix==0)
  827. ix=1;
  828. else
  829. *p = phonSTRESS_3;
  830. }
  831. }
  832. strcpy(word_phonemes,prefix_phonemes);
  833. strcat(word_phonemes,phonemes);
  834. SetWordStress(word_phonemes,dictionary_flags,-1,0);
  835. }
  836. else
  837. {
  838. // stress position affects the whole word, including prefix
  839. strcpy(word_phonemes,prefix_phonemes);
  840. strcat(word_phonemes,phonemes);
  841. SetWordStress(word_phonemes,dictionary_flags,-1,prev_last_stress);
  842. }
  843. }
  844. else
  845. {
  846. if(prefix_phonemes[0] == 0)
  847. SetWordStress(phonemes,dictionary_flags,-1,prev_last_stress);
  848. else
  849. SetWordStress(phonemes,dictionary_flags,-1,0);
  850. strcpy(word_phonemes,prefix_phonemes);
  851. strcat(word_phonemes,phonemes);
  852. }
  853. if(end_phonemes[0] != 0)
  854. {
  855. // a suffix had the SUFX_T option set, add the suffix after the stress pattern has been determined
  856. strcat(word_phonemes,end_phonemes);
  857. }
  858. // if(next_pause > 2)
  859. ix = ((dictionary_flags >> 5) & 7); // dictionary indicates skip next word(s)
  860. if(wtab[ix].flags & FLAG_LAST_WORD)
  861. {
  862. // the word has attribute to stress or unstress when at end of clause
  863. if(dictionary_flags & (FLAG_STRESS_END | FLAG_STRESS_END2))
  864. ChangeWordStress(this,word_phonemes,4);
  865. // SetWordStress(word_phonemes,0,4,prev_last_stress);
  866. else
  867. if(dictionary_flags & FLAG_UNSTRESS_END)
  868. ChangeWordStress(this,word_phonemes,3);
  869. // SetWordStress(word_phonemes,0,3,prev_last_stress);
  870. }
  871. if(wflags & FLAG_STRESSED_WORD)
  872. {
  873. // A word is indicated in the source text as stressed
  874. // we need to improve the intonation module to deal better with a clauses tonic
  875. // stress being early in the clause, before enabling this
  876. //SetWordStress(word_phonemes,0,5,prev_last_stress);
  877. }
  878. // dictionary flags for this word give a clue about which alternative pronunciations of
  879. // following words to use.
  880. if(end_type & SUFX_F)
  881. {
  882. // expect a verb form, with or without -s suffix
  883. expect_verb = 2;
  884. expect_verb_s = 2;
  885. }
  886. if(dictionary_flags & FLAG_PASTF)
  887. {
  888. /* expect perfect tense in next two words */
  889. expect_past = 3;
  890. expect_verb = 0;
  891. }
  892. else
  893. if(dictionary_flags & FLAG_VERBF)
  894. {
  895. /* expect a verb in the next word */
  896. expect_verb = 2;
  897. expect_verb_s = 0; /* verb won't have -s suffix */
  898. }
  899. else
  900. if(dictionary_flags & FLAG_VERBSF)
  901. {
  902. // expect a verb, must have a -s suffix
  903. expect_verb = 0;
  904. expect_verb_s = 2;
  905. expect_past = 0;
  906. }
  907. else
  908. if(dictionary_flags & FLAG_NOUNF)
  909. {
  910. /* not expecting a verb next */
  911. expect_verb = 0;
  912. expect_verb_s = 0;
  913. expect_past = 0;
  914. }
  915. if((wordx[0] != 0) && (!(dictionary_flags & FLAG_VERB_EXT)))
  916. {
  917. if(expect_verb > 0)
  918. expect_verb -= 1;
  919. if(expect_verb_s > 0)
  920. expect_verb_s -= 1;
  921. if(expect_past > 0)
  922. expect_past -= 1;
  923. }
  924. if((word_length == 1) && iswalpha(first_char) && (first_char != 'i'))
  925. {
  926. // English Specific !!!!
  927. // any single letter before a dot is an abbreviation, except 'I'
  928. dictionary_flags |= FLAG_DOT;
  929. }
  930. return(dictionary_flags);
  931. } // end of TranslateWord
  932. static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode)
  933. {//==========================================================
  934. p->phcode = phcode;
  935. p->stress = 0;
  936. p->tone_number = 0;
  937. p->synthflags = 0;
  938. p->sourceix = 0;
  939. }
  940. static int CountSyllables(unsigned char *phonemes)
  941. {//===============================================
  942. int count = 0;
  943. int phon;
  944. while((phon = *phonemes++) != 0)
  945. {
  946. if(phoneme_tab[phon]->type == phVOWEL)
  947. count++;
  948. }
  949. return(count);
  950. }
  951. int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int next_pause)
  952. {//======================================================================================
  953. int flags=0;
  954. int stress;
  955. int next_stress;
  956. int next_tone=0;
  957. unsigned char *p;
  958. int srcix;
  959. int embedded_flag=0;
  960. int embedded_cmd;
  961. int value;
  962. int found_dict_flag;
  963. unsigned char ph_code;
  964. PHONEME_LIST2 *plist2;
  965. PHONEME_TAB *ph;
  966. int max_stress;
  967. int max_stress_ix=0;
  968. int prev_vowel = -1;
  969. int pitch_raised = 0;
  970. int switch_phonemes = -1;
  971. int first_phoneme = 1;
  972. int source_ix;
  973. int len;
  974. int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
  975. const char *new_language;
  976. unsigned char bad_phoneme[4];
  977. len = wtab->length;
  978. if(len > 31) len = 31;
  979. source_ix = (wtab->sourceix & 0x7ff) | (len << 11); // bits 0-10 sourceix, bits 11-15 word length
  980. word_flags = wtab[0].flags;
  981. if(word_flags & FLAG_EMBEDDED)
  982. {
  983. embedded_flag = SFLAG_EMBEDDED;
  984. value = embedded_list[embedded_read] >> 8;
  985. switch(embedded_cmd = embedded_list[embedded_read] & 0x1f)
  986. {
  987. case EMBED_Y:
  988. option_sayas = value;
  989. break;
  990. case EMBED_F:
  991. option_emphasis = value;
  992. break;
  993. case EMBED_B:
  994. // break command
  995. if(value == 0)
  996. pre_pause = 0; // break=none
  997. else
  998. pre_pause += value;
  999. break;
  1000. }
  1001. while((embedded_list[embedded_read++] & 0x80) == 0); // read over the embedded commands for this word
  1002. }
  1003. if(word[0] == 0)
  1004. {
  1005. // nothing to translate
  1006. word_phonemes[0] = 0;
  1007. return(0);
  1008. }
  1009. // after a $pause word attribute, ignore a $pause attribute on the next two words
  1010. if(prepause_timeout > 0)
  1011. prepause_timeout--;
  1012. if((option_sayas & 0xf0) == 0x10)
  1013. {
  1014. // SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
  1015. pre_pause += 4;
  1016. }
  1017. if(word_flags & FLAG_FIRST_UPPER)
  1018. {
  1019. if((option_capitals > 2) && (embedded_ix < N_EMBEDDED_LIST-6))
  1020. {
  1021. // indicate capital letter by raising pitch
  1022. if(embedded_flag)
  1023. embedded_list[embedded_ix-1] &= ~0x80; // already embedded command before this word, remove terminator
  1024. if((pitch_raised = option_capitals) == 3)
  1025. pitch_raised = 20; // default pitch raise for capitals
  1026. embedded_list[embedded_ix++] = EMBED_P+0x40+0x80 + (pitch_raised << 8); // raise pitch
  1027. embedded_flag = SFLAG_EMBEDDED;
  1028. }
  1029. }
  1030. p = (unsigned char *)translator->word_phonemes;
  1031. if(word_flags & FLAG_PHONEMES)
  1032. {
  1033. // The input is in phoneme mnemonics, not language text
  1034. EncodePhonemes(word,word_phonemes,bad_phoneme);
  1035. flags = FLAG_FOUND;
  1036. }
  1037. else
  1038. {
  1039. flags = translator->TranslateWord(word, next_pause, wtab);
  1040. if((flags & FLAG_ALT2_TRANS) && ((sylimit = langopts.param[LOPT_COMBINE_WORDS]) > 0))
  1041. {
  1042. char *p2;
  1043. int ok = 1;
  1044. int flags2;
  1045. int c_word2;
  1046. char ph_buf[N_WORD_PHONEMES];
  1047. // LANG=cs,sk
  1048. // combine a preposition with the following word
  1049. p2 = word;
  1050. while(*p2 != ' ') p2++;
  1051. utf8_in(&c_word2, p2+1, 0); // first character of the next word;
  1052. if(!iswalpha(c_word2))
  1053. {
  1054. ok =0;
  1055. }
  1056. if(sylimit & 0x100)
  1057. {
  1058. // only if the second word has $alt attribute
  1059. strcpy(ph_buf,word_phonemes);
  1060. flags2 = translator->TranslateWord(p2+1, 0, wtab+1);
  1061. if((flags2 & FLAG_ALT_TRANS) == 0)
  1062. {
  1063. ok = 0;
  1064. strcpy(word_phonemes,ph_buf);
  1065. }
  1066. }
  1067. if((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD))
  1068. {
  1069. // not if the next word is end-of-sentence
  1070. ok = 0;
  1071. }
  1072. if(ok)
  1073. {
  1074. *p2 = '-'; // replace next space by hyphen
  1075. flags = translator->TranslateWord(word, next_pause, wtab); // translate the combined word
  1076. if(CountSyllables(p) > (sylimit & 0xf))
  1077. {
  1078. // revert to separate words
  1079. *p2 = ' ';
  1080. flags = translator->TranslateWord(word, next_pause, wtab);
  1081. }
  1082. else
  1083. {
  1084. flags |= FLAG_SKIPWORDS;
  1085. dictionary_skipwords = 1;
  1086. }
  1087. }
  1088. }
  1089. if(p[0] == phonSWITCH)
  1090. {
  1091. // this word uses a different language
  1092. new_language = (char *)(&p[1]);
  1093. if(new_language[0]==0)
  1094. new_language = "en";
  1095. if((switch_phonemes = SelectPhonemeTableName(new_language)) >= 0)
  1096. {
  1097. if((translator2 != NULL) && (strcmp(new_language,translator2_language) != 0))
  1098. {
  1099. // we already have an alternative translator, but not for the required language, delete it
  1100. delete translator2;
  1101. translator2 = NULL;
  1102. }
  1103. if(translator2 == NULL)
  1104. {
  1105. translator2 = SelectTranslator(new_language);
  1106. strcpy(translator2_language,new_language);
  1107. if(translator2->LoadDictionary(new_language,0) != 0)
  1108. {
  1109. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  1110. switch_phonemes = -1;
  1111. translator2_language[0] = 0;
  1112. }
  1113. }
  1114. }
  1115. if(switch_phonemes >= 0)
  1116. {
  1117. // re-translate the word using the new translator
  1118. flags = translator2->TranslateWord(word, next_pause, wtab);
  1119. strcpy((char *)p,translator2->word_phonemes);
  1120. if(p[0] == phonSWITCH)
  1121. {
  1122. // the second translator doesn't want to process this word
  1123. switch_phonemes = -1;
  1124. }
  1125. }
  1126. if(switch_phonemes < 0)
  1127. {
  1128. // language code is not recognised or 2nd translator won't translate it
  1129. p[0] = phonSCHWA; // just say something
  1130. p[1] = phonSCHWA;
  1131. p[2] = 0;
  1132. }
  1133. }
  1134. if(!(word_flags & FLAG_LAST_WORD) && !(word_flags & FLAG_HYPHEN))
  1135. {
  1136. if(flags & FLAG_PAUSE1)
  1137. {
  1138. if(pre_pause < 1)
  1139. pre_pause = 1;
  1140. }
  1141. if((flags & FLAG_PREPAUSE) && (prepause_timeout == 0))
  1142. {
  1143. // the word is marked in the dictionary list with $pause
  1144. if(pre_pause < 4) pre_pause = 4;
  1145. prepause_timeout = 3;
  1146. }
  1147. }
  1148. if((option_emphasis >= 3) && (pre_pause < 2))
  1149. pre_pause = 2;
  1150. }
  1151. plist2 = &ph_list2[n_ph_list2];
  1152. stress = 0;
  1153. next_stress = 0;
  1154. srcix = 0;
  1155. max_stress = -1;
  1156. found_dict_flag = 0;
  1157. if(flags & FLAG_FOUND)
  1158. found_dict_flag = SFLAG_DICTIONARY;
  1159. while((pre_pause > 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1160. {
  1161. // add pause phonemes here. Either because of punctuation (brackets or quotes) in the
  1162. // text, or because the word is marked in the dictionary lookup as a conjunction
  1163. if(pre_pause > 1)
  1164. {
  1165. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE);
  1166. pre_pause -= 2;
  1167. }
  1168. else
  1169. {
  1170. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_NOLINK);
  1171. pre_pause--;
  1172. }
  1173. end_stressed_vowel = 0; // forget about the previous word
  1174. prev_dict_flags = 0;
  1175. }
  1176. if((option_capitals==1) && (word_flags & FLAG_FIRST_UPPER))
  1177. {
  1178. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1179. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1180. if((word_flags & FLAG_ALL_UPPER) && IsAlpha(word[1]))
  1181. {
  1182. // word > 1 letter and all capitals
  1183. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1184. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1185. }
  1186. }
  1187. if(switch_phonemes >= 0)
  1188. {
  1189. // this word uses a different phoneme table
  1190. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1191. ph_list2[n_ph_list2++].tone_number = switch_phonemes; // temporary phoneme table number
  1192. }
  1193. // remove initial pause from a word if it follows a hyphen
  1194. if((word_flags & FLAG_HYPHEN) && (phoneme_tab[*p]->type == phPAUSE))
  1195. p++;
  1196. while(((ph_code = *p++) != 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1197. {
  1198. if(ph_code == 255)
  1199. continue; // unknown phoneme
  1200. // Add the phonemes to the first stage phoneme list (ph_list2)
  1201. ph = phoneme_tab[ph_code];
  1202. if(ph->type == phSTRESS)
  1203. {
  1204. // don't add stress phonemes codes to the list, but give their stress
  1205. // value to the next vowel phoneme
  1206. // std_length is used to hold stress number or (if >10) a tone number for a tone language
  1207. if(ph->spect == 0)
  1208. next_stress = ph->std_length;
  1209. else
  1210. {
  1211. // for tone languages, the tone number for a syllable follows the vowel
  1212. if(prev_vowel >= 0)
  1213. {
  1214. ph_list2[prev_vowel].tone_number = ph_code;
  1215. }
  1216. else
  1217. {
  1218. next_tone = ph_code; // no previous vowel, apply to the next vowel
  1219. }
  1220. }
  1221. }
  1222. else
  1223. if(ph_code == phonSYLLABIC)
  1224. {
  1225. // mark the previous phoneme as a syllabic consonant
  1226. ph_list2[n_ph_list2-1].synthflags |= SFLAG_SYLLABLE;
  1227. ph_list2[n_ph_list2-1].stress = next_stress;
  1228. }
  1229. else
  1230. if(ph_code == phonLENGTHEN)
  1231. {
  1232. ph_list2[n_ph_list2-1].synthflags |= SFLAG_LENGTHEN;
  1233. }
  1234. else
  1235. if(ph_code == phonEND_WORD)
  1236. {
  1237. // a || symbol in a phoneme string was used to indicate a word boundary
  1238. // Don't add this phoneme to the list, but make sure the next phoneme has
  1239. // a newword indication
  1240. srcix = source_ix+1;
  1241. }
  1242. else
  1243. if(ph_code == phonX1)
  1244. {
  1245. // a language specific action
  1246. if(langopts.param[LOPT_IT_DOUBLING])
  1247. {
  1248. flags |= FLAG_DOUBLING;
  1249. }
  1250. }
  1251. else
  1252. {
  1253. ph_list2[n_ph_list2].phcode = ph_code;
  1254. ph_list2[n_ph_list2].tone_number = 0;
  1255. ph_list2[n_ph_list2].synthflags = embedded_flag | found_dict_flag;
  1256. embedded_flag = 0;
  1257. ph_list2[n_ph_list2].sourceix = srcix;
  1258. srcix = 0;
  1259. if(ph->type == phVOWEL)
  1260. {
  1261. stress = next_stress;
  1262. next_stress = 0;
  1263. if((prev_vowel >= 0) && (n_ph_list2-1) != prev_vowel)
  1264. ph_list2[n_ph_list2-1].stress = stress; // set stress for previous consonant
  1265. ph_list2[n_ph_list2].synthflags |= SFLAG_SYLLABLE;
  1266. prev_vowel = n_ph_list2;
  1267. if(stress > max_stress)
  1268. {
  1269. max_stress = stress;
  1270. max_stress_ix = n_ph_list2;
  1271. }
  1272. if(next_tone != 0)
  1273. {
  1274. ph_list2[n_ph_list2].tone_number = next_tone;
  1275. next_tone=0;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. if(first_phoneme && langopts.param[LOPT_IT_DOUBLING])
  1281. {
  1282. if(((prev_dict_flags & FLAG_DOUBLING) && (langopts.param[LOPT_IT_DOUBLING] & 1)) ||
  1283. (end_stressed_vowel && (langopts.param[LOPT_IT_DOUBLING] & 2)))
  1284. {
  1285. // italian, double the initial consonant if the previous word ends with a
  1286. // stressed vowel, or is marked with a flag
  1287. ph_list2[n_ph_list2].synthflags |= SFLAG_LENGTHEN;
  1288. }
  1289. }
  1290. }
  1291. ph_list2[n_ph_list2].stress = stress;
  1292. n_ph_list2++;
  1293. first_phoneme = 0;
  1294. }
  1295. }
  1296. plist2->sourceix = source_ix; // ????
  1297. end_stressed_vowel = 0;
  1298. if((stress >= 4) && (phoneme_tab[ph_list2[n_ph_list2-1].phcode]->type == phVOWEL))
  1299. {
  1300. end_stressed_vowel = 1; // word ends with a stressed vowel
  1301. }
  1302. if(switch_phonemes >= 0)
  1303. {
  1304. // this word uses a different phoneme table, now switch back
  1305. SelectPhonemeTable(voice->phoneme_tab_ix);
  1306. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1307. ph_list2[n_ph_list2++].tone_number = voice->phoneme_tab_ix; // original phoneme table number
  1308. }
  1309. if(pitch_raised > 0)
  1310. {
  1311. embedded_list[embedded_ix++] = EMBED_P+0x60+0x80 + (pitch_raised << 8); // lower pitch
  1312. SetPlist2(&ph_list2[n_ph_list2],phonPAUSE_SHORT);
  1313. ph_list2[n_ph_list2++].synthflags = SFLAG_EMBEDDED;
  1314. }
  1315. if(flags & FLAG_STRESS_END2)
  1316. {
  1317. // this's word's stress could be increased later
  1318. ph_list2[max_stress_ix].synthflags |= SFLAG_PROMOTE_STRESS;
  1319. }
  1320. prev_dict_flags = flags;
  1321. return(flags);
  1322. } // end of TranslateWord2
  1323. static int EmbeddedCommand(unsigned int &source_index)
  1324. {//===================================================
  1325. // An embedded command to change the pitch, volume, etc.
  1326. // returns number of commands added to embedded_list
  1327. // pitch,speed,amplitude,expression,reverb,tone,voice,sayas
  1328. const char *commands = "PSARHTIVYMUBF";
  1329. int value = -1;
  1330. int sign = 0;
  1331. unsigned char c;
  1332. char *p;
  1333. int cmd;
  1334. c = source[source_index];
  1335. if(c == '+')
  1336. {
  1337. sign = 0x40;
  1338. source_index++;
  1339. }
  1340. else
  1341. if(c == '-')
  1342. {
  1343. sign = 0x60;
  1344. source_index++;
  1345. }
  1346. if(isdigit(source[source_index]))
  1347. {
  1348. value = atoi(&source[source_index]);
  1349. while(isdigit(source[source_index]))
  1350. source_index++;
  1351. }
  1352. c = source[source_index++];
  1353. if(embedded_ix >= (N_EMBEDDED_LIST - 2))
  1354. return(0); // list is full
  1355. if((p = strchr_w(commands,c)) == NULL)
  1356. return(0);
  1357. cmd = (p - commands)+1;
  1358. if(value == -1)
  1359. {
  1360. value = embedded_default[cmd];
  1361. sign = 0;
  1362. }
  1363. if(cmd == EMBED_Y)
  1364. {
  1365. option_sayas2 = value;
  1366. count_sayas_digits = 0;
  1367. }
  1368. embedded_list[embedded_ix++] = cmd + sign + (value << 8);
  1369. return(1);
  1370. } // end of EmbeddedCommand
  1371. int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, int *insert)
  1372. {//==================================================================================
  1373. int ix;
  1374. unsigned int word;
  1375. unsigned int new_c, c2, c_lower;
  1376. int upper_case = 0;
  1377. static int ignore_next = 0;
  1378. const unsigned int *replace_chars;
  1379. if(ignore_next)
  1380. {
  1381. ignore_next = 0;
  1382. return(8);
  1383. }
  1384. if(c == 0) return(0);
  1385. if((replace_chars = tr->langopts.replace_chars) == NULL)
  1386. return(c);
  1387. // there is a list of character codes to be substituted with alternative codes
  1388. if(iswupper(c_lower = c))
  1389. {
  1390. c_lower = towlower(c);
  1391. upper_case = 1;
  1392. }
  1393. new_c = 0;
  1394. for(ix=0; (word = replace_chars[ix]) != 0; ix+=2)
  1395. {
  1396. if(c_lower == (word & 0xffff))
  1397. {
  1398. if((word >> 16) == 0)
  1399. {
  1400. new_c = replace_chars[ix+1];
  1401. break;
  1402. }
  1403. if((word >> 16) == (unsigned int)tolower(next_in))
  1404. {
  1405. new_c = replace_chars[ix+1];
  1406. ignore_next = 1;
  1407. break;
  1408. }
  1409. }
  1410. }
  1411. if(new_c == 0)
  1412. return(c); // no substitution
  1413. if(new_c & 0xffe00000)
  1414. {
  1415. // there is a second character to be inserted
  1416. // don't convert the case of the second character unless the next letter is also upper case
  1417. c2 = new_c >> 16;
  1418. if(upper_case && iswupper(next_in))
  1419. c2 = towupper(c2);
  1420. *insert = c2;
  1421. new_c &= 0xffff;
  1422. }
  1423. if(upper_case)
  1424. new_c = towupper(new_c);
  1425. return(new_c);
  1426. }
  1427. int Translator::TranslateChar(char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert)
  1428. {//=====================================================================================================
  1429. // To allow language specific examination and replacement of characters
  1430. return(SubstituteChar(this,c,next_in,insert));
  1431. }
  1432. void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_out, char **voice_change)
  1433. {//======================================================================================================
  1434. int ix;
  1435. int c;
  1436. int cc;
  1437. unsigned int source_index=0;
  1438. unsigned int prev_source_index=0;
  1439. int prev_in;
  1440. int prev_out=' ';
  1441. int prev_out2;
  1442. int prev_in2=0;
  1443. int next_in;
  1444. int char_inserted=0;
  1445. int clause_pause;
  1446. int pre_pause=0;
  1447. int pre_pause_add=0;
  1448. int word_mark = 0;
  1449. int all_upper_case=FLAG_ALL_UPPER;
  1450. int finished;
  1451. int single_quoted;
  1452. int phoneme_mode = 0;
  1453. int dict_flags; // returned from dictionary lookup
  1454. int word_flags; // set here
  1455. int next_word_flags;
  1456. int embedded_count = 0;
  1457. int letter_count = 0;
  1458. int space_inserted = 0;
  1459. char *word;
  1460. char *p;
  1461. int j, k;
  1462. int n_digits;
  1463. unsigned short charix[N_TR_SOURCE+1];
  1464. WORD_TAB words[N_CLAUSE_WORDS];
  1465. int word_count=0; // index into words
  1466. char sbuf[512];
  1467. int terminator;
  1468. int tone;
  1469. p_textinput = (char *)vp_input;
  1470. p_wchar_input = (wchar_t *)vp_input;
  1471. embedded_ix = 0;
  1472. embedded_read = 0;
  1473. if((clause_start_char = count_characters) < 0)
  1474. clause_start_char = 0;
  1475. clause_start_word = count_words + 1;
  1476. for(ix=0; ix<N_TR_SOURCE; ix++)
  1477. charix[ix] = 0;
  1478. terminator = translator->ReadClause(f_text,source,charix,N_TR_SOURCE);
  1479. charix[N_TR_SOURCE] = count_characters;
  1480. clause_pause = (terminator & 0xff) * 10; // mS
  1481. tone = (terminator & 0xf00) >> 8;
  1482. for(p=source; *p != 0; p++)
  1483. {
  1484. if(!isspace2(*p))
  1485. {
  1486. break;
  1487. }
  1488. }
  1489. if(*p == 0)
  1490. {
  1491. // No characters except spaces. This is not a sentence.
  1492. // Don't add this pause, just make up the previous pause to this value;
  1493. clause_pause -= max_clause_pause;
  1494. if(clause_pause < 0)
  1495. clause_pause = 0;
  1496. terminator &= ~CLAUSE_BIT_SENTENCE; // clear sentence bit
  1497. max_clause_pause += clause_pause;
  1498. }
  1499. else
  1500. {
  1501. max_clause_pause = clause_pause;
  1502. }
  1503. if(new_sentence)
  1504. {
  1505. count_sentences++;
  1506. if(skip_sentences > 0)
  1507. {
  1508. skip_sentences--;
  1509. if(skip_sentences == 0)
  1510. skipping_text = 0;
  1511. }
  1512. }
  1513. ph_list2[0].phcode = phonPAUSE_SHORT;
  1514. ph_list2[0].stress = 0;
  1515. ph_list2[0].tone_number = 0;
  1516. ph_list2[0].sourceix = 0;
  1517. n_ph_list2 = 1;
  1518. prev_last_stress = 0;
  1519. prepause_timeout = 0;
  1520. word_count = 0;
  1521. single_quoted = 0;
  1522. word_flags = 0;
  1523. next_word_flags = 0;
  1524. expect_verb=0;
  1525. expect_past=0;
  1526. expect_verb_s=0;
  1527. end_stressed_vowel=0;
  1528. prev_dict_flags = 0;
  1529. sbuf[0] = 0;
  1530. sbuf[1] = ' ';
  1531. sbuf[2] = ' ';
  1532. ix = 3;
  1533. prev_in = ' ';
  1534. words[0].start = ix;
  1535. words[0].flags = 0;
  1536. finished = 0;
  1537. for(j=0; charix[j]==0; j++);
  1538. words[0].sourceix = charix[j];
  1539. for(k=j; charix[k]!=0; k++);
  1540. words[0].length = k-j;
  1541. while(!finished && (ix < (int)sizeof(sbuf))&& (n_ph_list2 < N_PHONEME_LIST-4))
  1542. {
  1543. prev_out2 = prev_out;
  1544. utf8_in(&prev_out,&sbuf[ix-1],1); // prev_out = sbuf[ix-1];
  1545. if(langopts.tone_numbers && IsDigit09(prev_out) && IsAlpha(prev_out2))
  1546. {
  1547. // tone numbers can be part of a word, consider them as alphabetic
  1548. prev_out = 'a';
  1549. }
  1550. if(prev_in2 != 0)
  1551. {
  1552. prev_in = prev_in2;
  1553. prev_in2 = 0;
  1554. }
  1555. else
  1556. if(source_index > 0)
  1557. {
  1558. utf8_in(&prev_in,&source[source_index-1],1); // prev_in = source[source_index-1];
  1559. }
  1560. prev_source_index = source_index;
  1561. if(char_inserted)
  1562. {
  1563. c = char_inserted;
  1564. char_inserted = 0;
  1565. }
  1566. else
  1567. {
  1568. source_index += utf8_in(&cc,&source[source_index],0); // cc = source[source_index++];
  1569. c = cc;
  1570. }
  1571. utf8_in(&next_in,&source[source_index],0);
  1572. if((c == CTRL_EMBEDDED) || (c == ctrl_embedded))
  1573. {
  1574. // start of embedded command in the text
  1575. int srcix = source_index-1;
  1576. if(prev_in != ' ')
  1577. {
  1578. c = ' ';
  1579. prev_in2 = c;
  1580. source_index--;
  1581. }
  1582. else
  1583. {
  1584. embedded_count += EmbeddedCommand(source_index);
  1585. prev_in2 = prev_in;
  1586. // replace the embedded command by spaces
  1587. memset(&source[srcix],' ',source_index-srcix);
  1588. source_index = srcix;
  1589. continue;
  1590. }
  1591. }
  1592. if(phoneme_mode)
  1593. {
  1594. all_upper_case = FLAG_PHONEMES;
  1595. if((c == ']') && (next_in == ']'))
  1596. {
  1597. phoneme_mode = 0;
  1598. source_index++;
  1599. c = ' ';
  1600. }
  1601. }
  1602. else
  1603. if((option_sayas2 & 0xf0) == SAYAS_DIGITS)
  1604. {
  1605. if(iswdigit(c))
  1606. {
  1607. count_sayas_digits++;
  1608. if(count_sayas_digits > (option_sayas2 & 0xf))
  1609. {
  1610. // break after the specified number of digits
  1611. c = ' ';
  1612. space_inserted = 1;
  1613. count_sayas_digits = 0;
  1614. }
  1615. }
  1616. else
  1617. {
  1618. count_sayas_digits = 0;
  1619. if(iswdigit(prev_out))
  1620. {
  1621. c = ' ';
  1622. space_inserted = 1;
  1623. }
  1624. }
  1625. }
  1626. else
  1627. if((option_sayas2 & 0xf0) != 0x10)
  1628. {
  1629. // speak as words
  1630. #ifdef deleted
  1631. if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_out))
  1632. {
  1633. // TESTING, explicit indication of stressed syllable by /2 after the word
  1634. word_mark = next_in-'0';
  1635. source_index++;
  1636. c = ' ';
  1637. }
  1638. #endif
  1639. if((c == 0x92) || (c == 0xb4) || (c == 0x2019))
  1640. c = '\''; // 'microsoft' quote or sexed closing single quote - possibly used as apostrophe
  1641. if((c == '?') && IsAlpha(prev_out) && IsAlpha(next_in))
  1642. {
  1643. // ? between two letters may be a smart-quote replaced by ?
  1644. c = '\'';
  1645. }
  1646. c = TranslateChar(&source[source_index], prev_in,c, next_in, &char_inserted); // optional language specific function
  1647. if(c == 8)
  1648. continue; // ignore this character
  1649. if(char_inserted)
  1650. next_in = char_inserted;
  1651. if(!IsAlpha(c) && !iswspace(c) && (c != '\''))
  1652. {
  1653. if(IsAlpha(prev_out))
  1654. {
  1655. if(langopts.tone_numbers && IsDigit09(c) && !IsDigit09(next_in))
  1656. {
  1657. // allow a tone number as part of the word
  1658. }
  1659. else
  1660. {
  1661. c = ' '; // ensure we have an end-of-word terminator
  1662. space_inserted = 1;
  1663. }
  1664. }
  1665. }
  1666. if(iswdigit(prev_out))
  1667. {
  1668. if(!iswdigit(c) && (c != '.') && (c != ','))
  1669. {
  1670. c = ' '; // terminate digit string with a space
  1671. space_inserted = 1;
  1672. }
  1673. }
  1674. if((c == '[') && (next_in == '[') && option_phoneme_input)
  1675. {
  1676. phoneme_mode = FLAG_PHONEMES;
  1677. source_index++;
  1678. continue;
  1679. }
  1680. if(c == 0)
  1681. {
  1682. finished = 1;
  1683. c = ' ';
  1684. }
  1685. else
  1686. if(IsAlpha(c))
  1687. {
  1688. if(!IsAlpha(prev_out) || (langopts.ideographs && ((c >= 0x3000) || (prev_out >= 0x3000))))
  1689. {
  1690. if(prev_out != '\'')
  1691. letter_count = 0; // don't reset count for an apostrophy within a word
  1692. if((prev_out != ' ') && (prev_out != '\''))
  1693. {
  1694. // start of word, insert space if not one there already
  1695. c = ' ';
  1696. space_inserted = 1;
  1697. }
  1698. else
  1699. {
  1700. if(iswupper(c))
  1701. word_flags |= FLAG_FIRST_UPPER;
  1702. if((prev_out == ' ') && iswdigit(sbuf[ix-2]) && !iswdigit(prev_in))
  1703. {
  1704. // word, following a number, but with a space between
  1705. // Add an extra space, to distinguish "2 a" from "2a"
  1706. sbuf[ix++] = ' ';
  1707. words[word_count].start++;
  1708. }
  1709. }
  1710. }
  1711. letter_count++;
  1712. if(iswupper(c))
  1713. {
  1714. c = towlower(c);
  1715. if(iswlower(prev_in))
  1716. {
  1717. c = ' '; // lower case followed by upper case, treat as new word
  1718. space_inserted = 1;
  1719. prev_in2 = c;
  1720. }
  1721. //#ifdef deleted
  1722. // changed to break after the last uppercase letter, not before. See below
  1723. else
  1724. if((c != ' ') && iswupper(prev_in) && iswlower(next_in) &&
  1725. (memcmp(&source[source_index],"s ",2) != 0)) // ENGLISH specific plural
  1726. {
  1727. c = ' '; // change from upper to lower case, start new word at the last uppercase
  1728. space_inserted = 1;
  1729. prev_in2 = c;
  1730. next_word_flags |= FLAG_NOSPACE;
  1731. }
  1732. //#endif
  1733. }
  1734. else
  1735. {
  1736. #ifdef deleted
  1737. if(iswupper(prev_in) && iswalpha(prev_out2) &&
  1738. (memcmp(&source[source_index-1],"s ",2) != 0)) // ENGLISH specific plural
  1739. {
  1740. // change to break after the last uppercase letter, not before.
  1741. c = ' '; // more than one upper case followed by lower case, treat as new word
  1742. space_inserted = 1;
  1743. prev_in2 = c;
  1744. }
  1745. #endif
  1746. if((all_upper_case) && (letter_count > 2))
  1747. {
  1748. if((c == 's') && (next_in==' '))
  1749. {
  1750. c = ' ';
  1751. all_upper_case |= FLAG_HAS_PLURAL;
  1752. if(sbuf[ix-1] == '\'')
  1753. sbuf[ix-1] = ' ';
  1754. }
  1755. else
  1756. all_upper_case = 0; // current word contains lower case letters, not "'s"
  1757. }
  1758. else
  1759. all_upper_case = 0;
  1760. }
  1761. }
  1762. else
  1763. if(c=='-')
  1764. {
  1765. if(IsAlpha(prev_in) && IsAlpha(next_in))
  1766. {
  1767. // '-' between two letters is a hyphen, treat as a space
  1768. word_flags |= FLAG_HYPHEN;
  1769. words[word_count-1].flags |= FLAG_HYPHEN_AFTER;
  1770. c = ' ';
  1771. }
  1772. else
  1773. if((prev_in==' ') && (next_in==' '))
  1774. {
  1775. // ' - ' dash between two spaces, treat as pause
  1776. c = ' ';
  1777. pre_pause_add = 4;
  1778. }
  1779. else
  1780. if(next_in=='-')
  1781. {
  1782. // double hyphen, treat as pause
  1783. source_index++;
  1784. c = ' ';
  1785. pre_pause_add = 4;
  1786. }
  1787. else
  1788. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1789. {
  1790. // insert extra space between a word + space + hyphen, to distinguish 'a -2' from 'a-2'
  1791. sbuf[ix++] = ' ';
  1792. words[word_count].start++;
  1793. }
  1794. }
  1795. else
  1796. if(c == '\'')
  1797. {
  1798. if(iswalnum(prev_in) && IsAlpha(next_in))
  1799. {
  1800. // between two letters, consider apostrophe as part of the word
  1801. single_quoted = 0;
  1802. }
  1803. else
  1804. if((wcschr(char_plus_apostrophe,prev_in) != 0) && (prev_out2 == ' '))
  1805. {
  1806. // consider single character plus apostrophe as a word
  1807. single_quoted = 0;
  1808. if(next_in == ' ')
  1809. {
  1810. source_index++; // skip following space
  1811. }
  1812. }
  1813. else
  1814. {
  1815. if((prev_out == 's') && (single_quoted==0))
  1816. {
  1817. // looks like apostrophe after an 's'
  1818. c = ' ';
  1819. }
  1820. else
  1821. {
  1822. if(iswspace(prev_out))
  1823. single_quoted = 1;
  1824. else
  1825. single_quoted = 0;
  1826. pre_pause_add = 4; // single quote
  1827. c = ' ';
  1828. }
  1829. }
  1830. }
  1831. else
  1832. if(IsBracket(c))
  1833. {
  1834. pre_pause_add = 4;
  1835. c = ' ';
  1836. }
  1837. else
  1838. if(lookupwchar(breaks,c) != 0)
  1839. {
  1840. c = ' '; // various characters to treat as space
  1841. }
  1842. else
  1843. if(iswdigit(c))
  1844. {
  1845. if(langopts.tone_numbers && IsAlpha(prev_out) && !IsDigit(next_in))
  1846. {
  1847. }
  1848. else
  1849. if((prev_out != ' ') && !iswdigit(prev_out) && (prev_out != langopts.decimal_sep)) // TEST2
  1850. {
  1851. c = ' ';
  1852. space_inserted = 1;
  1853. }
  1854. else
  1855. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1856. {
  1857. // insert extra space between a word and a number, to distinguish 'a 2' from 'a2'
  1858. sbuf[ix++] = ' ';
  1859. words[word_count].start++;
  1860. }
  1861. }
  1862. }
  1863. if(iswspace(c))
  1864. {
  1865. if(space_inserted)
  1866. {
  1867. source_index = prev_source_index; // rewind to the previous character
  1868. char_inserted = 0;
  1869. space_inserted = 0;
  1870. }
  1871. if(prev_out == ' ')
  1872. {
  1873. continue; // multiple spaces
  1874. }
  1875. // end of 'word'
  1876. sbuf[ix++] = ' ';
  1877. if((ix > words[word_count].start) && (word_count < N_CLAUSE_WORDS-1))
  1878. {
  1879. if(embedded_count > 0)
  1880. {
  1881. // there are embedded commands before this word
  1882. embedded_list[embedded_ix-1] |= 0x80; // terminate list of commands for this word
  1883. words[word_count].flags |= FLAG_EMBEDDED;
  1884. embedded_count = 0;
  1885. }
  1886. words[word_count].pre_pause = pre_pause;
  1887. words[word_count].flags |= (all_upper_case | word_flags);
  1888. words[word_count].wmark = word_mark;
  1889. if(pre_pause > 0)
  1890. {
  1891. // insert an extra space before the word, to prevent influence from previous word across the pause
  1892. for(j=ix; j>words[word_count].start; j--)
  1893. {
  1894. sbuf[j] = sbuf[j-1];
  1895. }
  1896. sbuf[j] = ' ';
  1897. words[word_count].start++;
  1898. ix++;
  1899. }
  1900. word_count++;
  1901. words[word_count].start = ix;
  1902. words[word_count].flags = 0;
  1903. for(j=source_index; charix[j] == 0; j++);
  1904. words[word_count].sourceix = charix[j];
  1905. for(k=j; charix[k]!=0; k++);
  1906. words[word_count].length = k-j;
  1907. word_flags = next_word_flags;
  1908. next_word_flags = 0;
  1909. pre_pause = 0;
  1910. word_mark = 0;
  1911. all_upper_case = FLAG_ALL_UPPER;
  1912. }
  1913. }
  1914. else
  1915. {
  1916. ix += utf8_out(c,&sbuf[ix]); // sbuf[ix++] = c;
  1917. }
  1918. if(pre_pause_add > pre_pause)
  1919. pre_pause = pre_pause_add;
  1920. pre_pause_add = 0;
  1921. }
  1922. if((word_count==0) && (embedded_count > 0))
  1923. {
  1924. // add a null 'word' to carry the embedded command flag
  1925. embedded_list[embedded_ix-1] |= 0x80;
  1926. words[word_count].flags |= FLAG_EMBEDDED;
  1927. word_count = 1;
  1928. }
  1929. clause_end = &sbuf[ix-1];
  1930. sbuf[ix] = 0;
  1931. words[0].pre_pause = 0; // don't add extra pause at beginning of clause
  1932. words[word_count].pre_pause = 8;
  1933. if(word_count > 0)
  1934. words[word_count-1].flags |= FLAG_LAST_WORD;
  1935. for(ix=0; ix<word_count; ix++)
  1936. {
  1937. int j;
  1938. char *pn;
  1939. char *pw;
  1940. char number_buf[80];
  1941. // start speaking at a specified word position in the text?
  1942. count_words++;
  1943. if(skip_words > 0)
  1944. {
  1945. skip_words--;
  1946. if(skip_words == 0)
  1947. skipping_text = 0;
  1948. }
  1949. if(skipping_text)
  1950. continue;
  1951. // digits should have been converted to Latin alphabet ('0' to '9')
  1952. word = pw = &sbuf[words[ix].start];
  1953. for(n_digits=0; iswdigit(word[n_digits]); n_digits++); // count consecutive digits
  1954. if((n_digits > 4) && (word[0] != '0'))
  1955. {
  1956. // word is entirely digits, insert commas and break into 3 digit "words"
  1957. number_buf[0] = ' ';
  1958. pn = &number_buf[1];
  1959. j = n_digits;
  1960. while(pn < &number_buf[sizeof(number_buf)-3])
  1961. {
  1962. if(!isdigit(c = *pw++) && (c != langopts.decimal_sep))
  1963. break;
  1964. *pn++ = c;
  1965. if((--j > 0) && (j % 3)==0)
  1966. {
  1967. if(langopts.thousands_sep != ' ')
  1968. *pn++ = langopts.thousands_sep;
  1969. *pn++ = ' ';
  1970. }
  1971. }
  1972. pn[0] = ' ';
  1973. pn[1] = 0;
  1974. word = pw;
  1975. for(pw = &number_buf[1]; pw < pn;)
  1976. {
  1977. TranslateWord2(pw, &words[ix], words[ix].pre_pause,0 );
  1978. while(*pw++ != ' ');
  1979. words[ix].pre_pause = 0;
  1980. words[ix].flags = 0;
  1981. }
  1982. }
  1983. else
  1984. {
  1985. dict_flags = TranslateWord2(word, &words[ix], words[ix].pre_pause, words[ix+1].pre_pause);
  1986. if(dict_flags & FLAG_SKIPWORDS)
  1987. ix += dictionary_skipwords; // dictionary indicates skip next word(s)
  1988. if((dict_flags & FLAG_DOT) && (ix == word_count-1) && (terminator == CLAUSE_PERIOD))
  1989. {
  1990. // probably an abbreviation such as Mr. or B. rather than end of sentence
  1991. clause_pause = 10;
  1992. tone = 4;
  1993. }
  1994. }
  1995. }
  1996. for(ix=0; ix<2; ix++)
  1997. {
  1998. // terminate the clause with 2 PAUSE phonemes
  1999. ph_list2[n_ph_list2+ix].phcode = phonPAUSE;
  2000. ph_list2[n_ph_list2+ix].stress = 0;
  2001. ph_list2[n_ph_list2+ix].sourceix = 0;
  2002. ph_list2[n_ph_list2+ix].synthflags = 0;
  2003. }
  2004. n_ph_list2 += 2;
  2005. if(Eof() && ((word_count == 0) || (option_endpause==0)))
  2006. {
  2007. clause_pause = 10;
  2008. }
  2009. MakePhonemeList(clause_pause, new_sentence);
  2010. if(embedded_count) // ???? is this needed
  2011. {
  2012. phoneme_list[n_phoneme_list-2].synthflags = SFLAG_EMBEDDED;
  2013. embedded_list[embedded_ix-1] |= 0x80;
  2014. }
  2015. prev_clause_pause = clause_pause;
  2016. *tone_out = tone;
  2017. new_sentence = 0;
  2018. if(terminator & CLAUSE_BIT_SENTENCE)
  2019. {
  2020. new_sentence = 1; // next clause is a new sentence
  2021. }
  2022. if(voice_change != NULL)
  2023. {
  2024. // return new voice name if an embedded voice change command terminated the clause
  2025. if(terminator & CLAUSE_BIT_VOICE)
  2026. *voice_change = &source[source_index];
  2027. else
  2028. *voice_change = NULL;
  2029. }
  2030. if(Eof() || (vp_input==NULL))
  2031. return(NULL);
  2032. if(option_multibyte == espeakCHARS_WCHAR)
  2033. return((void *)p_wchar_input);
  2034. else
  2035. return((void *)p_textinput);
  2036. } // end of TranslateClause
  2037. void InitText(int control)
  2038. {//=======================
  2039. count_sentences = 0;
  2040. count_words = 0;
  2041. end_character_position = 0;
  2042. skip_sentences = 0;
  2043. skip_marker[0] = 0;
  2044. skip_words = 0;
  2045. skip_characters = 0;
  2046. skipping_text = 0;
  2047. new_sentence = 1;
  2048. ungot_char = 0;
  2049. prev_clause_pause = 0;
  2050. option_sayas = 0;
  2051. option_sayas2 = 0;
  2052. option_emphasis = 0;
  2053. InitText2();
  2054. if((control & espeakKEEP_NAMEDATA) == 0)
  2055. {
  2056. InitNamedata();
  2057. }
  2058. }