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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470
  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. 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); // Tamil 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. posn++;
  641. if(phonemes[0] == phonSWITCH)
  642. {
  643. // change to another language in order to translate this word
  644. strcpy(word_phonemes,phonemes);
  645. return(0);
  646. }
  647. }
  648. SetSpellingStress(phonemes,spell_word,posn);
  649. }
  650. else
  651. if(found == 0)
  652. {
  653. // word's pronunciation is not given in the dictionary list, although
  654. // dictionary_flags may have ben set there
  655. posn = 0;
  656. length = 999;
  657. wordx = word1;
  658. while(((length < 3) && (length > 0))|| (word_length > 1 && Unpronouncable(wordx)))
  659. {
  660. char *p;
  661. // This word looks "unpronouncable", so speak letters individually until we
  662. // find a remainder that we can pronounce.
  663. emphasize_allcaps = 0;
  664. wordx += TranslateLetter(wordx,phonemes,0);
  665. posn++;
  666. if(phonemes[0] == phonSWITCH)
  667. {
  668. // change to another language in order to translate this word
  669. strcpy(word_phonemes,phonemes);
  670. return(0);
  671. }
  672. p = &wordx[word_length-3];
  673. if(memcmp(p,"'s ",3) == 0)
  674. {
  675. // remove a 's suffix and pronounce this separately (not as an individual letter)
  676. add_plural_suffix = 1;
  677. p[0] = ' ';
  678. p[1] = ' ';
  679. last_char = p[-1];
  680. }
  681. length=0;
  682. while(wordx[length] != ' ') length++;
  683. if(length > 0)
  684. wordx[-1] = ' '; // prevent this affecting the pronunciation of the pronuncable part
  685. }
  686. SetSpellingStress(phonemes,0,posn);
  687. // anything left ?
  688. if(*wordx != ' ')
  689. {
  690. // Translate the stem
  691. unpron_length = strlen(phonemes);
  692. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags, dictionary_flags[0]);
  693. if(phonemes[0] == phonSWITCH)
  694. {
  695. // change to another language in order to translate this word
  696. strcpy(word_phonemes,phonemes);
  697. return(0);
  698. }
  699. c_temp = wordx[-1];
  700. found = 0;
  701. confirm_prefix = 1;
  702. while(end_type & SUFX_P)
  703. {
  704. // Found a standard prefix, remove it and retranslate
  705. if(confirm_prefix)
  706. {
  707. int end2;
  708. char phonemes2[N_WORD_PHONEMES];
  709. char end_phonemes2[N_WORD_PHONEMES];
  710. // remove any standard suffix and confirm that the prefix is still recognised
  711. phonemes2[0] = 0;
  712. end2 = TranslateRules(wordx, phonemes2, N_WORD_PHONEMES, end_phonemes2, wflags|FLAG_NO_PREFIX|FLAG_NO_TRACE, dictionary_flags[0]);
  713. if(end2)
  714. {
  715. RemoveEnding(wordx,end2,word_copy);
  716. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, wflags|FLAG_NO_TRACE, dictionary_flags[0]);
  717. memcpy(wordx,word_copy,strlen(word_copy));
  718. if((end_type & SUFX_P) == 0)
  719. {
  720. // after removing the suffix, the prefix is no longer recognised.
  721. // Keep the suffix, but don't use the prefix
  722. end_type = end2;
  723. strcpy(phonemes,phonemes2);
  724. strcpy(end_phonemes,end_phonemes2);
  725. if(option_phonemes == 2)
  726. {
  727. DecodePhonemes(end_phonemes,end_phonemes2);
  728. fprintf(f_trans," suffix [%s]\n\n",end_phonemes2);
  729. }
  730. }
  731. confirm_prefix = 0;
  732. continue;
  733. }
  734. }
  735. strcat(prefix_phonemes,end_phonemes);
  736. end_phonemes[0] = 0;
  737. prefix_type = end_type;
  738. if(prefix_type & SUFX_V)
  739. {
  740. expect_verb = 1; // use the verb form of the word
  741. }
  742. wordx[-1] = c_temp;
  743. for(ix=(prefix_type & 0xf); ix>0; ix--) // num. of characters to remove
  744. {
  745. wordx++;
  746. while((*wordx & 0xc0) == 0x80) wordx++; // for multibyte characters
  747. }
  748. c_temp = wordx[-1];
  749. wordx[-1] = ' ';
  750. confirm_prefix = 1;
  751. end_type = 0;
  752. found = LookupDictList(&wordx, phonemes, dictionary_flags2, SUFX_P, wtab); // without prefix
  753. if(dictionary_flags[0]==0)
  754. {
  755. dictionary_flags[0] = dictionary_flags2[0];
  756. dictionary_flags[1] = dictionary_flags2[1];
  757. }
  758. else
  759. prefix_flags = 1;
  760. if(found == 0)
  761. {
  762. end_type = TranslateRules(wordx, phonemes, N_WORD_PHONEMES, end_phonemes, 0, dictionary_flags[0]);
  763. if(phonemes[0] == phonSWITCH)
  764. {
  765. // change to another language in order to translate this word
  766. wordx[-1] = c_temp;
  767. strcpy(word_phonemes,phonemes);
  768. return(0);
  769. }
  770. }
  771. }
  772. if((end_type != 0) && !(end_type & SUFX_P))
  773. {
  774. char phonemes2[N_WORD_PHONEMES];
  775. strcpy(phonemes2,phonemes);
  776. // The word has a standard ending, re-translate without this ending
  777. end_flags = RemoveEnding(wordx,end_type,word_copy);
  778. phonemes_ptr = &phonemes[unpron_length];
  779. phonemes_ptr[0] = 0;
  780. if(prefix_phonemes[0] != 0)
  781. {
  782. // lookup the stem without the prefix removed
  783. wordx[-1] = c_temp;
  784. found = LookupDictList(&word1, phonemes_ptr, dictionary_flags2, end_flags, wtab); // include prefix, but not suffix
  785. wordx[-1] = ' ';
  786. if(dictionary_flags[0]==0)
  787. {
  788. dictionary_flags[0] = dictionary_flags2[0];
  789. dictionary_flags[1] = dictionary_flags2[1];
  790. }
  791. if(found)
  792. prefix_phonemes[0] = 0; // matched whole word, don't need prefix now
  793. if((found==0) && (dictionary_flags2[0] != 0))
  794. prefix_flags = 1;
  795. }
  796. if(found == 0)
  797. {
  798. found = LookupDictList(&wordx, phonemes_ptr, dictionary_flags2, end_flags, wtab); // without prefix and suffix
  799. if(phonemes_ptr[0] == phonSWITCH)
  800. {
  801. // change to another language in order to translate this word
  802. memcpy(wordx,word_copy,strlen(word_copy));
  803. strcpy(word_phonemes,phonemes_ptr);
  804. return(0);
  805. }
  806. if(dictionary_flags[0]==0)
  807. {
  808. dictionary_flags[0] = dictionary_flags2[0];
  809. dictionary_flags[1] = dictionary_flags2[1];
  810. }
  811. }
  812. if(found == 0)
  813. {
  814. if(end_type & SUFX_Q)
  815. {
  816. // don't retranslate, use the original lookup result
  817. strcpy(phonemes,phonemes2);
  818. // language specific changes
  819. ApplySpecialAttribute(phonemes,dictionary_flags[0]);
  820. }
  821. else
  822. {
  823. if(end_flags & FLAG_SUFX)
  824. TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags | FLAG_SUFFIX_REMOVED, dictionary_flags[0]);
  825. else
  826. TranslateRules(wordx, phonemes, N_WORD_PHONEMES, NULL,wflags,dictionary_flags[0]);
  827. if(phonemes[0] == phonSWITCH)
  828. {
  829. // change to another language in order to translate this word
  830. strcpy(word_phonemes,phonemes);
  831. memcpy(wordx,word_copy,strlen(word_copy));
  832. wordx[-1] = c_temp;
  833. return(0);
  834. }
  835. }
  836. }
  837. if((end_type & SUFX_T) == 0)
  838. {
  839. // the default is to add the suffix and then determine the word's stress pattern
  840. AppendPhonemes(phonemes, N_WORD_PHONEMES, end_phonemes);
  841. end_phonemes[0] = 0;
  842. }
  843. }
  844. wordx[-1] = c_temp;
  845. }
  846. }
  847. if((add_plural_suffix) || (wflags & FLAG_HAS_PLURAL))
  848. {
  849. // s or 's suffix, append [s], [z] or [Iz] depending on previous letter
  850. if(last_char == 'f')
  851. TranslateRules(&word_ss[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  852. else
  853. if((last_char==0) || (strchr_w("hsx",last_char)==NULL))
  854. TranslateRules(&word_zz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  855. else
  856. TranslateRules(&word_iz[1], phonemes, N_WORD_PHONEMES, NULL, 0, 0);
  857. }
  858. wflags |= emphasize_allcaps;
  859. /* determine stress pattern for this word */
  860. /******************************************/
  861. /* NOTE: this also adds a single PAUSE if the previous word ended
  862. in a primary stress, and this one starts with one */
  863. if(prefix_flags || (strchr(prefix_phonemes,phonSTRESS_P)!=NULL))
  864. {
  865. if((langopts.param[LOPT_PREFIXES]) || (prefix_type & SUFX_T))
  866. {
  867. char *p;
  868. // German, keep a secondary stress on the stem
  869. SetWordStress(phonemes,dictionary_flags[0],3,0);
  870. // reduce all but the first primary stress
  871. ix=0;
  872. for(p=prefix_phonemes; *p != 0; p++)
  873. {
  874. if(*p == phonSTRESS_P)
  875. {
  876. if(ix==0)
  877. ix=1;
  878. else
  879. *p = phonSTRESS_3;
  880. }
  881. }
  882. strcpy(word_phonemes,prefix_phonemes);
  883. strcat(word_phonemes,phonemes);
  884. SetWordStress(word_phonemes,dictionary_flags[0],-1,0);
  885. }
  886. else
  887. {
  888. // stress position affects the whole word, including prefix
  889. strcpy(word_phonemes,prefix_phonemes);
  890. strcat(word_phonemes,phonemes);
  891. SetWordStress(word_phonemes,dictionary_flags[0],-1,prev_last_stress);
  892. }
  893. }
  894. else
  895. {
  896. if(prefix_phonemes[0] == 0)
  897. SetWordStress(phonemes,dictionary_flags[0],-1,prev_last_stress);
  898. else
  899. SetWordStress(phonemes,dictionary_flags[0],-1,0);
  900. strcpy(word_phonemes,prefix_phonemes);
  901. strcat(word_phonemes,phonemes);
  902. }
  903. if(end_phonemes[0] != 0)
  904. {
  905. // a suffix had the SUFX_T option set, add the suffix after the stress pattern has been determined
  906. strcat(word_phonemes,end_phonemes);
  907. }
  908. if(wflags & FLAG_LAST_WORD)
  909. {
  910. // don't use $brk pause before the last word of a sentence
  911. // (but allow it for emphasis, see below
  912. dictionary_flags[0] &= ~FLAG_PAUSE1;
  913. }
  914. if(wflags & FLAG_EMPHASIZED)
  915. {
  916. // A word is indicated in the source text as stressed
  917. // Give it stress level 6 (for the intonation module)
  918. ChangeWordStress(this,word_phonemes,6);
  919. // if(!(wflags & FLAG_LAST_WORD)) // ?? omit pre-pause if it's the last word in the sentence?
  920. dictionary_flags[0] |= FLAG_PAUSE1; // precede by short pause
  921. }
  922. else
  923. if(wtab[dictionary_skipwords].flags & FLAG_LAST_WORD)
  924. {
  925. // the word has attribute to stress or unstress when at end of clause
  926. if(dictionary_flags[0] & (FLAG_STRESS_END | FLAG_STRESS_END2))
  927. ChangeWordStress(this,word_phonemes,4);
  928. else
  929. if(dictionary_flags[0] & FLAG_UNSTRESS_END)
  930. ChangeWordStress(this,word_phonemes,3);
  931. }
  932. // dictionary flags for this word give a clue about which alternative pronunciations of
  933. // following words to use.
  934. if(end_type & SUFX_F)
  935. {
  936. // expect a verb form, with or without -s suffix
  937. expect_verb = 2;
  938. expect_verb_s = 2;
  939. }
  940. if(dictionary_flags[1] & FLAG_PASTF)
  941. {
  942. /* expect perfect tense in next two words */
  943. expect_past = 3;
  944. expect_verb = 0;
  945. expect_noun = 0;
  946. }
  947. else
  948. if(dictionary_flags[1] & FLAG_VERBF)
  949. {
  950. /* expect a verb in the next word */
  951. expect_verb = 2;
  952. expect_verb_s = 0; /* verb won't have -s suffix */
  953. expect_noun = 0;
  954. }
  955. else
  956. if(dictionary_flags[1] & FLAG_VERBSF)
  957. {
  958. // expect a verb, must have a -s suffix
  959. expect_verb = 0;
  960. expect_verb_s = 2;
  961. expect_past = 0;
  962. expect_noun = 0;
  963. }
  964. else
  965. if(dictionary_flags[1] & FLAG_NOUNF)
  966. {
  967. /* not expecting a verb next */
  968. expect_noun = 3;
  969. expect_verb = 0;
  970. expect_verb_s = 0;
  971. expect_past = 0;
  972. }
  973. if((wordx[0] != 0) && (!(dictionary_flags[1] & FLAG_VERB_EXT)))
  974. {
  975. if(expect_verb > 0)
  976. expect_verb--;
  977. if(expect_verb_s > 0)
  978. expect_verb_s--;
  979. if(expect_noun >0)
  980. expect_noun--;
  981. if(expect_past > 0)
  982. expect_past--;
  983. }
  984. if((word_length == 1) && iswalpha(first_char) && (first_char != 'i'))
  985. {
  986. // English Specific !!!!
  987. // any single letter before a dot is an abbreviation, except 'I'
  988. dictionary_flags[0] |= FLAG_DOT;
  989. }
  990. return(dictionary_flags[0]);
  991. } // end of TranslateWord
  992. static void SetPlist2(PHONEME_LIST2 *p, unsigned char phcode)
  993. {//==========================================================
  994. p->phcode = phcode;
  995. p->stress = 0;
  996. p->tone_number = 0;
  997. p->synthflags = 0;
  998. p->sourceix = 0;
  999. }
  1000. static int CountSyllables(unsigned char *phonemes)
  1001. {//===============================================
  1002. int count = 0;
  1003. int phon;
  1004. while((phon = *phonemes++) != 0)
  1005. {
  1006. if(phoneme_tab[phon]->type == phVOWEL)
  1007. count++;
  1008. }
  1009. return(count);
  1010. }
  1011. int SetTranslator2(const char *new_language)
  1012. {//=========================================
  1013. // Set translator2 to a second language
  1014. int new_phoneme_tab;
  1015. if((new_phoneme_tab = SelectPhonemeTableName(new_language)) >= 0)
  1016. {
  1017. if((translator2 != NULL) && (strcmp(new_language,translator2_language) != 0))
  1018. {
  1019. // we already have an alternative translator, but not for the required language, delete it
  1020. delete translator2;
  1021. translator2 = NULL;
  1022. }
  1023. if(translator2 == NULL)
  1024. {
  1025. translator2 = SelectTranslator(new_language);
  1026. strcpy(translator2_language,new_language);
  1027. if(translator2->LoadDictionary(new_language,0) != 0)
  1028. {
  1029. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  1030. new_phoneme_tab = -1;
  1031. translator2_language[0] = 0;
  1032. }
  1033. }
  1034. }
  1035. return(new_phoneme_tab);
  1036. } // end of SetTranslator2
  1037. int Translator::TranslateWord2(char *word, WORD_TAB *wtab, int pre_pause, int next_pause)
  1038. {//======================================================================================
  1039. int flags=0;
  1040. int stress;
  1041. int next_stress;
  1042. int next_tone=0;
  1043. unsigned char *p;
  1044. int srcix;
  1045. int embedded_flag=0;
  1046. int embedded_cmd;
  1047. int value;
  1048. int found_dict_flag;
  1049. unsigned char ph_code;
  1050. PHONEME_LIST2 *plist2;
  1051. PHONEME_TAB *ph;
  1052. int max_stress;
  1053. int max_stress_ix=0;
  1054. int prev_vowel = -1;
  1055. int pitch_raised = 0;
  1056. int switch_phonemes = -1;
  1057. int first_phoneme = 1;
  1058. int source_ix;
  1059. int len;
  1060. int sylimit; // max. number of syllables in a word to be combined with a preceding preposition
  1061. const char *new_language;
  1062. unsigned char bad_phoneme[4];
  1063. len = wtab->length;
  1064. if(len > 31) len = 31;
  1065. source_ix = (wtab->sourceix & 0x7ff) | (len << 11); // bits 0-10 sourceix, bits 11-15 word length
  1066. word_flags = wtab[0].flags;
  1067. if(word_flags & FLAG_EMBEDDED)
  1068. {
  1069. embedded_flag = SFLAG_EMBEDDED;
  1070. do
  1071. {
  1072. embedded_cmd = embedded_list[embedded_read++];
  1073. value = embedded_cmd >> 8;
  1074. switch(embedded_cmd & 0x1f)
  1075. {
  1076. case EMBED_Y:
  1077. option_sayas = value;
  1078. break;
  1079. case EMBED_F:
  1080. option_emphasis = value;
  1081. break;
  1082. case EMBED_B:
  1083. // break command
  1084. if(value == 0)
  1085. pre_pause = 0; // break=none
  1086. else
  1087. pre_pause += value;
  1088. break;
  1089. }
  1090. } while((embedded_cmd & 0x80) == 0);
  1091. }
  1092. if(word[0] == 0)
  1093. {
  1094. // nothing to translate
  1095. word_phonemes[0] = 0;
  1096. return(0);
  1097. }
  1098. // after a $pause word attribute, ignore a $pause attribute on the next two words
  1099. if(prepause_timeout > 0)
  1100. prepause_timeout--;
  1101. if((option_sayas & 0xf0) == 0x10)
  1102. {
  1103. if(!(word_flags & FLAG_FIRST_WORD))
  1104. {
  1105. // SAYAS_CHARS, SAYAS_GLYPHS, or SAYAS_SINGLECHARS. Pause between each word.
  1106. pre_pause += 4;
  1107. }
  1108. }
  1109. if(word_flags & FLAG_FIRST_UPPER)
  1110. {
  1111. if((option_capitals > 2) && (embedded_ix < N_EMBEDDED_LIST-6))
  1112. {
  1113. // indicate capital letter by raising pitch
  1114. if(embedded_flag)
  1115. embedded_list[embedded_ix-1] &= ~0x80; // already embedded command before this word, remove terminator
  1116. if((pitch_raised = option_capitals) == 3)
  1117. pitch_raised = 20; // default pitch raise for capitals
  1118. embedded_list[embedded_ix++] = EMBED_P+0x40+0x80 + (pitch_raised << 8); // raise pitch
  1119. embedded_flag = SFLAG_EMBEDDED;
  1120. }
  1121. }
  1122. p = (unsigned char *)translator->word_phonemes;
  1123. if(word_flags & FLAG_PHONEMES)
  1124. {
  1125. // The input is in phoneme mnemonics, not language text
  1126. EncodePhonemes(word,word_phonemes,bad_phoneme);
  1127. flags = FLAG_FOUND;
  1128. }
  1129. else
  1130. {
  1131. flags = translator->TranslateWord(word, next_pause, wtab);
  1132. if((flags & FLAG_ALT2_TRANS) && ((sylimit = langopts.param[LOPT_COMBINE_WORDS]) > 0))
  1133. {
  1134. char *p2;
  1135. int ok = 1;
  1136. int flags2;
  1137. int c_word2;
  1138. char ph_buf[N_WORD_PHONEMES];
  1139. // LANG=cs,sk
  1140. // combine a preposition with the following word
  1141. p2 = word;
  1142. while(*p2 != ' ') p2++;
  1143. utf8_in(&c_word2, p2+1, 0); // first character of the next word;
  1144. if(!iswalpha(c_word2))
  1145. {
  1146. ok =0;
  1147. }
  1148. if(sylimit & 0x100)
  1149. {
  1150. // only if the second word has $alt attribute
  1151. strcpy(ph_buf,word_phonemes);
  1152. flags2 = translator->TranslateWord(p2+1, 0, wtab+1);
  1153. if((flags2 & FLAG_ALT_TRANS) == 0)
  1154. {
  1155. ok = 0;
  1156. strcpy(word_phonemes,ph_buf);
  1157. }
  1158. }
  1159. if((sylimit & 0x200) && ((wtab+1)->flags & FLAG_LAST_WORD))
  1160. {
  1161. // not if the next word is end-of-sentence
  1162. ok = 0;
  1163. }
  1164. if(ok)
  1165. {
  1166. *p2 = '-'; // replace next space by hyphen
  1167. flags = translator->TranslateWord(word, next_pause, wtab); // translate the combined word
  1168. if(CountSyllables(p) > (sylimit & 0xf))
  1169. {
  1170. // revert to separate words
  1171. *p2 = ' ';
  1172. flags = translator->TranslateWord(word, next_pause, wtab);
  1173. }
  1174. else
  1175. {
  1176. flags |= FLAG_SKIPWORDS;
  1177. dictionary_skipwords = 1;
  1178. }
  1179. }
  1180. }
  1181. if(p[0] == phonSWITCH)
  1182. {
  1183. // this word uses a different language
  1184. new_language = (char *)(&p[1]);
  1185. if(new_language[0]==0)
  1186. new_language = "en";
  1187. switch_phonemes = SetTranslator2(new_language);
  1188. if(switch_phonemes >= 0)
  1189. {
  1190. // re-translate the word using the new translator
  1191. flags = translator2->TranslateWord(word, next_pause, wtab);
  1192. strcpy((char *)p,translator2->word_phonemes);
  1193. if(p[0] == phonSWITCH)
  1194. {
  1195. // the second translator doesn't want to process this word
  1196. switch_phonemes = -1;
  1197. }
  1198. }
  1199. if(switch_phonemes < 0)
  1200. {
  1201. // language code is not recognised or 2nd translator won't translate it
  1202. p[0] = phonSCHWA; // just say something
  1203. p[1] = phonSCHWA;
  1204. p[2] = 0;
  1205. }
  1206. }
  1207. if(!(word_flags & FLAG_HYPHEN))
  1208. {
  1209. if(flags & FLAG_PAUSE1)
  1210. {
  1211. if(pre_pause < 1)
  1212. pre_pause = 1;
  1213. }
  1214. if((flags & FLAG_PREPAUSE) && (prepause_timeout == 0))
  1215. {
  1216. // the word is marked in the dictionary list with $pause
  1217. if(pre_pause < 4) pre_pause = 4;
  1218. prepause_timeout = 3;
  1219. }
  1220. }
  1221. if((option_emphasis >= 3) && (pre_pause < 1))
  1222. pre_pause = 1;
  1223. }
  1224. plist2 = &ph_list2[n_ph_list2];
  1225. stress = 0;
  1226. next_stress = 0;
  1227. srcix = 0;
  1228. max_stress = -1;
  1229. found_dict_flag = 0;
  1230. if(flags & FLAG_FOUND)
  1231. found_dict_flag = SFLAG_DICTIONARY;
  1232. while((pre_pause > 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1233. {
  1234. // add pause phonemes here. Either because of punctuation (brackets or quotes) in the
  1235. // text, or because the word is marked in the dictionary lookup as a conjunction
  1236. if(pre_pause > 1)
  1237. {
  1238. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE);
  1239. pre_pause -= 2;
  1240. }
  1241. else
  1242. {
  1243. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_NOLINK);
  1244. pre_pause--;
  1245. }
  1246. end_stressed_vowel = 0; // forget about the previous word
  1247. prev_dict_flags = 0;
  1248. }
  1249. if((option_capitals==1) && (word_flags & FLAG_FIRST_UPPER))
  1250. {
  1251. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1252. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1253. if((word_flags & FLAG_ALL_UPPER) && IsAlpha(word[1]))
  1254. {
  1255. // word > 1 letter and all capitals
  1256. SetPlist2(&ph_list2[n_ph_list2++],phonPAUSE_SHORT);
  1257. SetPlist2(&ph_list2[n_ph_list2++],phonCAPITAL);
  1258. }
  1259. }
  1260. if(switch_phonemes >= 0)
  1261. {
  1262. // this word uses a different phoneme table
  1263. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1264. ph_list2[n_ph_list2++].tone_number = switch_phonemes; // temporary phoneme table number
  1265. }
  1266. // remove initial pause from a word if it follows a hyphen
  1267. if((word_flags & FLAG_HYPHEN) && (phoneme_tab[*p]->type == phPAUSE))
  1268. p++;
  1269. while(((ph_code = *p++) != 0) && (n_ph_list2 < N_PHONEME_LIST-4))
  1270. {
  1271. if(ph_code == 255)
  1272. continue; // unknown phoneme
  1273. // Add the phonemes to the first stage phoneme list (ph_list2)
  1274. ph = phoneme_tab[ph_code];
  1275. if(ph->type == phSTRESS)
  1276. {
  1277. // don't add stress phonemes codes to the list, but give their stress
  1278. // value to the next vowel phoneme
  1279. // std_length is used to hold stress number or (if >10) a tone number for a tone language
  1280. if(ph->spect == 0)
  1281. next_stress = ph->std_length;
  1282. else
  1283. {
  1284. // for tone languages, the tone number for a syllable follows the vowel
  1285. if(prev_vowel >= 0)
  1286. {
  1287. ph_list2[prev_vowel].tone_number = ph_code;
  1288. }
  1289. else
  1290. {
  1291. next_tone = ph_code; // no previous vowel, apply to the next vowel
  1292. }
  1293. }
  1294. }
  1295. else
  1296. if(ph_code == phonSYLLABIC)
  1297. {
  1298. // mark the previous phoneme as a syllabic consonant
  1299. prev_vowel = n_ph_list2-1;
  1300. ph_list2[prev_vowel].synthflags |= SFLAG_SYLLABLE;
  1301. ph_list2[prev_vowel].stress = next_stress;
  1302. }
  1303. else
  1304. if(ph_code == phonLENGTHEN)
  1305. {
  1306. ph_list2[n_ph_list2-1].synthflags |= SFLAG_LENGTHEN;
  1307. }
  1308. else
  1309. if(ph_code == phonEND_WORD)
  1310. {
  1311. // a || symbol in a phoneme string was used to indicate a word boundary
  1312. // Don't add this phoneme to the list, but make sure the next phoneme has
  1313. // a newword indication
  1314. srcix = source_ix+1;
  1315. }
  1316. else
  1317. if(ph_code == phonSWITCH2)
  1318. {
  1319. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1320. ph_list2[n_ph_list2++].tone_number = *p++ - phonTOP; // phoneme table number (phonTOP is added to avoid confusion with special phoneme numbers)
  1321. }
  1322. else
  1323. if(ph_code == phonX1)
  1324. {
  1325. // a language specific action
  1326. if(langopts.param[LOPT_IT_DOUBLING])
  1327. {
  1328. flags |= FLAG_DOUBLING;
  1329. }
  1330. }
  1331. else
  1332. {
  1333. ph_list2[n_ph_list2].phcode = ph_code;
  1334. ph_list2[n_ph_list2].tone_number = 0;
  1335. ph_list2[n_ph_list2].synthflags = embedded_flag | found_dict_flag;
  1336. embedded_flag = 0;
  1337. ph_list2[n_ph_list2].sourceix = srcix;
  1338. srcix = 0;
  1339. if(ph->type == phVOWEL)
  1340. {
  1341. stress = next_stress;
  1342. next_stress = 0;
  1343. if((prev_vowel >= 0) && (n_ph_list2-1) != prev_vowel)
  1344. ph_list2[n_ph_list2-1].stress = stress; // set stress for previous consonant
  1345. ph_list2[n_ph_list2].synthflags |= SFLAG_SYLLABLE;
  1346. prev_vowel = n_ph_list2;
  1347. if(stress > max_stress)
  1348. {
  1349. max_stress = stress;
  1350. max_stress_ix = n_ph_list2;
  1351. }
  1352. if(next_tone != 0)
  1353. {
  1354. ph_list2[n_ph_list2].tone_number = next_tone;
  1355. next_tone=0;
  1356. }
  1357. }
  1358. else
  1359. {
  1360. if(first_phoneme && langopts.param[LOPT_IT_DOUBLING])
  1361. {
  1362. if(((prev_dict_flags & FLAG_DOUBLING) && (langopts.param[LOPT_IT_DOUBLING] & 1)) ||
  1363. (end_stressed_vowel && (langopts.param[LOPT_IT_DOUBLING] & 2)))
  1364. {
  1365. // italian, double the initial consonant if the previous word ends with a
  1366. // stressed vowel, or is marked with a flag
  1367. ph_list2[n_ph_list2].synthflags |= SFLAG_LENGTHEN;
  1368. }
  1369. }
  1370. }
  1371. ph_list2[n_ph_list2].stress = stress;
  1372. n_ph_list2++;
  1373. first_phoneme = 0;
  1374. }
  1375. }
  1376. plist2->sourceix = source_ix; // ????
  1377. end_stressed_vowel = 0;
  1378. if((stress >= 4) && (phoneme_tab[ph_list2[n_ph_list2-1].phcode]->type == phVOWEL))
  1379. {
  1380. end_stressed_vowel = 1; // word ends with a stressed vowel
  1381. }
  1382. if(switch_phonemes >= 0)
  1383. {
  1384. // this word uses a different phoneme table, now switch back
  1385. SelectPhonemeTable(voice->phoneme_tab_ix);
  1386. SetPlist2(&ph_list2[n_ph_list2],phonSWITCH);
  1387. ph_list2[n_ph_list2++].tone_number = voice->phoneme_tab_ix; // original phoneme table number
  1388. }
  1389. if(pitch_raised > 0)
  1390. {
  1391. embedded_list[embedded_ix++] = EMBED_P+0x60+0x80 + (pitch_raised << 8); // lower pitch
  1392. SetPlist2(&ph_list2[n_ph_list2],phonPAUSE_SHORT);
  1393. ph_list2[n_ph_list2++].synthflags = SFLAG_EMBEDDED;
  1394. }
  1395. if(flags & FLAG_STRESS_END2)
  1396. {
  1397. // this's word's stress could be increased later
  1398. ph_list2[max_stress_ix].synthflags |= SFLAG_PROMOTE_STRESS;
  1399. }
  1400. prev_dict_flags = flags;
  1401. return(flags);
  1402. } // end of TranslateWord2
  1403. static int EmbeddedCommand(unsigned int &source_index)
  1404. {//===================================================
  1405. // An embedded command to change the pitch, volume, etc.
  1406. // returns number of commands added to embedded_list
  1407. // pitch,speed,amplitude,expression,reverb,tone,voice,sayas
  1408. const char *commands = "PSARHTIVYMUBF";
  1409. int value = -1;
  1410. int sign = 0;
  1411. unsigned char c;
  1412. char *p;
  1413. int cmd;
  1414. c = source[source_index];
  1415. if(c == '+')
  1416. {
  1417. sign = 0x40;
  1418. source_index++;
  1419. }
  1420. else
  1421. if(c == '-')
  1422. {
  1423. sign = 0x60;
  1424. source_index++;
  1425. }
  1426. if(isdigit(source[source_index]))
  1427. {
  1428. value = atoi(&source[source_index]);
  1429. while(isdigit(source[source_index]))
  1430. source_index++;
  1431. }
  1432. c = source[source_index++];
  1433. if(embedded_ix >= (N_EMBEDDED_LIST - 2))
  1434. return(0); // list is full
  1435. if((p = strchr_w(commands,c)) == NULL)
  1436. return(0);
  1437. cmd = (p - commands)+1;
  1438. if(value == -1)
  1439. {
  1440. value = embedded_default[cmd];
  1441. sign = 0;
  1442. }
  1443. if(cmd == EMBED_Y)
  1444. {
  1445. option_sayas2 = value;
  1446. count_sayas_digits = 0;
  1447. }
  1448. if(cmd == EMBED_F)
  1449. {
  1450. if(value >= 3)
  1451. word_emphasis = FLAG_EMPHASIZED;
  1452. else
  1453. word_emphasis = 0;
  1454. }
  1455. embedded_list[embedded_ix++] = cmd + sign + (value << 8);
  1456. return(1);
  1457. } // end of EmbeddedCommand
  1458. int SubstituteChar(Translator *tr, unsigned int c, unsigned int next_in, int *insert)
  1459. {//==================================================================================
  1460. int ix;
  1461. unsigned int word;
  1462. unsigned int new_c, c2, c_lower;
  1463. int upper_case = 0;
  1464. static int ignore_next = 0;
  1465. const unsigned int *replace_chars;
  1466. if(ignore_next)
  1467. {
  1468. ignore_next = 0;
  1469. return(8);
  1470. }
  1471. if(c == 0) return(0);
  1472. if((replace_chars = tr->langopts.replace_chars) == NULL)
  1473. return(c);
  1474. // there is a list of character codes to be substituted with alternative codes
  1475. if(iswupper(c_lower = c))
  1476. {
  1477. c_lower = towlower(c);
  1478. upper_case = 1;
  1479. }
  1480. new_c = 0;
  1481. for(ix=0; (word = replace_chars[ix]) != 0; ix+=2)
  1482. {
  1483. if(c_lower == (word & 0xffff))
  1484. {
  1485. if((word >> 16) == 0)
  1486. {
  1487. new_c = replace_chars[ix+1];
  1488. break;
  1489. }
  1490. if((word >> 16) == (unsigned int)tolower(next_in))
  1491. {
  1492. new_c = replace_chars[ix+1];
  1493. ignore_next = 1;
  1494. break;
  1495. }
  1496. }
  1497. }
  1498. if(new_c == 0)
  1499. return(c); // no substitution
  1500. if(new_c & 0xffe00000)
  1501. {
  1502. // there is a second character to be inserted
  1503. // don't convert the case of the second character unless the next letter is also upper case
  1504. c2 = new_c >> 16;
  1505. if(upper_case && iswupper(next_in))
  1506. c2 = towupper(c2);
  1507. *insert = c2;
  1508. new_c &= 0xffff;
  1509. }
  1510. if(upper_case)
  1511. new_c = towupper(new_c);
  1512. return(new_c);
  1513. }
  1514. int Translator::TranslateChar(char *ptr, int prev_in, unsigned int c, unsigned int next_in, int *insert)
  1515. {//=====================================================================================================
  1516. // To allow language specific examination and replacement of characters
  1517. return(SubstituteChar(this,c,next_in,insert));
  1518. }
  1519. void *Translator::TranslateClause(FILE *f_text, const void *vp_input, int *tone_out, char **voice_change)
  1520. {//======================================================================================================
  1521. int ix;
  1522. int c;
  1523. int cc;
  1524. unsigned int source_index=0;
  1525. unsigned int prev_source_index=0;
  1526. int prev_in;
  1527. int prev_out=' ';
  1528. int prev_out2;
  1529. int prev_in2=0;
  1530. int next_in;
  1531. int char_inserted=0;
  1532. int clause_pause;
  1533. int pre_pause=0;
  1534. int pre_pause_add=0;
  1535. int word_mark = 0;
  1536. int all_upper_case=FLAG_ALL_UPPER;
  1537. int finished;
  1538. int single_quoted;
  1539. int phoneme_mode = 0;
  1540. int dict_flags; // returned from dictionary lookup
  1541. int word_flags; // set here
  1542. int next_word_flags;
  1543. int embedded_count = 0;
  1544. int letter_count = 0;
  1545. int space_inserted = 0;
  1546. int syllable_marked = 0;
  1547. char *word;
  1548. char *p;
  1549. int j, k;
  1550. int n_digits;
  1551. unsigned short charix[N_TR_SOURCE+1];
  1552. WORD_TAB words[N_CLAUSE_WORDS];
  1553. int word_count=0; // index into words
  1554. char sbuf[N_TR_SOURCE];
  1555. int terminator;
  1556. int tone;
  1557. p_textinput = (char *)vp_input;
  1558. p_wchar_input = (wchar_t *)vp_input;
  1559. embedded_ix = 0;
  1560. embedded_read = 0;
  1561. if((clause_start_char = count_characters) < 0)
  1562. clause_start_char = 0;
  1563. clause_start_word = count_words + 1;
  1564. for(ix=0; ix<N_TR_SOURCE; ix++)
  1565. charix[ix] = 0;
  1566. terminator = translator->ReadClause(f_text,source,charix,N_TR_SOURCE);
  1567. charix[N_TR_SOURCE] = count_characters;
  1568. clause_pause = (terminator & 0xfff) * 10; // mS
  1569. tone = (terminator >> 12) & 0xf;
  1570. for(p=source; *p != 0; p++)
  1571. {
  1572. if(!isspace2(*p))
  1573. {
  1574. break;
  1575. }
  1576. }
  1577. if(*p == 0)
  1578. {
  1579. // No characters except spaces. This is not a sentence.
  1580. // Don't add this pause, just make up the previous pause to this value;
  1581. clause_pause -= max_clause_pause;
  1582. if(clause_pause < 0)
  1583. clause_pause = 0;
  1584. terminator &= ~CLAUSE_BIT_SENTENCE; // clear sentence bit
  1585. max_clause_pause += clause_pause;
  1586. }
  1587. else
  1588. {
  1589. max_clause_pause = clause_pause;
  1590. }
  1591. if(new_sentence)
  1592. {
  1593. count_sentences++;
  1594. if(skip_sentences > 0)
  1595. {
  1596. skip_sentences--;
  1597. if(skip_sentences == 0)
  1598. skipping_text = 0;
  1599. }
  1600. }
  1601. ph_list2[0].phcode = phonPAUSE_SHORT;
  1602. ph_list2[0].stress = 0;
  1603. ph_list2[0].tone_number = 0;
  1604. ph_list2[0].sourceix = 0;
  1605. n_ph_list2 = 1;
  1606. prev_last_stress = 0;
  1607. prepause_timeout = 0;
  1608. word_count = 0;
  1609. single_quoted = 0;
  1610. word_flags = 0;
  1611. next_word_flags = 0;
  1612. expect_verb=0;
  1613. expect_noun=0;
  1614. expect_past=0;
  1615. expect_verb_s=0;
  1616. end_stressed_vowel=0;
  1617. prev_dict_flags = 0;
  1618. sbuf[0] = 0;
  1619. sbuf[1] = ' ';
  1620. sbuf[2] = ' ';
  1621. ix = 3;
  1622. prev_in = ' ';
  1623. words[0].start = ix;
  1624. words[0].flags = 0;
  1625. finished = 0;
  1626. for(j=0; charix[j]==0; j++);
  1627. words[0].sourceix = charix[j];
  1628. for(k=j; charix[k]!=0; k++);
  1629. words[0].length = k-j;
  1630. while(!finished && (ix < (int)sizeof(sbuf))&& (n_ph_list2 < N_PHONEME_LIST-4))
  1631. {
  1632. prev_out2 = prev_out;
  1633. utf8_in(&prev_out,&sbuf[ix-1],1); // prev_out = sbuf[ix-1];
  1634. if(langopts.tone_numbers && IsDigit09(prev_out) && IsAlpha(prev_out2))
  1635. {
  1636. // tone numbers can be part of a word, consider them as alphabetic
  1637. prev_out = 'a';
  1638. }
  1639. if(prev_in2 != 0)
  1640. {
  1641. prev_in = prev_in2;
  1642. prev_in2 = 0;
  1643. }
  1644. else
  1645. if(source_index > 0)
  1646. {
  1647. utf8_in(&prev_in,&source[source_index-1],1); // prev_in = source[source_index-1];
  1648. }
  1649. prev_source_index = source_index;
  1650. if(char_inserted)
  1651. {
  1652. c = char_inserted;
  1653. char_inserted = 0;
  1654. }
  1655. else
  1656. {
  1657. source_index += utf8_in(&cc,&source[source_index],0); // cc = source[source_index++];
  1658. c = cc;
  1659. }
  1660. utf8_in(&next_in,&source[source_index],0);
  1661. if((c == CTRL_EMBEDDED) || (c == ctrl_embedded))
  1662. {
  1663. // start of embedded command in the text
  1664. int srcix = source_index-1;
  1665. if(prev_in != ' ')
  1666. {
  1667. c = ' ';
  1668. prev_in2 = c;
  1669. source_index--;
  1670. }
  1671. else
  1672. {
  1673. embedded_count += EmbeddedCommand(source_index);
  1674. prev_in2 = prev_in;
  1675. // replace the embedded command by spaces
  1676. memset(&source[srcix],' ',source_index-srcix);
  1677. source_index = srcix;
  1678. continue;
  1679. }
  1680. }
  1681. if(option_sayas2 == SAYAS_KEY)
  1682. {
  1683. if(((c == '_') || (c == '-')) && IsAlpha(prev_in))
  1684. {
  1685. c = ' ';
  1686. }
  1687. c = towlower(c);
  1688. }
  1689. if(phoneme_mode)
  1690. {
  1691. all_upper_case = FLAG_PHONEMES;
  1692. if((c == ']') && (next_in == ']'))
  1693. {
  1694. phoneme_mode = 0;
  1695. source_index++;
  1696. c = ' ';
  1697. }
  1698. }
  1699. else
  1700. if((option_sayas2 & 0xf0) == SAYAS_DIGITS)
  1701. {
  1702. if(iswdigit(c))
  1703. {
  1704. count_sayas_digits++;
  1705. if(count_sayas_digits > (option_sayas2 & 0xf))
  1706. {
  1707. // break after the specified number of digits
  1708. c = ' ';
  1709. space_inserted = 1;
  1710. count_sayas_digits = 0;
  1711. }
  1712. }
  1713. else
  1714. {
  1715. count_sayas_digits = 0;
  1716. if(iswdigit(prev_out))
  1717. {
  1718. c = ' ';
  1719. space_inserted = 1;
  1720. }
  1721. }
  1722. }
  1723. else
  1724. if((option_sayas2 & 0x30) == 0)
  1725. {
  1726. // speak as words
  1727. #ifdef deleted
  1728. if((c == '/') && (langopts.testing & 2) && IsDigit09(next_in) && IsAlpha(prev_out))
  1729. {
  1730. // TESTING, explicit indication of stressed syllable by /2 after the word
  1731. word_mark = next_in-'0';
  1732. source_index++;
  1733. c = ' ';
  1734. }
  1735. #endif
  1736. if((c == 0x92) || (c == 0xb4) || (c == 0x2019))
  1737. c = '\''; // 'microsoft' quote or sexed closing single quote - possibly used as apostrophe
  1738. if((c == '?') && IsAlpha(prev_out) && IsAlpha(next_in))
  1739. {
  1740. // ? between two letters may be a smart-quote replaced by ?
  1741. c = '\'';
  1742. }
  1743. c = TranslateChar(&source[source_index], prev_in,c, next_in, &char_inserted); // optional language specific function
  1744. if(c == 8)
  1745. continue; // ignore this character
  1746. if(char_inserted)
  1747. next_in = char_inserted;
  1748. // allow certain punctuation within a word (usually only apostrophe)
  1749. if(!IsAlpha(c) && !iswspace(c) && (wcschr(punct_within_word,c) == 0))
  1750. {
  1751. if(IsAlpha(prev_out))
  1752. {
  1753. if(langopts.tone_numbers && IsDigit09(c) && !IsDigit09(next_in))
  1754. {
  1755. // allow a tone number as part of the word
  1756. }
  1757. else
  1758. {
  1759. c = ' '; // ensure we have an end-of-word terminator
  1760. space_inserted = 1;
  1761. }
  1762. }
  1763. }
  1764. if(iswdigit(prev_out))
  1765. {
  1766. if(!iswdigit(c) && (c != '.') && (c != ','))
  1767. {
  1768. c = ' '; // terminate digit string with a space
  1769. space_inserted = 1;
  1770. }
  1771. }
  1772. if((c == '[') && (next_in == '[') && option_phoneme_input)
  1773. {
  1774. phoneme_mode = FLAG_PHONEMES;
  1775. source_index++;
  1776. continue;
  1777. }
  1778. if(c == 0)
  1779. {
  1780. finished = 1;
  1781. c = ' ';
  1782. }
  1783. else
  1784. if(IsAlpha(c))
  1785. {
  1786. if(!IsAlpha(prev_out) || (langopts.ideographs && ((c > 0x3040) || (prev_out > 0x3040))))
  1787. {
  1788. if(wcschr(punct_within_word,prev_out) == 0)
  1789. letter_count = 0; // don't reset count for an apostrophy within a word
  1790. if((prev_out != ' ') && (wcschr(punct_within_word,prev_out) == 0))
  1791. {
  1792. // start of word, insert space if not one there already
  1793. c = ' ';
  1794. space_inserted = 1;
  1795. }
  1796. else
  1797. {
  1798. if(iswupper(c))
  1799. word_flags |= FLAG_FIRST_UPPER;
  1800. if((prev_out == ' ') && iswdigit(sbuf[ix-2]) && !iswdigit(prev_in))
  1801. {
  1802. // word, following a number, but with a space between
  1803. // Add an extra space, to distinguish "2 a" from "2a"
  1804. sbuf[ix++] = ' ';
  1805. words[word_count].start++;
  1806. }
  1807. }
  1808. }
  1809. letter_count++;
  1810. if(iswupper(c))
  1811. {
  1812. c = towlower(c);
  1813. if(langopts.param[LOPT_SYLLABLE_CAPS])
  1814. {
  1815. if(syllable_marked == 0)
  1816. {
  1817. char_inserted = c;
  1818. c = 0x2c8; // stress marker
  1819. syllable_marked = 1;
  1820. }
  1821. }
  1822. else
  1823. {
  1824. if(iswlower(prev_in))
  1825. {
  1826. c = ' '; // lower case followed by upper case, treat as new word
  1827. space_inserted = 1;
  1828. prev_in2 = c;
  1829. }
  1830. else
  1831. if((c != ' ') && iswupper(prev_in) && iswlower(next_in) &&
  1832. (memcmp(&source[source_index],"s ",2) != 0)) // ENGLISH specific plural
  1833. {
  1834. c = ' '; // change from upper to lower case, start new word at the last uppercase
  1835. space_inserted = 1;
  1836. prev_in2 = c;
  1837. next_word_flags |= FLAG_NOSPACE;
  1838. }
  1839. }
  1840. }
  1841. else
  1842. {
  1843. if((all_upper_case) && (letter_count > 2))
  1844. {
  1845. if((c == 's') && (next_in==' '))
  1846. {
  1847. c = ' ';
  1848. all_upper_case |= FLAG_HAS_PLURAL;
  1849. if(sbuf[ix-1] == '\'')
  1850. sbuf[ix-1] = ' ';
  1851. }
  1852. else
  1853. all_upper_case = 0; // current word contains lower case letters, not "'s"
  1854. }
  1855. else
  1856. all_upper_case = 0;
  1857. }
  1858. }
  1859. else
  1860. if(c=='-')
  1861. {
  1862. if(IsAlpha(prev_in) && IsAlpha(next_in))
  1863. {
  1864. // '-' between two letters is a hyphen, treat as a space
  1865. word_flags |= FLAG_HYPHEN;
  1866. words[word_count-1].flags |= FLAG_HYPHEN_AFTER;
  1867. c = ' ';
  1868. }
  1869. else
  1870. if((prev_in==' ') && (next_in==' '))
  1871. {
  1872. // ' - ' dash between two spaces, treat as pause
  1873. c = ' ';
  1874. pre_pause_add = 4;
  1875. }
  1876. else
  1877. if(next_in=='-')
  1878. {
  1879. // double hyphen, treat as pause
  1880. source_index++;
  1881. c = ' ';
  1882. pre_pause_add = 4;
  1883. }
  1884. else
  1885. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1886. {
  1887. // insert extra space between a word + space + hyphen, to distinguish 'a -2' from 'a-2'
  1888. sbuf[ix++] = ' ';
  1889. words[word_count].start++;
  1890. }
  1891. }
  1892. else
  1893. if(c == '\'')
  1894. {
  1895. if(iswalnum(prev_in) && IsAlpha(next_in))
  1896. {
  1897. // between two letters, consider apostrophe as part of the word
  1898. single_quoted = 0;
  1899. }
  1900. else
  1901. if((wcschr(char_plus_apostrophe,prev_in) != 0) && (prev_out2 == ' '))
  1902. {
  1903. // consider single character plus apostrophe as a word
  1904. single_quoted = 0;
  1905. if(next_in == ' ')
  1906. {
  1907. source_index++; // skip following space
  1908. }
  1909. }
  1910. else
  1911. {
  1912. if((prev_out == 's') && (single_quoted==0))
  1913. {
  1914. // looks like apostrophe after an 's'
  1915. c = ' ';
  1916. }
  1917. else
  1918. {
  1919. if(iswspace(prev_out))
  1920. single_quoted = 1;
  1921. else
  1922. single_quoted = 0;
  1923. pre_pause_add = 4; // single quote
  1924. c = ' ';
  1925. }
  1926. }
  1927. }
  1928. else
  1929. if(IsBracket(c))
  1930. {
  1931. pre_pause_add = 4;
  1932. c = ' ';
  1933. }
  1934. else
  1935. if(lookupwchar(breaks,c) != 0)
  1936. {
  1937. c = ' '; // various characters to treat as space
  1938. }
  1939. else
  1940. if(iswdigit(c))
  1941. {
  1942. if(langopts.tone_numbers && IsAlpha(prev_out) && !IsDigit(next_in))
  1943. {
  1944. }
  1945. else
  1946. if((prev_out != ' ') && !iswdigit(prev_out) && (prev_out != langopts.decimal_sep)) // TEST2
  1947. {
  1948. c = ' ';
  1949. space_inserted = 1;
  1950. }
  1951. else
  1952. if((prev_out == ' ') && IsAlpha(sbuf[ix-2]) && !IsAlpha(prev_in))
  1953. {
  1954. // insert extra space between a word and a number, to distinguish 'a 2' from 'a2'
  1955. sbuf[ix++] = ' ';
  1956. words[word_count].start++;
  1957. }
  1958. }
  1959. }
  1960. if(iswspace(c))
  1961. {
  1962. if(space_inserted)
  1963. {
  1964. source_index = prev_source_index; // rewind to the previous character
  1965. char_inserted = 0;
  1966. space_inserted = 0;
  1967. }
  1968. if(prev_out == ' ')
  1969. {
  1970. continue; // multiple spaces
  1971. }
  1972. // end of 'word'
  1973. sbuf[ix++] = ' ';
  1974. if((ix > words[word_count].start) && (word_count < N_CLAUSE_WORDS-1))
  1975. {
  1976. if(embedded_count > 0)
  1977. {
  1978. // there are embedded commands before this word
  1979. embedded_list[embedded_ix-1] |= 0x80; // terminate list of commands for this word
  1980. words[word_count].flags |= FLAG_EMBEDDED;
  1981. embedded_count = 0;
  1982. }
  1983. words[word_count].pre_pause = pre_pause;
  1984. words[word_count].flags |= (all_upper_case | word_flags | word_emphasis);
  1985. words[word_count].wmark = word_mark;
  1986. if(pre_pause > 0)
  1987. {
  1988. // insert an extra space before the word, to prevent influence from previous word across the pause
  1989. for(j=ix; j>words[word_count].start; j--)
  1990. {
  1991. sbuf[j] = sbuf[j-1];
  1992. }
  1993. sbuf[j] = ' ';
  1994. words[word_count].start++;
  1995. ix++;
  1996. }
  1997. word_count++;
  1998. words[word_count].start = ix;
  1999. words[word_count].flags = 0;
  2000. for(j=source_index; charix[j] == 0; j++);
  2001. words[word_count].sourceix = charix[j];
  2002. for(k=j; charix[k]!=0; k++);
  2003. words[word_count].length = k-j;
  2004. word_flags = next_word_flags;
  2005. next_word_flags = 0;
  2006. pre_pause = 0;
  2007. word_mark = 0;
  2008. all_upper_case = FLAG_ALL_UPPER;
  2009. syllable_marked = 0;
  2010. }
  2011. }
  2012. else
  2013. {
  2014. ix += utf8_out(c,&sbuf[ix]); // sbuf[ix++] = c;
  2015. }
  2016. if(pre_pause_add > pre_pause)
  2017. pre_pause = pre_pause_add;
  2018. pre_pause_add = 0;
  2019. }
  2020. if((word_count==0) && (embedded_count > 0))
  2021. {
  2022. // add a null 'word' to carry the embedded command flag
  2023. embedded_list[embedded_ix-1] |= 0x80;
  2024. words[word_count].flags |= FLAG_EMBEDDED;
  2025. word_count = 1;
  2026. }
  2027. clause_end = &sbuf[ix-1];
  2028. sbuf[ix] = 0;
  2029. words[0].pre_pause = 0; // don't add extra pause at beginning of clause
  2030. words[word_count].pre_pause = 8;
  2031. if(word_count > 0)
  2032. words[word_count-1].flags |= FLAG_LAST_WORD;
  2033. words[0].flags |= FLAG_FIRST_WORD;
  2034. for(ix=0; ix<word_count; ix++)
  2035. {
  2036. int j;
  2037. char *pn;
  2038. char *pw;
  2039. char number_buf[80];
  2040. // start speaking at a specified word position in the text?
  2041. count_words++;
  2042. if(skip_words > 0)
  2043. {
  2044. skip_words--;
  2045. if(skip_words == 0)
  2046. skipping_text = 0;
  2047. }
  2048. if(skipping_text)
  2049. continue;
  2050. // digits should have been converted to Latin alphabet ('0' to '9')
  2051. word = pw = &sbuf[words[ix].start];
  2052. for(n_digits=0; iswdigit(word[n_digits]); n_digits++); // count consecutive digits
  2053. if((n_digits > 4) && (word[0] != '0'))
  2054. {
  2055. // word is entirely digits, insert commas and break into 3 digit "words"
  2056. number_buf[0] = ' ';
  2057. pn = &number_buf[1];
  2058. j = n_digits;
  2059. while(pn < &number_buf[sizeof(number_buf)-3])
  2060. {
  2061. if(!isdigit(c = *pw++) && (c != langopts.decimal_sep))
  2062. break;
  2063. *pn++ = c;
  2064. if((--j > 0) && (j % 3)==0)
  2065. {
  2066. if(langopts.thousands_sep != ' ')
  2067. *pn++ = langopts.thousands_sep;
  2068. *pn++ = ' ';
  2069. }
  2070. }
  2071. pn[0] = ' ';
  2072. pn[1] = 0;
  2073. word = pw;
  2074. for(pw = &number_buf[1]; pw < pn;)
  2075. {
  2076. TranslateWord2(pw, &words[ix], words[ix].pre_pause,0 );
  2077. while(*pw++ != ' ');
  2078. words[ix].pre_pause = 0;
  2079. words[ix].flags = 0;
  2080. }
  2081. }
  2082. else
  2083. {
  2084. dict_flags = TranslateWord2(word, &words[ix], words[ix].pre_pause, words[ix+1].pre_pause);
  2085. if(dict_flags & FLAG_SKIPWORDS)
  2086. ix += dictionary_skipwords; // dictionary indicates skip next word(s)
  2087. if((dict_flags & FLAG_DOT) && (ix == word_count-1) && (terminator == CLAUSE_PERIOD))
  2088. {
  2089. // probably an abbreviation such as Mr. or B. rather than end of sentence
  2090. clause_pause = 10;
  2091. tone = 4;
  2092. }
  2093. }
  2094. }
  2095. for(ix=0; ix<2; ix++)
  2096. {
  2097. // terminate the clause with 2 PAUSE phonemes
  2098. ph_list2[n_ph_list2+ix].phcode = phonPAUSE;
  2099. ph_list2[n_ph_list2+ix].stress = 0;
  2100. ph_list2[n_ph_list2+ix].sourceix = 0;
  2101. ph_list2[n_ph_list2+ix].synthflags = 0;
  2102. }
  2103. n_ph_list2 += 2;
  2104. if(Eof() && ((word_count == 0) || (option_endpause==0)))
  2105. {
  2106. clause_pause = 10;
  2107. }
  2108. MakePhonemeList(clause_pause, new_sentence);
  2109. if(embedded_count) // ???? is this needed
  2110. {
  2111. phoneme_list[n_phoneme_list-2].synthflags = SFLAG_EMBEDDED;
  2112. embedded_list[embedded_ix-1] |= 0x80;
  2113. }
  2114. prev_clause_pause = clause_pause;
  2115. *tone_out = tone;
  2116. new_sentence = 0;
  2117. if(terminator & CLAUSE_BIT_SENTENCE)
  2118. {
  2119. new_sentence = 1; // next clause is a new sentence
  2120. }
  2121. if(voice_change != NULL)
  2122. {
  2123. // return new voice name if an embedded voice change command terminated the clause
  2124. if(terminator & CLAUSE_BIT_VOICE)
  2125. *voice_change = &source[source_index];
  2126. else
  2127. *voice_change = NULL;
  2128. }
  2129. if(Eof() || (vp_input==NULL))
  2130. return(NULL);
  2131. if(option_multibyte == espeakCHARS_WCHAR)
  2132. return((void *)p_wchar_input);
  2133. else
  2134. return((void *)p_textinput);
  2135. } // end of TranslateClause
  2136. void InitText(int control)
  2137. {//=======================
  2138. count_sentences = 0;
  2139. count_words = 0;
  2140. end_character_position = 0;
  2141. skip_sentences = 0;
  2142. skip_marker[0] = 0;
  2143. skip_words = 0;
  2144. skip_characters = 0;
  2145. skipping_text = 0;
  2146. new_sentence = 1;
  2147. ungot_char = 0;
  2148. prev_clause_pause = 0;
  2149. option_sayas = 0;
  2150. option_sayas2 = 0;
  2151. option_emphasis = 0;
  2152. word_emphasis = 0;
  2153. InitText2();
  2154. if((control & espeakKEEP_NAMEDATA) == 0)
  2155. {
  2156. InitNamedata();
  2157. }
  2158. }