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.

readclause.cpp 62KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2010 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, write 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 <math.h>
  27. #include "speak_lib.h"
  28. #include "speech.h"
  29. #include "phoneme.h"
  30. #include "synthesize.h"
  31. #include "voice.h"
  32. #include "translate.h"
  33. #ifdef PLATFORM_POSIX
  34. #include <unistd.h>
  35. #endif
  36. #include <locale.h>
  37. #define N_XML_BUF 256
  38. static const char *xmlbase = ""; // base URL from <speak>
  39. static int namedata_ix=0;
  40. static int n_namedata = 0;
  41. char *namedata = NULL;
  42. static FILE *f_input = NULL;
  43. static int ungot_char2 = 0;
  44. unsigned char *p_textinput;
  45. wchar_t *p_wchar_input;
  46. static int ungot_char;
  47. static const char *ungot_word = NULL;
  48. static int end_of_input;
  49. static int ignore_text=0; // set during <sub> ... </sub> to ignore text which has been replaced by an alias
  50. static int audio_text=0; // set during <audio> ... </audio>
  51. static int clear_skipping_text = 0; // next clause should clear the skipping_text flag
  52. int count_characters = 0;
  53. static int sayas_mode;
  54. static int sayas_start;
  55. static int ssml_ignore_l_angle = 0;
  56. // alter tone for announce punctuation or capitals
  57. //static const char *tone_punct_on = "\0016T"; // add reverberation, lower pitch
  58. //static const char *tone_punct_off = "\001T\001P";
  59. // ignore these characters
  60. static const unsigned short chars_ignore[] = {
  61. 0x200c, // zero width non-joiner
  62. 0x200d, // zero width joiner
  63. 0 };
  64. // punctuations symbols that can end a clause
  65. static const unsigned short punct_chars[] = {',','.','?','!',':',';',
  66. 0x2013, // en-dash
  67. 0x2014, // em-dash
  68. 0x2026, // elipsis
  69. 0x037e, // Greek question mark (looks like semicolon)
  70. 0x0387, // Greek semicolon, ano teleia
  71. 0x0964, // Devanagari Danda (fullstop)
  72. 0x0589, // Armenian period
  73. 0x055d, // Armenian comma
  74. 0x055c, // Armenian exclamation
  75. 0x055e, // Armenian question
  76. 0x055b, // Armenian emphasis mark
  77. 0x0b1b, // Arabic ;
  78. 0x061f, // Arabic ?
  79. 0x1362, // Ethiopic period
  80. 0x1363,
  81. 0x1364,
  82. 0x1365,
  83. 0x1366,
  84. 0x1367,
  85. 0x1368,
  86. 0x3001, // ideograph comma
  87. 0x3002, // ideograph period
  88. 0xff01, // fullwidth exclamation
  89. 0xff0c, // fullwidth comma
  90. 0xff0e, // fullwidth period
  91. 0xff1a, // fullwidth colon
  92. 0xff1b, // fullwidth semicolon
  93. 0xff1f, // fullwidth question mark
  94. 0};
  95. // indexed by (entry num. in punct_chars) + 1
  96. // bits 0-7 pause x 10mS, bits 12-14 intonation type, bit 15 don't need following space or bracket
  97. static const unsigned int punct_attributes [] = { 0,
  98. CLAUSE_COMMA, CLAUSE_PERIOD, CLAUSE_QUESTION, CLAUSE_EXCLAMATION, CLAUSE_COLON, CLAUSE_SEMICOLON,
  99. CLAUSE_SEMICOLON, // en-dash
  100. CLAUSE_SEMICOLON, // em-dash
  101. CLAUSE_SEMICOLON | PUNCT_SAY_NAME | 0x8000, // elipsis
  102. CLAUSE_QUESTION, // Greek question mark
  103. CLAUSE_SEMICOLON, // Greek semicolon
  104. CLAUSE_PERIOD | 0x8000, // Devanagari Danda (fullstop)
  105. CLAUSE_PERIOD | 0x8000, // Armenian period
  106. CLAUSE_COMMA, // Armenian comma
  107. CLAUSE_EXCLAMATION | PUNCT_IN_WORD, // Armenian exclamation
  108. CLAUSE_QUESTION | PUNCT_IN_WORD, // Armenian question
  109. CLAUSE_PERIOD | PUNCT_IN_WORD, // Armenian emphasis mark
  110. CLAUSE_SEMICOLON, // Arabic ;
  111. CLAUSE_QUESTION, // Arabic question mark
  112. CLAUSE_PERIOD, // Ethiopic period
  113. CLAUSE_COMMA, // Ethiopic comma
  114. CLAUSE_SEMICOLON, // Ethiopic semicolon
  115. CLAUSE_COLON, // Ethiopic colon
  116. CLAUSE_COLON, // Ethiopic preface colon
  117. CLAUSE_QUESTION, // Ethiopic question mark
  118. CLAUSE_PERIOD, // Ethiopic paragraph
  119. CLAUSE_COMMA+0x8000, // ideograph comma
  120. CLAUSE_PERIOD+0x8000, // ideograph period
  121. CLAUSE_EXCLAMATION+0x8000, // fullwidth
  122. CLAUSE_COMMA+0x8000,
  123. CLAUSE_PERIOD+0x8000,
  124. CLAUSE_COLON+0x8000,
  125. CLAUSE_SEMICOLON+0x8000,
  126. CLAUSE_QUESTION+0x8000,
  127. CLAUSE_SEMICOLON, // spare
  128. 0 };
  129. // stack for language and voice properties
  130. // frame 0 is for the defaults, before any ssml tags.
  131. typedef struct {
  132. int tag_type;
  133. int voice_variant;
  134. int voice_gender;
  135. int voice_age;
  136. char voice_name[40];
  137. char language[20];
  138. } SSML_STACK;
  139. #define N_SSML_STACK 20
  140. static int n_ssml_stack;
  141. static SSML_STACK ssml_stack[N_SSML_STACK];
  142. static char current_voice_id[40] = {0};
  143. #define N_PARAM_STACK 20
  144. static int n_param_stack;
  145. PARAM_STACK param_stack[N_PARAM_STACK];
  146. static int speech_parameters[N_SPEECH_PARAM]; // current values, from param_stack
  147. const int param_defaults[N_SPEECH_PARAM] = {
  148. 0, // silence (internal use)
  149. 175, // rate wpm
  150. 100, // volume
  151. 50, // pitch
  152. 50, // range
  153. 0, // punctuation
  154. 0, // capital letters
  155. 0, // wordgap
  156. 0, // options
  157. 0, // intonation
  158. 0,
  159. 0,
  160. 0, // emphasis
  161. 0, // line length
  162. 0, // voice type
  163. };
  164. #ifdef NEED_WCHAR_FUNCTIONS
  165. // additional Latin characters beyond the Latin1 character set
  166. #define MAX_WALPHA 0x233
  167. // indexed by character - 0x100
  168. // 0=not alphabetic, 0xff=lower case, other=value to add to upper case to convert to lower case
  169. static unsigned char walpha_tab[MAX_WALPHA-0xff] = {
  170. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 100
  171. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 110
  172. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 120
  173. 0xff,0xff, 1,0xff, 1,0xff, 1,0xff,0xff, 1,0xff, 1,0xff, 1,0xff, 1, // 130
  174. 0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff,0xff, 1,0xff, 1,0xff, 1,0xff, // 140
  175. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 150
  176. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 160
  177. 1,0xff, 1,0xff, 1,0xff, 1,0xff,0xff, 1,0xff, 1,0xff, 1,0xff,0xff, // 170
  178. 0xff, 210, 1,0xff, 1,0xff, 206, 1,0xff, 205, 205, 1,0xff,0xff, 79, 202, // 180
  179. 203, 1,0xff, 205, 207,0xff, 211, 209, 1,0xff,0xff,0xff, 211, 213,0xff, 214, // 190
  180. 1,0xff, 1,0xff, 1,0xff, 218, 1,0xff, 218,0xff,0xff, 1,0xff, 218, 1, // 1a0
  181. 0xff, 217, 217, 1,0xff, 1,0xff, 219, 1,0xff,0xff,0xff, 1,0xff,0xff,0xff, // 1b0
  182. 0xff,0xff,0xff,0xff, 2, 1,0xff, 2, 1,0xff, 2, 1,0xff, 1,0xff, 1, // 1c0
  183. 0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff,0xff, 1,0xff, // 1d0
  184. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 1e0
  185. 0xff, 2, 1,0xff, 1,0xff,0xff,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 1f0
  186. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 200
  187. 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 210
  188. 0xff, 0, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, 1,0xff, // 220
  189. 1,0xff, 1,0xff }; // 230
  190. // use ctype.h functions for Latin1 (character < 0x100)
  191. int iswalpha(int c)
  192. {
  193. if(c < 0x100)
  194. return(isalpha(c));
  195. if((c > 0x3040) && (c <= 0xa700))
  196. return(1); // japanese, chinese characters
  197. if(c > MAX_WALPHA)
  198. return(0);
  199. return(walpha_tab[c-0x100]);
  200. }
  201. int iswdigit(int c)
  202. {
  203. if(c < 0x100)
  204. return(isdigit(c));
  205. return(0);
  206. }
  207. int iswalnum(int c)
  208. {
  209. if(iswdigit(c))
  210. return(1);
  211. return(iswalpha(c));
  212. }
  213. int towlower(int c)
  214. {
  215. int x;
  216. if(c < 0x100)
  217. return(tolower(c));
  218. if((c > MAX_WALPHA) || ((x = walpha_tab[c-0x100])==0xff))
  219. return(c); // already lower case
  220. return(c + x); // convert to lower case
  221. }
  222. int towupper(int c)
  223. {
  224. // check whether the previous character code is the upper-case equivalent of this character
  225. if(tolower(c-1) == c)
  226. return(c-1); // yes, use it
  227. return(c); // no
  228. }
  229. int iswupper(int c)
  230. {
  231. int x;
  232. if(c < 0x100)
  233. return(isupper(c));
  234. if(((c > MAX_WALPHA) || (x = walpha_tab[c-0x100])==0) || (x == 0xff))
  235. return(0);
  236. return(1);
  237. }
  238. int iswlower(int c)
  239. {
  240. if(c < 0x100)
  241. return(islower(c));
  242. if((c > MAX_WALPHA) || (walpha_tab[c-0x100] != 0xff))
  243. return(0);
  244. return(1);
  245. }
  246. int iswspace(int c)
  247. {
  248. if(c < 0x100)
  249. return(isspace(c));
  250. return(0);
  251. }
  252. int iswpunct(int c)
  253. {
  254. if(c < 0x100)
  255. return(ispunct(c));
  256. return(0);
  257. }
  258. const wchar_t *wcschr(const wchar_t *str, int c)
  259. {
  260. while(*str != 0)
  261. {
  262. if(*str == c)
  263. return(str);
  264. str++;
  265. }
  266. return(NULL);
  267. }
  268. #ifndef WINCE
  269. // wcslen() is provided by WINCE, but not the other wchar functions
  270. const int wcslen(const wchar_t *str)
  271. {
  272. int ix=0;
  273. while(*str != 0)
  274. {
  275. ix++;
  276. }
  277. return(ix);
  278. }
  279. #endif
  280. float wcstod(const wchar_t *str, wchar_t **tailptr)
  281. {
  282. int ix;
  283. char buf[80];
  284. while(isspace(*str)) str++;
  285. for(ix=0; ix<80; ix++)
  286. {
  287. buf[ix] = str[ix];
  288. if(isspace(buf[ix]))
  289. break;
  290. }
  291. *tailptr = (wchar_t *)&str[ix];
  292. return(atof(buf));
  293. }
  294. #endif
  295. int towlower2(unsigned int c)
  296. {
  297. // check for non-standard upper to lower case conversions
  298. if(c == 'I')
  299. {
  300. if(translator->translator_name == L('t','r'))
  301. {
  302. c = 0x131; // I -> ı
  303. }
  304. }
  305. return(towlower(c));
  306. }
  307. static int IsRomanU(unsigned int c)
  308. {//================================
  309. if((c=='I') || (c=='V') || (c=='X') || (c=='L'))
  310. return(1);
  311. return(0);
  312. }
  313. static void GetC_unget(int c)
  314. {//==========================
  315. // This is only called with UTF8 input, not wchar input
  316. if(f_input != NULL)
  317. ungetc(c,f_input);
  318. else
  319. {
  320. p_textinput--;
  321. *p_textinput = c;
  322. end_of_input = 0;
  323. }
  324. }
  325. int Eof(void)
  326. {//==========
  327. if(ungot_char != 0)
  328. return(0);
  329. if(f_input != 0)
  330. return(feof(f_input));
  331. return(end_of_input);
  332. }
  333. static int GetC_get(void)
  334. {//======================
  335. unsigned int c;
  336. unsigned int c2;
  337. if(f_input != NULL)
  338. {
  339. c = fgetc(f_input);
  340. if(feof(f_input)) c = ' ';
  341. if(option_multibyte == espeakCHARS_16BIT)
  342. {
  343. c2 = fgetc(f_input);
  344. if(feof(f_input)) c2 = 0;
  345. c = c + (c2 << 8);
  346. }
  347. return(c);
  348. }
  349. if(option_multibyte == espeakCHARS_WCHAR)
  350. {
  351. if(*p_wchar_input == 0)
  352. {
  353. end_of_input = 1;
  354. return(0);
  355. }
  356. if(!end_of_input)
  357. return(*p_wchar_input++);
  358. }
  359. else
  360. {
  361. if(*p_textinput == 0)
  362. {
  363. end_of_input = 1;
  364. return(0);
  365. }
  366. if(!end_of_input)
  367. {
  368. if(option_multibyte == espeakCHARS_16BIT)
  369. {
  370. c = p_textinput[0] + (p_textinput[1] << 8);
  371. p_textinput += 2;
  372. return(c);
  373. }
  374. return(*p_textinput++ & 0xff);
  375. }
  376. }
  377. return(0);
  378. }
  379. static int GetC(void)
  380. {//==================
  381. // Returns a unicode wide character
  382. // Performs UTF8 checking and conversion
  383. int c;
  384. int c1;
  385. int c2;
  386. int cbuf[4];
  387. int ix;
  388. int n_bytes;
  389. unsigned char m;
  390. static int ungot2 = 0;
  391. static const unsigned char mask[4] = {0xff,0x1f,0x0f,0x07};
  392. static const unsigned char mask2[4] = {0,0x80,0x20,0x30};
  393. if((c1 = ungot_char) != 0)
  394. {
  395. ungot_char = 0;
  396. return(c1);
  397. }
  398. if(ungot2 != 0)
  399. {
  400. c1 = ungot2;
  401. ungot2 = 0;
  402. }
  403. else
  404. {
  405. c1 = GetC_get();
  406. }
  407. if((option_multibyte == espeakCHARS_WCHAR) || (option_multibyte == espeakCHARS_16BIT))
  408. {
  409. count_characters++;
  410. return(c1); // wchar_t text
  411. }
  412. if((option_multibyte < 2) && (c1 & 0x80))
  413. {
  414. // multi-byte utf8 encoding, convert to unicode
  415. n_bytes = 0;
  416. if(((c1 & 0xe0) == 0xc0) && ((c1 & 0x1e) != 0))
  417. n_bytes = 1;
  418. else
  419. if((c1 & 0xf0) == 0xe0)
  420. n_bytes = 2;
  421. else
  422. if(((c1 & 0xf8) == 0xf0) && ((c1 & 0x0f) <= 4))
  423. n_bytes = 3;
  424. if((ix = n_bytes) > 0)
  425. {
  426. c = c1 & mask[ix];
  427. m = mask2[ix];
  428. while(ix > 0)
  429. {
  430. if((c2 = cbuf[ix] = GetC_get()) == 0)
  431. {
  432. if(option_multibyte==espeakCHARS_AUTO)
  433. option_multibyte=espeakCHARS_8BIT; // change "auto" option to "no"
  434. GetC_unget(' ');
  435. break;
  436. }
  437. if((c2 & 0xc0) != 0x80)
  438. {
  439. // This is not UTF8. Change to 8-bit characterset.
  440. if((n_bytes == 2) && (ix == 1))
  441. ungot2 = cbuf[2];
  442. GetC_unget(c2);
  443. break;
  444. }
  445. m = 0x80;
  446. c = (c << 6) + (c2 & 0x3f);
  447. ix--;
  448. }
  449. if(ix == 0)
  450. {
  451. count_characters++;
  452. return(c);
  453. }
  454. }
  455. // top-bit-set character is not utf8, drop through to 8bit charset case
  456. if((option_multibyte==espeakCHARS_AUTO) && !Eof())
  457. option_multibyte=espeakCHARS_8BIT; // change "auto" option to "no"
  458. }
  459. // 8 bit character set, convert to unicode if
  460. count_characters++;
  461. if(c1 >= 0xa0)
  462. return(translator->charset_a0[c1-0xa0]);
  463. return(c1);
  464. } // end of GetC
  465. static void UngetC(int c)
  466. {//======================
  467. ungot_char = c;
  468. }
  469. static const char *WordToString2(unsigned int word)
  470. {//================================================
  471. // Convert a language mnemonic word into a string
  472. int ix;
  473. static char buf[5];
  474. char *p;
  475. p = buf;
  476. for(ix=3; ix>=0; ix--)
  477. {
  478. if((*p = word >> (ix*8)) != 0)
  479. p++;
  480. }
  481. *p = 0;
  482. return(buf);
  483. }
  484. static const char *LookupSpecial(Translator *tr, const char *string, char* text_out)
  485. {//=================================================================================
  486. unsigned int flags[2];
  487. char phonemes[55];
  488. char phonemes2[55];
  489. char *string1 = (char *)string;
  490. flags[0] = flags[1] = 0;
  491. if(LookupDictList(tr,&string1,phonemes,flags,0,NULL))
  492. {
  493. SetWordStress(tr, phonemes, flags, -1, 0);
  494. DecodePhonemes(phonemes,phonemes2);
  495. sprintf(text_out,"[\002%s]]",phonemes2);
  496. return(text_out);
  497. }
  498. return(NULL);
  499. }
  500. static const char *LookupCharName(Translator *tr, int c, int only)
  501. {//===============================================================
  502. // Find the phoneme string (in ascii) to speak the name of character c
  503. // Used for punctuation characters and symbols
  504. int ix;
  505. unsigned int flags[2];
  506. char single_letter[24];
  507. char phonemes[60];
  508. char phonemes2[60];
  509. const char *lang_name = NULL;
  510. char *string;
  511. static char buf[60];
  512. buf[0] = 0;
  513. flags[0] = 0;
  514. flags[1] = 0;
  515. single_letter[0] = 0;
  516. single_letter[1] = '_';
  517. ix = utf8_out(c,&single_letter[2]);
  518. single_letter[2+ix]=0;
  519. if(only)
  520. {
  521. string = &single_letter[2];
  522. LookupDictList(tr, &string, phonemes, flags, 0, NULL);
  523. }
  524. else
  525. {
  526. string = &single_letter[1];
  527. if(LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0)
  528. {
  529. // try _* then *
  530. string = &single_letter[2];
  531. if(LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0)
  532. {
  533. // now try the rules
  534. single_letter[1] = ' ';
  535. TranslateRules(tr, &single_letter[2], phonemes, sizeof(phonemes), NULL,0,NULL);
  536. }
  537. }
  538. }
  539. if((only==0) && (phonemes[0] == 0) && (tr->translator_name != L('e','n')))
  540. {
  541. // not found, try English
  542. SetTranslator2("en");
  543. string = &single_letter[1];
  544. single_letter[1] = '_';
  545. if(LookupDictList(translator2, &string, phonemes, flags, 0, NULL) == 0)
  546. {
  547. string = &single_letter[2];
  548. LookupDictList(translator2, &string, phonemes, flags, 0, NULL);
  549. }
  550. if(phonemes[0])
  551. {
  552. lang_name = "en";
  553. }
  554. else
  555. {
  556. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  557. }
  558. }
  559. if(phonemes[0])
  560. {
  561. if(lang_name)
  562. {
  563. SetWordStress(translator2, phonemes, flags, -1, 0);
  564. DecodePhonemes(phonemes,phonemes2);
  565. sprintf(buf,"[\002_^_%s %s _^_%s]]","en",phonemes2,WordToString2(tr->translator_name));
  566. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  567. }
  568. else
  569. {
  570. SetWordStress(tr, phonemes, flags, -1, 0);
  571. DecodePhonemes(phonemes,phonemes2);
  572. sprintf(buf,"[\002%s]] ",phonemes2);
  573. }
  574. }
  575. else
  576. if(only == 0)
  577. {
  578. strcpy(buf,"[\002(X1)(X1)(X1)]]");
  579. }
  580. return(buf);
  581. }
  582. int Read4Bytes(FILE *f)
  583. {//====================
  584. // Read 4 bytes (least significant first) into a word
  585. int ix;
  586. unsigned char c;
  587. int acc=0;
  588. for(ix=0; ix<4; ix++)
  589. {
  590. c = fgetc(f) & 0xff;
  591. acc += (c << (ix*8));
  592. }
  593. return(acc);
  594. }
  595. static int LoadSoundFile(const char *fname, int index)
  596. {//===================================================
  597. FILE *f;
  598. char *p;
  599. int *ip;
  600. int length;
  601. char fname_temp[100];
  602. char fname2[sizeof(path_home)+13+40];
  603. if(fname == NULL)
  604. {
  605. // filename is already in the table
  606. fname = soundicon_tab[index].filename;
  607. }
  608. if(fname==NULL)
  609. return(1);
  610. if(fname[0] != '/')
  611. {
  612. // a relative path, look in espeak-data/soundicons
  613. sprintf(fname2,"%s%csoundicons%c%s",path_home,PATHSEP,PATHSEP,fname);
  614. fname = fname2;
  615. }
  616. f = NULL;
  617. #ifdef PLATFORM_POSIX
  618. if((f = fopen(fname,"rb")) != NULL)
  619. {
  620. int ix;
  621. int fd_temp;
  622. const char *resample;
  623. int header[3];
  624. char command[sizeof(fname2)+sizeof(fname2)+40];
  625. fseek(f,20,SEEK_SET);
  626. for(ix=0; ix<3; ix++)
  627. header[ix] = Read4Bytes(f);
  628. // if the sound file is not mono, 16 bit signed, at the correct sample rate, then convert it
  629. if((header[0] != 0x10001) || (header[1] != samplerate) || (header[2] != samplerate*2))
  630. {
  631. fclose(f);
  632. f = NULL;
  633. if(header[2] == samplerate)
  634. resample = "";
  635. else
  636. resample = "polyphase";
  637. strcpy(fname_temp,"/tmp/espeakXXXXXX");
  638. if((fd_temp = mkstemp(fname_temp)) >= 0)
  639. {
  640. close(fd_temp);
  641. // sprintf(fname_temp,"%s.wav",tmpnam(NULL));
  642. sprintf(command,"sox \"%s\" -r %d -w -s -c1 %s %s\n", fname, samplerate, fname_temp, resample);
  643. if(system(command) == 0)
  644. {
  645. fname = fname_temp;
  646. }
  647. }
  648. }
  649. }
  650. #endif
  651. if(f == NULL)
  652. {
  653. f = fopen(fname,"rb");
  654. if(f == NULL)
  655. {
  656. // fprintf(stderr,"Can't read temp file: %s\n",fname);
  657. return(3);
  658. }
  659. }
  660. length = GetFileLength(fname);
  661. fseek(f,0,SEEK_SET);
  662. if((p = (char *)realloc(soundicon_tab[index].data, length)) == NULL)
  663. {
  664. fclose(f);
  665. return(4);
  666. }
  667. length = fread(p,1,length,f);
  668. fclose(f);
  669. remove(fname_temp);
  670. ip = (int *)(&p[40]);
  671. soundicon_tab[index].length = (*ip) / 2; // length in samples
  672. soundicon_tab[index].data = p;
  673. return(0);
  674. } // end of LoadSoundFile
  675. static int LookupSoundicon(int c)
  676. {//==============================
  677. // Find the sound icon number for a punctuation chatacter
  678. int ix;
  679. for(ix=N_SOUNDICON_SLOTS; ix<n_soundicon_tab; ix++)
  680. {
  681. if(soundicon_tab[ix].name == c)
  682. {
  683. if(soundicon_tab[ix].length == 0)
  684. {
  685. if(LoadSoundFile(NULL,ix)!=0)
  686. return(-1); // sound file is not available
  687. }
  688. return(ix);
  689. }
  690. }
  691. return(-1);
  692. }
  693. static int LoadSoundFile2(const char *fname)
  694. {//=========================================
  695. // Load a sound file into one of the reserved slots in the sound icon table
  696. // (if it'snot already loaded)
  697. int ix;
  698. static int slot = -1;
  699. for(ix=0; ix<n_soundicon_tab; ix++)
  700. {
  701. if(((soundicon_tab[ix].filename != NULL) && strcmp(fname, soundicon_tab[ix].filename) == 0))
  702. return(ix); // already loaded
  703. }
  704. // load the file into the next slot
  705. slot++;
  706. if(slot >= N_SOUNDICON_SLOTS)
  707. slot = 0;
  708. if(LoadSoundFile(fname, slot) != 0)
  709. return(-1);
  710. soundicon_tab[slot].filename = (char *)realloc(soundicon_tab[ix].filename, strlen(fname)+1);
  711. strcpy(soundicon_tab[slot].filename, fname);
  712. return(slot);
  713. }
  714. static int AnnouncePunctuation(Translator *tr, int c1, int *c2_ptr, char *output, int *bufix, int end_clause)
  715. {//==========================================================================================================
  716. // announce punctuation names
  717. // c1: the punctuation character
  718. // c2: the following character
  719. int punct_count;
  720. const char *punctname;
  721. int found = 0;
  722. int soundicon;
  723. int attributes;
  724. int short_pause;
  725. int c2;
  726. int len;
  727. int bufix1;
  728. char buf[200];
  729. char buf2[80];
  730. c2 = *c2_ptr;
  731. buf[0] = 0;
  732. if((soundicon = LookupSoundicon(c1)) >= 0)
  733. {
  734. // add an embedded command to play the soundicon
  735. sprintf(buf,"\001%dI ",soundicon);
  736. UngetC(c2);
  737. found = 1;
  738. }
  739. else
  740. if((punctname = LookupCharName(tr, c1, 0)) != NULL)
  741. {
  742. found = 1;
  743. if((*bufix==0) || (end_clause ==0) || (tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2))
  744. {
  745. punct_count=1;
  746. while((c2 == c1) && (c1 != '<')) // don't eat extra '<', it can miss XML tags
  747. {
  748. punct_count++;
  749. c2 = GetC();
  750. }
  751. *c2_ptr = c2;
  752. if(end_clause)
  753. {
  754. UngetC(c2);
  755. }
  756. if(punct_count==1)
  757. {
  758. // sprintf(buf,"%s %s %s",tone_punct_on,punctname,tone_punct_off);
  759. sprintf(buf,"%s",punctname);
  760. }
  761. else
  762. if(punct_count < 4)
  763. {
  764. sprintf(buf,"\001+10S");
  765. while(punct_count-- > 0)
  766. {
  767. sprintf(buf2," %s",punctname);
  768. strcat(buf, buf2);
  769. }
  770. sprintf(buf2," \001-10S");
  771. strcat(buf, buf2);
  772. }
  773. else
  774. {
  775. sprintf(buf,"%s %d %s",
  776. punctname,punct_count,punctname);
  777. }
  778. }
  779. else
  780. {
  781. // end the clause now and pick up the punctuation next time
  782. UngetC(c2);
  783. if(option_ssml)
  784. {
  785. if((c1 == '<') || (c1 == '&'))
  786. ssml_ignore_l_angle = c1; // this was &lt; which was converted to <, don't pick it up again as <
  787. }
  788. ungot_char2 = c1;
  789. buf[0] = ' ';
  790. buf[1] = 0;
  791. }
  792. }
  793. if(found == 0)
  794. return(-1);
  795. bufix1 = *bufix;
  796. len = strlen(buf);
  797. strcpy(&output[*bufix],buf);
  798. *bufix += len;
  799. if(end_clause==0)
  800. return(-1);
  801. if(c1 == '-')
  802. return(CLAUSE_NONE); // no pause
  803. attributes = punct_attributes[lookupwchar(punct_chars,c1)];
  804. short_pause = CLAUSE_SHORTFALL;
  805. if((attributes & CLAUSE_BITS_INTONATION) == 0x1000)
  806. short_pause = CLAUSE_SHORTCOMMA;
  807. if((bufix1 > 0) && !(tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2))
  808. {
  809. if((attributes & ~0x8000) == CLAUSE_SEMICOLON)
  810. return(CLAUSE_SHORTFALL);
  811. return(short_pause);
  812. }
  813. if(attributes & CLAUSE_BIT_SENTENCE)
  814. return(attributes);
  815. return(short_pause);
  816. } // end of AnnouncePunctuation
  817. #define SSML_SPEAK 1
  818. #define SSML_VOICE 2
  819. #define SSML_PROSODY 3
  820. #define SSML_SAYAS 4
  821. #define SSML_MARK 5
  822. #define SSML_SENTENCE 6
  823. #define SSML_PARAGRAPH 7
  824. #define SSML_PHONEME 8
  825. #define SSML_SUB 9
  826. #define SSML_STYLE 10
  827. #define SSML_AUDIO 11
  828. #define SSML_EMPHASIS 12
  829. #define SSML_BREAK 13
  830. #define SSML_IGNORE_TEXT 14
  831. #define HTML_BREAK 15
  832. #define HTML_NOSPACE 16 // don't insert a space for this element, so it doesn't break a word
  833. #define SSML_CLOSE 0x20 // for a closing tag, OR this with the tag type
  834. // these tags have no effect if they are self-closing, eg. <voice />
  835. static char ignore_if_self_closing[] = {0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,0,0,0};
  836. static MNEM_TAB ssmltags[] = {
  837. {"speak", SSML_SPEAK},
  838. {"voice", SSML_VOICE},
  839. {"prosody", SSML_PROSODY},
  840. {"say-as", SSML_SAYAS},
  841. {"mark", SSML_MARK},
  842. {"s", SSML_SENTENCE},
  843. {"p", SSML_PARAGRAPH},
  844. {"phoneme", SSML_PHONEME},
  845. {"sub", SSML_SUB},
  846. {"tts:style", SSML_STYLE},
  847. {"audio", SSML_AUDIO},
  848. {"emphasis", SSML_EMPHASIS},
  849. {"break", SSML_BREAK},
  850. {"metadata", SSML_IGNORE_TEXT},
  851. {"br", HTML_BREAK},
  852. {"li", HTML_BREAK},
  853. {"dd", HTML_BREAK},
  854. {"img", HTML_BREAK},
  855. {"td", HTML_BREAK},
  856. {"h1", SSML_PARAGRAPH},
  857. {"h2", SSML_PARAGRAPH},
  858. {"h3", SSML_PARAGRAPH},
  859. {"h4", SSML_PARAGRAPH},
  860. {"hr", SSML_PARAGRAPH},
  861. {"script", SSML_IGNORE_TEXT},
  862. {"style", SSML_IGNORE_TEXT},
  863. {"font", HTML_NOSPACE},
  864. {"b", HTML_NOSPACE},
  865. {"i", HTML_NOSPACE},
  866. {"strong", HTML_NOSPACE},
  867. {"em", HTML_NOSPACE},
  868. {"code", HTML_NOSPACE},
  869. {NULL,0}};
  870. static const char *VoiceFromStack()
  871. {//================================
  872. // Use the voice properties from the SSML stack to choose a voice, and switch
  873. // to that voice if it's not the current voice
  874. int ix;
  875. SSML_STACK *sp;
  876. const char *v_id;
  877. int voice_name_specified;
  878. int voice_found;
  879. espeak_VOICE voice_select;
  880. char voice_name[40];
  881. char language[40];
  882. strcpy(voice_name,ssml_stack[0].voice_name);
  883. strcpy(language,ssml_stack[0].language);
  884. voice_select.age = ssml_stack[0].voice_age;
  885. voice_select.gender = ssml_stack[0].voice_gender;
  886. voice_select.variant = ssml_stack[0].voice_variant;
  887. voice_select.identifier = NULL;
  888. for(ix=0; ix<n_ssml_stack; ix++)
  889. {
  890. sp = &ssml_stack[ix];
  891. voice_name_specified = 0;
  892. if((sp->voice_name[0] != 0) && (SelectVoiceByName(NULL,sp->voice_name) != NULL))
  893. {
  894. voice_name_specified = 1;
  895. strcpy(voice_name, sp->voice_name);
  896. language[0] = 0;
  897. voice_select.gender = 0;
  898. voice_select.age = 0;
  899. voice_select.variant = 0;
  900. }
  901. if(sp->language[0] != 0)
  902. {
  903. strcpy(language, sp->language);
  904. if(voice_name_specified == 0)
  905. voice_name[0] = 0; // forget a previous voice name if a language is specified
  906. }
  907. if(sp->voice_gender != 0)
  908. voice_select.gender = sp->voice_gender;
  909. if(sp->voice_age != 0)
  910. voice_select.age = sp->voice_age;
  911. if(sp->voice_variant != 0)
  912. voice_select.variant = sp->voice_variant;
  913. }
  914. voice_select.name = voice_name;
  915. voice_select.languages = language;
  916. v_id = SelectVoice(&voice_select, &voice_found);
  917. if(v_id == NULL)
  918. return("default");
  919. return(v_id);
  920. } // end of VoiceFromStack
  921. static void ProcessParamStack(char *outbuf, int &outix)
  922. {//====================================================
  923. // Set the speech parameters from the parameter stack
  924. int param;
  925. int ix;
  926. int value;
  927. char buf[20];
  928. int new_parameters[N_SPEECH_PARAM];
  929. static char cmd_letter[N_SPEECH_PARAM] = {0, 'S','A','P','R', 0, 'C', 0, 0, 0, 0, 0, 'F'}; // embedded command letters
  930. for(param=0; param<N_SPEECH_PARAM; param++)
  931. new_parameters[param] = -1;
  932. for(ix=0; ix<n_param_stack; ix++)
  933. {
  934. for(param=0; param<N_SPEECH_PARAM; param++)
  935. {
  936. if(param_stack[ix].parameter[param] >= 0)
  937. new_parameters[param] = param_stack[ix].parameter[param];
  938. }
  939. }
  940. for(param=0; param<N_SPEECH_PARAM; param++)
  941. {
  942. if((value = new_parameters[param]) != speech_parameters[param])
  943. {
  944. buf[0] = 0;
  945. switch(param)
  946. {
  947. case espeakPUNCTUATION:
  948. option_punctuation = value-1;
  949. break;
  950. case espeakCAPITALS:
  951. option_capitals = value;
  952. break;
  953. case espeakRATE:
  954. case espeakVOLUME:
  955. case espeakPITCH:
  956. case espeakRANGE:
  957. case espeakEMPHASIS:
  958. sprintf(buf,"%c%d%c",CTRL_EMBEDDED,value,cmd_letter[param]);
  959. break;
  960. }
  961. speech_parameters[param] = new_parameters[param];
  962. strcpy(&outbuf[outix],buf);
  963. outix += strlen(buf);
  964. }
  965. }
  966. } // end of ProcessParamStack
  967. static PARAM_STACK *PushParamStack(int tag_type)
  968. {//=============================================
  969. int ix;
  970. PARAM_STACK *sp;
  971. sp = &param_stack[n_param_stack];
  972. if(n_param_stack < (N_PARAM_STACK-1))
  973. n_param_stack++;
  974. sp->type = tag_type;
  975. for(ix=0; ix<N_SPEECH_PARAM; ix++)
  976. {
  977. sp->parameter[ix] = -1;
  978. }
  979. return(sp);
  980. } // end of PushParamStack
  981. static void PopParamStack(int tag_type, char *outbuf, int &outix)
  982. {//==============================================================
  983. // unwind the stack up to and including the previous tag of this type
  984. int ix;
  985. int top = 0;
  986. if(tag_type >= SSML_CLOSE)
  987. tag_type -= SSML_CLOSE;
  988. for(ix=0; ix<n_param_stack; ix++)
  989. {
  990. if(param_stack[ix].type == tag_type)
  991. {
  992. top = ix;
  993. }
  994. }
  995. if(top > 0)
  996. {
  997. n_param_stack = top;
  998. }
  999. ProcessParamStack(outbuf, outix);
  1000. } // end of PopParamStack
  1001. static wchar_t *GetSsmlAttribute(wchar_t *pw, const char *name)
  1002. {//============================================================
  1003. // Gets the value string for an attribute.
  1004. // Returns NULL if the attribute is not present
  1005. int ix;
  1006. static wchar_t empty[1] = {0};
  1007. while(*pw != 0)
  1008. {
  1009. if(iswspace(pw[-1]))
  1010. {
  1011. ix = 0;
  1012. while(*pw == name[ix])
  1013. {
  1014. pw++;
  1015. ix++;
  1016. }
  1017. if(name[ix]==0)
  1018. {
  1019. // found the attribute, now get the value
  1020. while(iswspace(*pw)) pw++;
  1021. if(*pw == '=') pw++;
  1022. while(iswspace(*pw)) pw++;
  1023. if(*pw == '"')
  1024. return(pw+1);
  1025. else
  1026. return(empty);
  1027. }
  1028. }
  1029. pw++;
  1030. }
  1031. return(NULL);
  1032. } // end of GetSsmlAttribute
  1033. static int attrcmp(const wchar_t *string1, const char *string2)
  1034. {//============================================================
  1035. int ix;
  1036. if(string1 == NULL)
  1037. return(1);
  1038. for(ix=0; (string1[ix] == string2[ix]) && (string1[ix] != 0); ix++)
  1039. {
  1040. }
  1041. if((string1[ix]=='"') && (string2[ix]==0))
  1042. return(0);
  1043. return(1);
  1044. }
  1045. static int attrlookup(const wchar_t *string1, const MNEM_TAB *mtab)
  1046. {//================================================================
  1047. int ix;
  1048. for(ix=0; mtab[ix].mnem != NULL; ix++)
  1049. {
  1050. if(attrcmp(string1,mtab[ix].mnem) == 0)
  1051. return(mtab[ix].value);
  1052. }
  1053. return(mtab[ix].value);
  1054. }
  1055. static int attrnumber(const wchar_t *pw, int default_value, int type)
  1056. {//==================================================================
  1057. int value = 0;
  1058. if((pw == NULL) || !isdigit(*pw))
  1059. return(default_value);
  1060. while(isdigit(*pw))
  1061. {
  1062. value = value*10 + *pw++ - '0';
  1063. }
  1064. if((type==1) && (towlower(*pw)=='s'))
  1065. {
  1066. // time: seconds rather than ms
  1067. value *= 1000;
  1068. }
  1069. return(value);
  1070. } // end of attrnumber
  1071. static int attrcopy_utf8(char *buf, const wchar_t *pw, int len)
  1072. {//============================================================
  1073. // Convert attribute string into utf8, write to buf, and return its utf8 length
  1074. unsigned int c;
  1075. int ix = 0;
  1076. int n;
  1077. int prev_c = 0;
  1078. if(pw != NULL)
  1079. {
  1080. while((ix < (len-4)) && ((c = *pw++) != 0))
  1081. {
  1082. if((c=='"') && (prev_c != '\\'))
  1083. break; // " indicates end of attribute, unless preceded by backstroke
  1084. n = utf8_out(c,&buf[ix]);
  1085. ix += n;
  1086. prev_c = c;
  1087. }
  1088. }
  1089. buf[ix] = 0;
  1090. return(ix);
  1091. } // end of attrcopy_utf8
  1092. static int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out)
  1093. {//=============================================================================
  1094. int sign = 0;
  1095. wchar_t *tail;
  1096. float value;
  1097. while(iswspace(*pw)) pw++;
  1098. if(*pw == '+')
  1099. {
  1100. pw++;
  1101. sign = 1;
  1102. }
  1103. if(*pw == '-')
  1104. {
  1105. pw++;
  1106. sign = -1;
  1107. }
  1108. value = (float)wcstod(pw,&tail);
  1109. if(tail == pw)
  1110. {
  1111. // failed to find a number, return 100%
  1112. *value_out = 100;
  1113. return(2);
  1114. }
  1115. if(*tail == '%')
  1116. {
  1117. if(sign != 0)
  1118. value = 100 + (sign * value);
  1119. *value_out = (int)value;
  1120. return(2); // percentage
  1121. }
  1122. if((tail[0]=='s') && (tail[1]=='t'))
  1123. {
  1124. double x;
  1125. // convert from semitones to a frequency percentage
  1126. x = pow(double(2.0),double((value*sign)/12)) * 100;
  1127. *value_out = (int)x;
  1128. return(2); // percentage
  1129. }
  1130. if(param_type == espeakRATE)
  1131. {
  1132. *value_out = (int)(value * 100);
  1133. return(2); // percentage
  1134. }
  1135. *value_out = (int)value;
  1136. return(sign); // -1, 0, or 1
  1137. } // end of attr_prosody_value
  1138. int AddNameData(const char *name, int wide)
  1139. {//========================================
  1140. // Add the name to the namedata and return its position
  1141. // (Used by the Windows SAPI wrapper)
  1142. int ix;
  1143. int len;
  1144. void *vp;
  1145. if(wide)
  1146. {
  1147. len = (wcslen((const wchar_t *)name)+1)*sizeof(wchar_t);
  1148. n_namedata = (n_namedata + sizeof(wchar_t) - 1) % sizeof(wchar_t); // round to wchar_t boundary
  1149. }
  1150. else
  1151. {
  1152. len = strlen(name)+1;
  1153. }
  1154. if(namedata_ix+len >= n_namedata)
  1155. {
  1156. // allocate more space for marker names
  1157. if((vp = realloc(namedata, namedata_ix+len + 300)) == NULL)
  1158. return(-1); // failed to allocate, original data is unchanged but ignore this new name
  1159. namedata = (char *)vp;
  1160. n_namedata = namedata_ix+len + 300;
  1161. }
  1162. memcpy(&namedata[ix = namedata_ix],name,len);
  1163. namedata_ix += len;
  1164. return(ix);
  1165. } // end of AddNameData
  1166. void SetVoiceStack(espeak_VOICE *v)
  1167. {//================================
  1168. SSML_STACK *sp;
  1169. sp = &ssml_stack[0];
  1170. if(v == NULL)
  1171. {
  1172. memset(sp,0,sizeof(ssml_stack[0]));
  1173. return;
  1174. }
  1175. if(v->languages != NULL)
  1176. strcpy(sp->language,v->languages);
  1177. if(v->name != NULL)
  1178. strcpy(sp->voice_name,v->name);
  1179. sp->voice_variant = v->variant;
  1180. sp->voice_age = v->age;
  1181. sp->voice_gender = v->gender;
  1182. }
  1183. static int GetVoiceAttributes(wchar_t *pw, int tag_type)
  1184. {//=====================================================
  1185. // Determines whether voice attribute are specified in this tag, and if so, whether this means
  1186. // a voice change.
  1187. // If it's a closing tag, delete the top frame of the stack and determine whether this implies
  1188. // a voice change.
  1189. // Returns CLAUSE_BIT_VOICE if there is a voice change
  1190. wchar_t *lang;
  1191. wchar_t *gender;
  1192. wchar_t *name;
  1193. wchar_t *age;
  1194. wchar_t *variant;
  1195. const char *new_voice_id;
  1196. SSML_STACK *ssml_sp;
  1197. static const MNEM_TAB mnem_gender[] = {
  1198. {"male", 1},
  1199. {"female", 2},
  1200. {"neutral", 3},
  1201. {NULL, 0}};
  1202. if(tag_type & SSML_CLOSE)
  1203. {
  1204. // delete a stack frame
  1205. if(n_ssml_stack > 1)
  1206. {
  1207. n_ssml_stack--;
  1208. }
  1209. }
  1210. else
  1211. {
  1212. // add a stack frame if any voice details are specified
  1213. lang = GetSsmlAttribute(pw,"xml:lang");
  1214. if(tag_type != SSML_VOICE)
  1215. {
  1216. // only expect an xml:lang attribute
  1217. name = NULL;
  1218. variant = NULL;
  1219. age = NULL;
  1220. gender = NULL;
  1221. }
  1222. else
  1223. {
  1224. name = GetSsmlAttribute(pw,"name");
  1225. variant = GetSsmlAttribute(pw,"variant");
  1226. age = GetSsmlAttribute(pw,"age");
  1227. gender = GetSsmlAttribute(pw,"gender");
  1228. }
  1229. if((tag_type != SSML_VOICE) && (lang==NULL))
  1230. return(0); // <s> or <p> without language spec, nothing to do
  1231. ssml_sp = &ssml_stack[n_ssml_stack++];
  1232. attrcopy_utf8(ssml_sp->language,lang,sizeof(ssml_sp->language));
  1233. attrcopy_utf8(ssml_sp->voice_name,name,sizeof(ssml_sp->voice_name));
  1234. ssml_sp->voice_variant = attrnumber(variant,1,0)-1;
  1235. ssml_sp->voice_age = attrnumber(age,0,0);
  1236. ssml_sp->voice_gender = attrlookup(gender,mnem_gender);
  1237. ssml_sp->tag_type = tag_type;
  1238. }
  1239. new_voice_id = VoiceFromStack();
  1240. if(strcmp(new_voice_id,current_voice_id) != 0)
  1241. {
  1242. // add an embedded command to change the voice
  1243. strcpy(current_voice_id,new_voice_id);
  1244. return(CLAUSE_BIT_VOICE); // change of voice
  1245. }
  1246. return(0);
  1247. } // end of GetVoiceAttributes
  1248. static void SetProsodyParameter(int param_type, wchar_t *attr1, PARAM_STACK *sp)
  1249. {//=============================================================================
  1250. int value;
  1251. int sign;
  1252. static const MNEM_TAB mnem_volume[] = {
  1253. {"default",100},
  1254. {"silent",0},
  1255. {"x-soft",30},
  1256. {"soft",65},
  1257. {"medium",100},
  1258. {"loud",150},
  1259. {"x-loud",230},
  1260. {NULL, -1}};
  1261. static const MNEM_TAB mnem_rate[] = {
  1262. {"default",100},
  1263. {"x-slow",60},
  1264. {"slow",80},
  1265. {"medium",100},
  1266. {"fast",125},
  1267. {"x-fast",160},
  1268. {NULL, -1}};
  1269. static const MNEM_TAB mnem_pitch[] = {
  1270. {"default",100},
  1271. {"x-low",70},
  1272. {"low",85},
  1273. {"medium",100},
  1274. {"high",110},
  1275. {"x-high",120},
  1276. {NULL, -1}};
  1277. static const MNEM_TAB mnem_range[] = {
  1278. {"default",100},
  1279. {"x-low",20},
  1280. {"low",50},
  1281. {"medium",100},
  1282. {"high",140},
  1283. {"x-high",180},
  1284. {NULL, -1}};
  1285. static const MNEM_TAB *mnem_tabs[5] = {
  1286. NULL, mnem_rate, mnem_volume, mnem_pitch, mnem_range };
  1287. if((value = attrlookup(attr1,mnem_tabs[param_type])) >= 0)
  1288. {
  1289. // mnemonic specifies a value as a percentage of the base pitch/range/rate/volume
  1290. sp->parameter[param_type] = (param_stack[0].parameter[param_type] * value)/100;
  1291. }
  1292. else
  1293. {
  1294. sign = attr_prosody_value(param_type,attr1,&value);
  1295. if(sign == 0)
  1296. sp->parameter[param_type] = value; // absolute value in Hz
  1297. else
  1298. if(sign == 2)
  1299. {
  1300. // change specified as percentage or in semitones
  1301. sp->parameter[param_type] = (speech_parameters[param_type] * value)/100;
  1302. }
  1303. else
  1304. {
  1305. // change specified as plus or minus Hz
  1306. sp->parameter[param_type] = speech_parameters[param_type] + (value*sign);
  1307. }
  1308. }
  1309. } // end of SetProsodyParemeter
  1310. static int ReplaceKeyName(char *outbuf, int index, int &outix)
  1311. {//===========================================================
  1312. // Replace some key-names by single characters, so they can be pronounced in different languages
  1313. MNEM_TAB keynames[] = {
  1314. {"space ",0xe020},
  1315. {"tab ", 0xe009},
  1316. {"underscore ", 0xe05f},
  1317. {"double-quote ", '"'},
  1318. {NULL, 0}};
  1319. int ix;
  1320. int letter;
  1321. char *p;
  1322. p = &outbuf[index];
  1323. if((letter = LookupMnem(keynames, p)) != 0)
  1324. {
  1325. ix = utf8_out(letter, p);
  1326. outix = index + ix;
  1327. return(letter);
  1328. }
  1329. return(0);
  1330. }
  1331. static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int &outix, int n_outbuf, int self_closing)
  1332. {//==================================================================================================
  1333. // xml_buf is the tag and attributes with a zero terminator in place of the original '>'
  1334. // returns a clause terminator value.
  1335. unsigned int ix;
  1336. int index;
  1337. int c;
  1338. int tag_type;
  1339. int value;
  1340. int value2;
  1341. int value3;
  1342. int voice_change_flag;
  1343. wchar_t *px;
  1344. wchar_t *attr1;
  1345. wchar_t *attr2;
  1346. wchar_t *attr3;
  1347. int terminator;
  1348. char *uri;
  1349. int param_type;
  1350. char tag_name[40];
  1351. char buf[80];
  1352. PARAM_STACK *sp;
  1353. SSML_STACK *ssml_sp;
  1354. static const MNEM_TAB mnem_punct[] = {
  1355. {"none", 1},
  1356. {"all", 2},
  1357. {"some", 3},
  1358. {NULL, -1}};
  1359. static const MNEM_TAB mnem_capitals[] = {
  1360. {"no", 0},
  1361. {"spelling", 2},
  1362. {"icon", 1},
  1363. {"pitch", 20}, // this is the amount by which to raise the pitch
  1364. {NULL, -1}};
  1365. static const MNEM_TAB mnem_interpret_as[] = {
  1366. {"characters",SAYAS_CHARS},
  1367. {"tts:char",SAYAS_SINGLE_CHARS},
  1368. {"tts:key",SAYAS_KEY},
  1369. {"tts:digits",SAYAS_DIGITS},
  1370. {"telephone",SAYAS_DIGITS1},
  1371. {NULL, -1}};
  1372. static const MNEM_TAB mnem_sayas_format[] = {
  1373. {"glyphs",1},
  1374. {NULL, -1}};
  1375. static const MNEM_TAB mnem_break[] = {
  1376. {"none",0},
  1377. {"x-weak",1},
  1378. {"weak",2},
  1379. {"medium",3},
  1380. {"strong",4},
  1381. {"x-strong",5},
  1382. {NULL,-1}};
  1383. static const MNEM_TAB mnem_emphasis[] = {
  1384. {"none",1},
  1385. {"reduced",2},
  1386. {"moderate",3},
  1387. {"strong",4},
  1388. {NULL,-1}};
  1389. static const char *prosody_attr[5] = {
  1390. NULL, "rate", "volume", "pitch", "range" };
  1391. for(ix=0; ix<(sizeof(tag_name)-1); ix++)
  1392. {
  1393. if(((c = xml_buf[ix]) == 0) || iswspace(c))
  1394. break;
  1395. tag_name[ix] = tolower((char)c);
  1396. }
  1397. tag_name[ix] = 0;
  1398. px = &xml_buf[ix]; // the tag's attributes
  1399. if(tag_name[0] == '/')
  1400. {
  1401. // closing tag
  1402. if((tag_type = LookupMnem(ssmltags,&tag_name[1])) != HTML_NOSPACE)
  1403. {
  1404. outbuf[outix++] = ' ';
  1405. }
  1406. tag_type += SSML_CLOSE;
  1407. }
  1408. else
  1409. {
  1410. if((tag_type = LookupMnem(ssmltags,tag_name)) != HTML_NOSPACE)
  1411. {
  1412. // separate SSML tags from the previous word (but not HMTL tags such as <b> <font> which can occur inside a word)
  1413. outbuf[outix++] = ' ';
  1414. }
  1415. if(self_closing && ignore_if_self_closing[tag_type])
  1416. return(0);
  1417. }
  1418. voice_change_flag = 0;
  1419. terminator = CLAUSE_NONE;
  1420. ssml_sp = &ssml_stack[n_ssml_stack-1];
  1421. switch(tag_type)
  1422. {
  1423. case SSML_STYLE:
  1424. sp = PushParamStack(tag_type);
  1425. attr1 = GetSsmlAttribute(px,"field");
  1426. attr2 = GetSsmlAttribute(px,"mode");
  1427. if(attrcmp(attr1,"punctuation")==0)
  1428. {
  1429. value = attrlookup(attr2,mnem_punct);
  1430. sp->parameter[espeakPUNCTUATION] = value;
  1431. }
  1432. else
  1433. if(attrcmp(attr1,"capital_letters")==0)
  1434. {
  1435. value = attrlookup(attr2,mnem_capitals);
  1436. sp->parameter[espeakCAPITALS] = value;
  1437. }
  1438. ProcessParamStack(outbuf, outix);
  1439. break;
  1440. case SSML_PROSODY:
  1441. sp = PushParamStack(tag_type);
  1442. // look for attributes: rate, volume, pitch, range
  1443. for(param_type=espeakRATE; param_type <= espeakRANGE; param_type++)
  1444. {
  1445. if((attr1 = GetSsmlAttribute(px,prosody_attr[param_type])) != NULL)
  1446. {
  1447. SetProsodyParameter(param_type, attr1, sp);
  1448. }
  1449. }
  1450. ProcessParamStack(outbuf, outix);
  1451. break;
  1452. case SSML_EMPHASIS:
  1453. sp = PushParamStack(tag_type);
  1454. value = 3; // default is "moderate"
  1455. if((attr1 = GetSsmlAttribute(px,"level")) != NULL)
  1456. {
  1457. value = attrlookup(attr1,mnem_emphasis);
  1458. }
  1459. if(translator->langopts.tone_language == 1)
  1460. {
  1461. static unsigned char emphasis_to_pitch_range[] = {50,50,40,70,90,90};
  1462. static unsigned char emphasis_to_volume[] = {100,100,70,110,140,140};
  1463. // tone language (eg.Chinese) do emphasis by increasing the pitch range.
  1464. sp->parameter[espeakRANGE] = emphasis_to_pitch_range[value];
  1465. sp->parameter[espeakVOLUME] = emphasis_to_volume[value];
  1466. }
  1467. else
  1468. {
  1469. sp->parameter[espeakEMPHASIS] = value;
  1470. }
  1471. ProcessParamStack(outbuf, outix);
  1472. break;
  1473. case SSML_STYLE + SSML_CLOSE:
  1474. case SSML_PROSODY + SSML_CLOSE:
  1475. case SSML_EMPHASIS + SSML_CLOSE:
  1476. PopParamStack(tag_type, outbuf, outix);
  1477. break;
  1478. case SSML_SAYAS:
  1479. attr1 = GetSsmlAttribute(px,"interpret-as");
  1480. attr2 = GetSsmlAttribute(px,"format");
  1481. attr3 = GetSsmlAttribute(px,"detail");
  1482. value = attrlookup(attr1,mnem_interpret_as);
  1483. value2 = attrlookup(attr2,mnem_sayas_format);
  1484. if(value2 == 1)
  1485. value = SAYAS_GLYPHS;
  1486. value3 = attrnumber(attr3,0,0);
  1487. if(value == SAYAS_DIGITS)
  1488. {
  1489. if(value3 <= 1)
  1490. value = SAYAS_DIGITS1;
  1491. else
  1492. value = SAYAS_DIGITS + value3;
  1493. }
  1494. sprintf(buf,"%c%dY",CTRL_EMBEDDED,value);
  1495. strcpy(&outbuf[outix],buf);
  1496. outix += strlen(buf);
  1497. sayas_start = outix;
  1498. sayas_mode = value; // punctuation doesn't end clause during SAY-AS
  1499. break;
  1500. case SSML_SAYAS + SSML_CLOSE:
  1501. if(sayas_mode == SAYAS_KEY)
  1502. {
  1503. outbuf[outix] = 0;
  1504. ReplaceKeyName(outbuf, sayas_start, outix);
  1505. }
  1506. outbuf[outix++] = CTRL_EMBEDDED;
  1507. outbuf[outix++] = 'Y';
  1508. sayas_mode = 0;
  1509. break;
  1510. case SSML_SUB:
  1511. if((attr1 = GetSsmlAttribute(px,"alias")) != NULL)
  1512. {
  1513. // use the alias rather than the text
  1514. ignore_text = 1;
  1515. outix += attrcopy_utf8(&outbuf[outix],attr1,n_outbuf-outix);
  1516. }
  1517. break;
  1518. case SSML_IGNORE_TEXT:
  1519. ignore_text = 1;
  1520. break;
  1521. case SSML_SUB + SSML_CLOSE:
  1522. case SSML_IGNORE_TEXT + SSML_CLOSE:
  1523. ignore_text = 0;
  1524. break;
  1525. case SSML_MARK:
  1526. if((attr1 = GetSsmlAttribute(px,"name")) != NULL)
  1527. {
  1528. // add name to circular buffer of marker names
  1529. attrcopy_utf8(buf,attr1,sizeof(buf));
  1530. if(strcmp(skip_marker,buf)==0)
  1531. {
  1532. // This is the marker we are waiting for before starting to speak
  1533. clear_skipping_text = 1;
  1534. skip_marker[0] = 0;
  1535. return(CLAUSE_NONE);
  1536. }
  1537. if((index = AddNameData(buf,0)) >= 0)
  1538. {
  1539. sprintf(buf,"%c%dM",CTRL_EMBEDDED,index);
  1540. strcpy(&outbuf[outix],buf);
  1541. outix += strlen(buf);
  1542. }
  1543. }
  1544. break;
  1545. case SSML_AUDIO:
  1546. sp = PushParamStack(tag_type);
  1547. if((attr1 = GetSsmlAttribute(px,"src")) != NULL)
  1548. {
  1549. char fname[256];
  1550. attrcopy_utf8(buf,attr1,sizeof(buf));
  1551. if(uri_callback == NULL)
  1552. {
  1553. if((xmlbase != NULL) && (buf[0] != '/'))
  1554. {
  1555. sprintf(fname,"%s/%s",xmlbase,buf);
  1556. index = LoadSoundFile2(fname);
  1557. }
  1558. else
  1559. {
  1560. index = LoadSoundFile2(buf);
  1561. }
  1562. if(index >= 0)
  1563. {
  1564. sprintf(buf,"%c%dI",CTRL_EMBEDDED,index);
  1565. strcpy(&outbuf[outix],buf);
  1566. outix += strlen(buf);
  1567. sp->parameter[espeakSILENCE] = 1;
  1568. }
  1569. }
  1570. else
  1571. {
  1572. if((index = AddNameData(buf,0)) >= 0)
  1573. {
  1574. uri = &namedata[index];
  1575. if(uri_callback(1,uri,xmlbase) == 0)
  1576. {
  1577. sprintf(buf,"%c%dU",CTRL_EMBEDDED,index);
  1578. strcpy(&outbuf[outix],buf);
  1579. outix += strlen(buf);
  1580. sp->parameter[espeakSILENCE] = 1;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. ProcessParamStack(outbuf, outix);
  1586. if(self_closing)
  1587. PopParamStack(tag_type, outbuf, outix);
  1588. else
  1589. audio_text = 1;
  1590. return(CLAUSE_NONE);
  1591. case SSML_AUDIO + SSML_CLOSE:
  1592. PopParamStack(tag_type, outbuf, outix);
  1593. audio_text = 0;
  1594. return(CLAUSE_NONE);
  1595. case SSML_BREAK:
  1596. value = 21;
  1597. terminator = CLAUSE_NONE;
  1598. if((attr1 = GetSsmlAttribute(px,"strength")) != NULL)
  1599. {
  1600. static int break_value[6] = {0,7,14,21,40,80}; // *10mS
  1601. value = attrlookup(attr1,mnem_break);
  1602. if(value < 3)
  1603. {
  1604. // adjust prepause on the following word
  1605. sprintf(&outbuf[outix],"%c%dB",CTRL_EMBEDDED,value);
  1606. outix += 3;
  1607. terminator = 0;
  1608. }
  1609. value = break_value[value];
  1610. }
  1611. if((attr2 = GetSsmlAttribute(px,"time")) != NULL)
  1612. {
  1613. value = (attrnumber(attr2,0,1) * 25) / speed.pause_factor; // compensate for speaking speed to keep constant pause length
  1614. if(terminator == 0)
  1615. terminator = CLAUSE_NONE;
  1616. }
  1617. if(terminator)
  1618. {
  1619. if(value > 0xfff)
  1620. value = 0xfff;
  1621. return(terminator + value);
  1622. }
  1623. break;
  1624. case SSML_SPEAK:
  1625. if((attr1 = GetSsmlAttribute(px,"xml:base")) != NULL)
  1626. {
  1627. attrcopy_utf8(buf,attr1,sizeof(buf));
  1628. if((index = AddNameData(buf,0)) >= 0)
  1629. {
  1630. xmlbase = &namedata[index];
  1631. }
  1632. }
  1633. if(GetVoiceAttributes(px, tag_type) == 0)
  1634. return(0); // no voice change
  1635. return(CLAUSE_VOICE);
  1636. case SSML_VOICE:
  1637. if(GetVoiceAttributes(px, tag_type) == 0)
  1638. return(0); // no voice change
  1639. return(CLAUSE_VOICE);
  1640. case SSML_SPEAK + SSML_CLOSE:
  1641. // unwind stack until the previous <voice> or <speak> tag
  1642. while((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_SPEAK))
  1643. {
  1644. n_ssml_stack--;
  1645. }
  1646. return(CLAUSE_PERIOD + GetVoiceAttributes(px, tag_type));
  1647. case SSML_VOICE + SSML_CLOSE:
  1648. // unwind stack until the previous <voice> or <speak> tag
  1649. while((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_VOICE))
  1650. {
  1651. n_ssml_stack--;
  1652. }
  1653. terminator=0; // ?? Sentence intonation, but no pause ??
  1654. return(terminator + GetVoiceAttributes(px, tag_type));
  1655. case HTML_BREAK:
  1656. case HTML_BREAK + SSML_CLOSE:
  1657. return(CLAUSE_COLON);
  1658. case SSML_SENTENCE:
  1659. if(ssml_sp->tag_type == SSML_SENTENCE)
  1660. {
  1661. // new sentence implies end-of-sentence
  1662. voice_change_flag = GetVoiceAttributes(px, SSML_SENTENCE+SSML_CLOSE);
  1663. }
  1664. voice_change_flag |= GetVoiceAttributes(px, tag_type);
  1665. return(CLAUSE_PARAGRAPH + voice_change_flag);
  1666. case SSML_PARAGRAPH:
  1667. if(ssml_sp->tag_type == SSML_SENTENCE)
  1668. {
  1669. // new paragraph implies end-of-sentence or end-of-paragraph
  1670. voice_change_flag = GetVoiceAttributes(px, SSML_SENTENCE+SSML_CLOSE);
  1671. }
  1672. if(ssml_sp->tag_type == SSML_PARAGRAPH)
  1673. {
  1674. // new paragraph implies end-of-sentence or end-of-paragraph
  1675. voice_change_flag |= GetVoiceAttributes(px, SSML_PARAGRAPH+SSML_CLOSE);
  1676. }
  1677. voice_change_flag |= GetVoiceAttributes(px, tag_type);
  1678. return(CLAUSE_PARAGRAPH + voice_change_flag);
  1679. case SSML_SENTENCE + SSML_CLOSE:
  1680. if(ssml_sp->tag_type == SSML_SENTENCE)
  1681. {
  1682. // end of a sentence which specified a language
  1683. voice_change_flag = GetVoiceAttributes(px, tag_type);
  1684. }
  1685. return(CLAUSE_PERIOD + voice_change_flag);
  1686. case SSML_PARAGRAPH + SSML_CLOSE:
  1687. if((ssml_sp->tag_type == SSML_SENTENCE) || (ssml_sp->tag_type == SSML_PARAGRAPH))
  1688. {
  1689. // End of a paragraph which specified a language.
  1690. // (End-of-paragraph also implies end-of-sentence)
  1691. return(GetVoiceAttributes(px, tag_type) + CLAUSE_PARAGRAPH);
  1692. }
  1693. return(CLAUSE_PARAGRAPH);
  1694. }
  1695. return(0);
  1696. } // end of ProcessSsmlTag
  1697. static MNEM_TAB xml_char_mnemonics[] = {
  1698. {"gt",'>'},
  1699. {"lt", 0xe000 + '<'}, // private usage area, to avoid confusion with XML tag
  1700. {"amp", '&'},
  1701. {"quot", '"'},
  1702. {"nbsp", ' '},
  1703. {"apos", '\''},
  1704. {NULL,-1}};
  1705. int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix_top, int n_buf, int *tone_type, char *voice_change)
  1706. {//=================================================================================================================================
  1707. /* Find the end of the current clause.
  1708. Write the clause into buf
  1709. returns: clause type (bits 0-7: pause x10mS, bits 8-11 intonation type)
  1710. Also checks for blank line (paragraph) as end-of-clause indicator.
  1711. Does not end clause for:
  1712. punctuation immediately followed by alphanumeric eg. 1.23 !Speak :path
  1713. repeated punctuation, eg. ... !!!
  1714. */
  1715. int c1=' '; // current character
  1716. int c2; // next character
  1717. int cprev=' '; // previous character
  1718. int cprev2=' ';
  1719. int c_next;
  1720. int parag;
  1721. int ix = 0;
  1722. int j;
  1723. int nl_count;
  1724. int linelength = 0;
  1725. int phoneme_mode = 0;
  1726. int n_xml_buf;
  1727. int terminator;
  1728. int punct;
  1729. int found;
  1730. int any_alnum = 0;
  1731. int self_closing;
  1732. int punct_data = 0;
  1733. int is_end_clause;
  1734. int announced_punctuation = 0;
  1735. int prev_announced_punctuation;
  1736. int stressed_word = 0;
  1737. int end_clause_after_tag = 0;
  1738. int end_clause_index = 0;
  1739. wchar_t xml_buf[N_XML_BUF+1];
  1740. #define N_XML_BUF2 20
  1741. char xml_buf2[N_XML_BUF2+2]; // for &<name> and &<number> sequences
  1742. static char ungot_string[N_XML_BUF2+4];
  1743. static int ungot_string_ix = -1;
  1744. if(clear_skipping_text)
  1745. {
  1746. skipping_text = 0;
  1747. clear_skipping_text = 0;
  1748. }
  1749. tr->phonemes_repeat_count = 0;
  1750. tr->clause_upper_count = 0;
  1751. tr->clause_lower_count = 0;
  1752. end_of_input = 0;
  1753. *tone_type = 0;
  1754. *voice_change = 0;
  1755. f_input = f_in; // for GetC etc
  1756. if(ungot_word != NULL)
  1757. {
  1758. strcpy(buf,ungot_word);
  1759. ix += strlen(ungot_word);
  1760. ungot_word = NULL;
  1761. }
  1762. if(ungot_char2 != 0)
  1763. {
  1764. c2 = ungot_char2;
  1765. }
  1766. else
  1767. {
  1768. c2 = GetC();
  1769. }
  1770. while(!Eof() || (ungot_char != 0) || (ungot_char2 != 0) || (ungot_string_ix >= 0))
  1771. {
  1772. if(!iswalnum(c1))
  1773. {
  1774. if((end_character_position > 0) && (count_characters > end_character_position))
  1775. {
  1776. end_of_input = 1;
  1777. return(CLAUSE_EOF);
  1778. }
  1779. if((skip_characters > 0) && (count_characters > skip_characters))
  1780. {
  1781. // reached the specified start position
  1782. // don't break a word
  1783. clear_skipping_text = 1;
  1784. skip_characters = 0;
  1785. UngetC(c2);
  1786. return(CLAUSE_NONE);
  1787. }
  1788. }
  1789. cprev2 = cprev;
  1790. cprev = c1;
  1791. c1 = c2;
  1792. if(ungot_string_ix >= 0)
  1793. {
  1794. if(ungot_string[ungot_string_ix] == 0)
  1795. ungot_string_ix = -1;
  1796. }
  1797. if((ungot_string_ix == 0) && (ungot_char2 == 0))
  1798. {
  1799. c1 = ungot_string[ungot_string_ix++];
  1800. }
  1801. if(ungot_string_ix >= 0)
  1802. {
  1803. c2 = ungot_string[ungot_string_ix++];
  1804. }
  1805. else
  1806. {
  1807. c2 = GetC();
  1808. if(Eof())
  1809. {
  1810. c2 = ' ';
  1811. }
  1812. }
  1813. ungot_char2 = 0;
  1814. if((option_ssml) && (phoneme_mode==0))
  1815. {
  1816. if((ssml_ignore_l_angle != '&') && (c1 == '&') && ((c2=='#') || ((c2 >= 'a') && (c2 <= 'z'))))
  1817. {
  1818. n_xml_buf = 0;
  1819. c1 = c2;
  1820. while(!Eof() && (iswalnum(c1) || (c1=='#')) && (n_xml_buf < N_XML_BUF2))
  1821. {
  1822. xml_buf2[n_xml_buf++] = c1;
  1823. c1 = GetC();
  1824. }
  1825. xml_buf2[n_xml_buf] = 0;
  1826. c2 = GetC();
  1827. sprintf(ungot_string,"%s%c%c",&xml_buf2[0],c1,c2);
  1828. if(c1 == ';')
  1829. {
  1830. if(xml_buf2[0] == '#')
  1831. {
  1832. // character code number
  1833. if(xml_buf2[1] == 'x')
  1834. found = sscanf(&xml_buf2[2],"%x",(unsigned int *)(&c1));
  1835. else
  1836. found = sscanf(&xml_buf2[1],"%d",&c1);
  1837. }
  1838. else
  1839. {
  1840. if((found = LookupMnem(xml_char_mnemonics,xml_buf2)) != -1)
  1841. {
  1842. c1 = found;
  1843. if(c2 == 0)
  1844. c2 = ' ';
  1845. }
  1846. }
  1847. }
  1848. else
  1849. {
  1850. found = -1;
  1851. }
  1852. if(found <= 0)
  1853. {
  1854. ungot_string_ix = 0;
  1855. c1 = '&';
  1856. c2 = ' ';
  1857. }
  1858. if((c1 <= 0x20) && ((sayas_mode == SAYAS_SINGLE_CHARS) || (sayas_mode == SAYAS_KEY)))
  1859. {
  1860. c1 += 0xe000; // move into unicode private usage area
  1861. }
  1862. }
  1863. else
  1864. if((c1 == '<') && (ssml_ignore_l_angle != '<'))
  1865. {
  1866. if(c2 == '!')
  1867. {
  1868. // a comment, ignore until closing '<'
  1869. while(!Eof() && (c1 != '>'))
  1870. {
  1871. c1 = GetC();
  1872. }
  1873. c2 = ' ';
  1874. }
  1875. else
  1876. if((c2 == '/') || iswalpha(c2))
  1877. {
  1878. // SSML Tag
  1879. n_xml_buf = 0;
  1880. c1 = c2;
  1881. while(!Eof() && (c1 != '>') && (n_xml_buf < N_XML_BUF))
  1882. {
  1883. xml_buf[n_xml_buf++] = c1;
  1884. c1 = GetC();
  1885. }
  1886. xml_buf[n_xml_buf] = 0;
  1887. c2 = ' ';
  1888. self_closing = 0;
  1889. if(xml_buf[n_xml_buf-1] == '/')
  1890. {
  1891. // a self-closing tag
  1892. xml_buf[n_xml_buf-1] = ' ';
  1893. self_closing = 1;
  1894. }
  1895. terminator = ProcessSsmlTag(xml_buf,buf,ix,n_buf,self_closing);
  1896. if(terminator != 0)
  1897. {
  1898. if(end_clause_after_tag)
  1899. ix = end_clause_index;
  1900. buf[ix] = ' ';
  1901. buf[ix++] = 0;
  1902. if(terminator & CLAUSE_BIT_VOICE)
  1903. {
  1904. strcpy(voice_change, current_voice_id);
  1905. }
  1906. return(terminator);
  1907. }
  1908. c1 = ' ';
  1909. c2 = GetC();
  1910. continue;
  1911. }
  1912. }
  1913. }
  1914. ssml_ignore_l_angle=0;
  1915. if(ignore_text)
  1916. continue;
  1917. if((c2=='\n') && (option_linelength == -1))
  1918. {
  1919. // single-line mode, return immediately on NL
  1920. if((punct = lookupwchar(punct_chars,c1)) == 0)
  1921. {
  1922. charix[ix] = count_characters - clause_start_char;
  1923. *charix_top = ix;
  1924. ix += utf8_out(c1,&buf[ix]);
  1925. terminator = CLAUSE_PERIOD; // line doesn't end in punctuation, assume period
  1926. }
  1927. else
  1928. {
  1929. terminator = punct_attributes[punct];
  1930. }
  1931. buf[ix] = ' ';
  1932. buf[ix+1] = 0;
  1933. return(terminator);
  1934. }
  1935. if((c1 == CTRL_EMBEDDED) || (c1 == ctrl_embedded))
  1936. {
  1937. // an embedded command. If it's a voice change, end the clause
  1938. if(c2 == 'V')
  1939. {
  1940. buf[ix++] = 0; // end the clause at this point
  1941. while(!iswspace(c1 = GetC()) && !Eof() && (ix < (n_buf-1)))
  1942. buf[ix++] = c1; // add voice name to end of buffer, after the text
  1943. buf[ix++] = 0;
  1944. return(CLAUSE_VOICE);
  1945. }
  1946. else
  1947. if(c2 == 'B')
  1948. {
  1949. // set the punctuation option from an embedded command
  1950. // B0 B1 B<punct list><space>
  1951. strcpy(&buf[ix]," ");
  1952. ix += 3;
  1953. if((c2 = GetC()) == '0')
  1954. option_punctuation = 0;
  1955. else
  1956. {
  1957. option_punctuation = 1;
  1958. option_punctlist[0] = 0;
  1959. if(c2 != '1')
  1960. {
  1961. // a list of punctuation characters to be spoken, terminated by space
  1962. j = 0;
  1963. while(!iswspace(c2) && !Eof())
  1964. {
  1965. option_punctlist[j++] = c2;
  1966. c2 = GetC();
  1967. buf[ix++] = ' ';
  1968. }
  1969. option_punctlist[j] = 0; // terminate punctuation list
  1970. option_punctuation = 2;
  1971. }
  1972. }
  1973. c2 = GetC();
  1974. continue;
  1975. }
  1976. }
  1977. linelength++;
  1978. if(iswalnum(c1))
  1979. any_alnum = 1;
  1980. else
  1981. {
  1982. if(stressed_word)
  1983. {
  1984. stressed_word = 0;
  1985. c1 = CHAR_EMPHASIS; // indicate this word is stressed
  1986. UngetC(c2);
  1987. c2 = ' ';
  1988. }
  1989. if(lookupwchar(chars_ignore,c1))
  1990. {
  1991. // ignore this character (eg. zero-width-non-joiner U+200C)
  1992. continue;
  1993. }
  1994. if(iswspace(c1))
  1995. {
  1996. char *p_word;
  1997. if(tr->translator_name == 0x6a626f)
  1998. {
  1999. // language jbo : lojban
  2000. // treat "i" or ".i" as end-of-sentence
  2001. p_word = &buf[ix-1];
  2002. if(p_word[0] == 'i')
  2003. {
  2004. if(p_word[-1] == '.')
  2005. p_word--;
  2006. if(p_word[-1] == ' ')
  2007. {
  2008. ungot_word = "i ";
  2009. UngetC(c2);
  2010. p_word[0] = 0;
  2011. return(CLAUSE_PERIOD);
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. if(iswupper(c1))
  2018. {
  2019. tr->clause_upper_count++;
  2020. if((option_capitals == 2) && (sayas_mode == 0) && !iswupper(cprev))
  2021. {
  2022. char text_buf[40];
  2023. char text_buf2[30];
  2024. if(LookupSpecial(tr, "_cap", text_buf2) != NULL)
  2025. {
  2026. sprintf(text_buf,"%s",text_buf2);
  2027. j = strlen(text_buf);
  2028. if((ix + j) < n_buf)
  2029. {
  2030. strcpy(&buf[ix],text_buf);
  2031. ix += j;
  2032. }
  2033. }
  2034. }
  2035. }
  2036. else
  2037. if(iswalpha(c1))
  2038. tr->clause_lower_count++;
  2039. if(option_phoneme_input)
  2040. {
  2041. if(phoneme_mode > 0)
  2042. phoneme_mode--;
  2043. else
  2044. if((c1 == '[') && (c2 == '['))
  2045. phoneme_mode = -1; // input is phoneme mnemonics, so don't look for punctuation
  2046. else
  2047. if((c1 == ']') && (c2 == ']'))
  2048. phoneme_mode = 2; // set phoneme_mode to zero after the next two characters
  2049. }
  2050. if(c1 == '\n')
  2051. {
  2052. parag = 0;
  2053. // count consecutive newlines, ignoring other spaces
  2054. while(!Eof() && iswspace(c2))
  2055. {
  2056. if(c2 == '\n')
  2057. parag++;
  2058. c2 = GetC();
  2059. }
  2060. if(parag > 0)
  2061. {
  2062. // 2nd newline, assume paragraph
  2063. UngetC(c2);
  2064. if(end_clause_after_tag)
  2065. ix = end_clause_index; // delete clause-end punctiation
  2066. buf[ix] = ' ';
  2067. buf[ix+1] = 0;
  2068. if(parag > 3)
  2069. parag = 3;
  2070. if(option_ssml) parag=1;
  2071. return((CLAUSE_PARAGRAPH-30) + 30*parag); // several blank lines, longer pause
  2072. }
  2073. if(linelength <= option_linelength)
  2074. {
  2075. // treat lines shorter than a specified length as end-of-clause
  2076. UngetC(c2);
  2077. buf[ix] = ' ';
  2078. buf[ix+1] = 0;
  2079. return(CLAUSE_COLON);
  2080. }
  2081. linelength = 0;
  2082. }
  2083. prev_announced_punctuation = announced_punctuation;
  2084. announced_punctuation = 0;
  2085. if((phoneme_mode==0) && (sayas_mode==0))
  2086. {
  2087. is_end_clause = 0;
  2088. if(end_clause_after_tag)
  2089. {
  2090. // Because of an xml tag, we are waiting for the
  2091. // next non-blank character to decide whether to end the clause
  2092. // i.e. is dot followed by an upper-case letter?
  2093. if(!iswspace(c1))
  2094. {
  2095. if(!IsAlpha(c1) || !iswlower(c1))
  2096. // if(iswdigit(c1) || (IsAlpha(c1) && !iswlower(c1)))
  2097. {
  2098. UngetC(c2);
  2099. ungot_char2 = c1;
  2100. buf[end_clause_index] = ' '; // delete the end-clause punctuation
  2101. buf[end_clause_index+1] = 0;
  2102. return(end_clause_after_tag);
  2103. }
  2104. end_clause_after_tag = 0;
  2105. }
  2106. }
  2107. if((c1 == '.') && (c2 == '.'))
  2108. {
  2109. while((c_next = GetC()) == '.')
  2110. {
  2111. // 3 or more dots, replace by elipsis
  2112. c1 = 0x2026;
  2113. c2 = ' ';
  2114. }
  2115. if(c1 == 0x2026)
  2116. c2 = c_next;
  2117. else
  2118. UngetC(c_next);
  2119. }
  2120. punct_data = 0;
  2121. if((punct = lookupwchar(punct_chars,c1)) != 0)
  2122. {
  2123. punct_data = punct_attributes[punct];
  2124. if(punct_data & PUNCT_IN_WORD)
  2125. {
  2126. // Armenian punctuation inside a word
  2127. stressed_word = 1;
  2128. *tone_type = punct_data >> 12 & 0xf; // override the end-of-sentence type
  2129. continue;
  2130. }
  2131. if((iswspace(c2) || (punct_data & 0x8000) || IsBracket(c2) || (c2=='?') || Eof())) // don't check for '-' because if prevent recognizing ':-)'
  2132. // if((iswspace(c2) || (punct_data & 0x8000) || IsBracket(c2) || (c2=='?') || (c2=='-') || Eof()))
  2133. {
  2134. // note: (c2='?') is for when a smart-quote has been replaced by '?'
  2135. is_end_clause = 1;
  2136. }
  2137. }
  2138. // don't announce punctuation for the alternative text inside inside <audio> ... </audio>
  2139. if(c1 == 0xe000+'<') c1 = '<';
  2140. if(option_punctuation && iswpunct(c1) && (audio_text == 0))
  2141. {
  2142. // option is set to explicitly speak punctuation characters
  2143. // if a list of allowed punctuation has been set up, check whether the character is in it
  2144. if((option_punctuation == 1) || (wcschr(option_punctlist,c1) != NULL))
  2145. {
  2146. tr->phonemes_repeat_count = 0;
  2147. if((terminator = AnnouncePunctuation(tr, c1, &c2, buf, &ix, is_end_clause)) >= 0)
  2148. return(terminator);
  2149. announced_punctuation = c1;
  2150. }
  2151. }
  2152. if((punct_data & PUNCT_SAY_NAME) && (announced_punctuation == 0))
  2153. {
  2154. // used for elipsis (and 3 dots) if a pronunciation for elipsis is given in *_list
  2155. char *p2;
  2156. p2 = &buf[ix];
  2157. sprintf(p2,"%s",LookupCharName(tr, c1, 1));
  2158. if(p2[0] != 0)
  2159. {
  2160. ix += strlen(p2);
  2161. announced_punctuation = c1;
  2162. punct_data = punct_data & ~CLAUSE_BITS_INTONATION; // change intonation type to 0 (full-stop)
  2163. }
  2164. }
  2165. if(is_end_clause)
  2166. {
  2167. nl_count = 0;
  2168. c_next = c2;
  2169. if(iswspace(c_next))
  2170. {
  2171. while(!Eof() && iswspace(c_next))
  2172. {
  2173. if(c_next == '\n')
  2174. nl_count++;
  2175. c_next = GetC(); // skip past space(s)
  2176. }
  2177. }
  2178. if((c1 == '.') && (nl_count < 2))
  2179. {
  2180. punct_data |= CLAUSE_DOT;
  2181. }
  2182. if(nl_count==0)
  2183. {
  2184. if((c1 == ',') && (cprev == '.') && (tr->translator_name == L('h','u')) && iswdigit(cprev2) && (iswdigit(c_next) || (iswlower(c_next))))
  2185. {
  2186. // lang=hu, fix for ordinal numbers, eg: "december 2., szerda", ignore ',' after ordinal number
  2187. c1 = CHAR_COMMA_BREAK;
  2188. is_end_clause = 0;
  2189. }
  2190. if(c1 == '.')
  2191. {
  2192. if((tr->langopts.numbers & NUM_ORDINAL_DOT) &&
  2193. (iswdigit(cprev) || (IsRomanU(cprev) && (IsRomanU(cprev2) || iswspace(cprev2))))) // lang=hu
  2194. {
  2195. // dot after a number indicates an ordinal number
  2196. if(!iswdigit(cprev))
  2197. {
  2198. is_end_clause = 0; // Roman number followed by dot
  2199. }
  2200. else
  2201. {
  2202. if (iswlower(c_next) || (c_next=='-')) // hyphen is needed for lang-hu (eg. 2.-kal)
  2203. is_end_clause = 0; // only if followed by lower-case, (or if there is a XML tag)
  2204. }
  2205. }
  2206. else
  2207. if(c_next == '\'')
  2208. {
  2209. is_end_clause = 0; // eg. u.s.a.'s
  2210. }
  2211. if(iswlower(c_next))
  2212. {
  2213. // next word has no capital letter, this dot is probably from an abbreviation
  2214. // c1 = ' ';
  2215. is_end_clause = 0;
  2216. }
  2217. if(any_alnum==0)
  2218. {
  2219. // no letters or digits yet, so probably not a sentence terminator
  2220. // Here, dot is followed by space or bracket
  2221. c1 = ' ';
  2222. is_end_clause = 0;
  2223. }
  2224. }
  2225. else
  2226. {
  2227. if(any_alnum==0)
  2228. {
  2229. // no letters or digits yet, so probably not a sentence terminator
  2230. is_end_clause = 0;
  2231. }
  2232. }
  2233. if(is_end_clause && (c1 == '.') && (c_next == '<') && option_ssml)
  2234. {
  2235. // wait until after the end of the xml tag, then look for upper-case letter
  2236. is_end_clause = 0;
  2237. end_clause_index = ix;
  2238. end_clause_after_tag = punct_data;
  2239. }
  2240. }
  2241. if(is_end_clause)
  2242. {
  2243. UngetC(c_next);
  2244. buf[ix] = ' ';
  2245. buf[ix+1] = 0;
  2246. if(iswdigit(cprev) && !IsAlpha(c_next)) // ????
  2247. {
  2248. punct_data &= ~CLAUSE_DOT;
  2249. }
  2250. if(nl_count > 1)
  2251. {
  2252. if((punct_data == CLAUSE_QUESTION) || (punct_data == CLAUSE_EXCLAMATION))
  2253. return(punct_data + 35); // with a longer pause
  2254. return(CLAUSE_PARAGRAPH);
  2255. }
  2256. return(punct_data); // only recognise punctuation if followed by a blank or bracket/quote
  2257. }
  2258. else
  2259. {
  2260. if(!Eof())
  2261. {
  2262. if(iswspace(c2))
  2263. UngetC(c_next);
  2264. }
  2265. }
  2266. }
  2267. }
  2268. if(speech_parameters[espeakSILENCE]==1)
  2269. continue;
  2270. if(c1 == announced_punctuation)
  2271. {
  2272. // This character has already been announced, so delete it so that it isn't spoken a second time.
  2273. // Unless it's a hyphen or apostrophe (which is used by TranslateClause() )
  2274. if(IsBracket(c1))
  2275. {
  2276. c1 = 0xe000 + '('; // Unicode private useage area. So TranslateRules() knows the bracket name has been spoken
  2277. }
  2278. else
  2279. if(c1 != '-')
  2280. {
  2281. c1 = ' ';
  2282. }
  2283. }
  2284. j = ix+1;
  2285. if(c1 == 0xe000 + '<') c1 = '<';
  2286. ix += utf8_out(c1,&buf[ix]); // buf[ix++] = c1;
  2287. if(!iswspace(c1) && !IsBracket(c1))
  2288. {
  2289. charix[ix] = count_characters - clause_start_char;
  2290. while(j < ix)
  2291. charix[j++] = -1; // subsequent bytes of a multibyte character
  2292. }
  2293. *charix_top = ix;
  2294. if(((ix > (n_buf-20)) && !IsAlpha(c1) && !iswdigit(c1)) || (ix >= (n_buf-2)))
  2295. {
  2296. // clause too long, getting near end of buffer, so break here
  2297. // try to break at a word boundary (unless we actually reach the end of buffer).
  2298. buf[ix] = ' ';
  2299. buf[ix+1] = 0;
  2300. UngetC(c2);
  2301. return(CLAUSE_NONE);
  2302. }
  2303. }
  2304. if(stressed_word)
  2305. {
  2306. ix += utf8_out(CHAR_EMPHASIS, &buf[ix]);
  2307. }
  2308. if(end_clause_after_tag)
  2309. {
  2310. ix = end_clause_index; // delete clause-end punctuation
  2311. }
  2312. buf[ix] = ' ';
  2313. buf[ix+1] = 0;
  2314. return(CLAUSE_EOF); // end of file
  2315. } // end of ReadClause
  2316. void InitNamedata(void)
  2317. {//====================
  2318. namedata_ix = 0;
  2319. if(namedata != NULL)
  2320. {
  2321. free(namedata);
  2322. namedata = NULL;
  2323. n_namedata = 0;
  2324. }
  2325. }
  2326. void InitText2(void)
  2327. {//=================
  2328. int param;
  2329. ungot_char = 0;
  2330. n_ssml_stack =1;
  2331. n_param_stack = 1;
  2332. ssml_stack[0].tag_type = 0;
  2333. for(param=0; param<N_SPEECH_PARAM; param++)
  2334. speech_parameters[param] = param_stack[0].parameter[param]; // set all speech parameters to defaults
  2335. option_punctuation = speech_parameters[espeakPUNCTUATION];
  2336. option_capitals = speech_parameters[espeakCAPITALS];
  2337. current_voice_id[0] = 0;
  2338. ignore_text = 0;
  2339. audio_text = 0;
  2340. clear_skipping_text = 0;
  2341. count_characters = -1;
  2342. sayas_mode = 0;
  2343. xmlbase = NULL;
  2344. }