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

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