123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961 |
-
-
- #include "StdAfx.h"
-
- #include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
-
- #ifdef ANDROID
- #include "android_wchar.h"
- #else
- #include <wctype.h>
- #include <wchar.h>
- #endif
-
- #include "speak_lib.h"
- #include "speech.h"
- #include "phoneme.h"
- #include "synthesize.h"
- #include "voice.h"
- #include "translate.h"
-
- #ifdef PLATFORM_POSIX
- #include <unistd.h>
- #endif
-
- #include <locale.h>
- #define N_XML_BUF 256
-
-
- static const char *xmlbase = "";
-
- static int namedata_ix=0;
- static int n_namedata = 0;
- char *namedata = NULL;
-
-
- static FILE *f_input = NULL;
- static int ungot_char2 = 0;
- unsigned char *p_textinput;
- wchar_t *p_wchar_input;
- static int ungot_char;
- static const char *ungot_word = NULL;
- static int end_of_input;
-
- static int ignore_text=0;
- static int audio_text=0;
- static int clear_skipping_text = 0;
- int count_characters = 0;
- static int sayas_mode;
- static int sayas_start;
- static int ssml_ignore_l_angle = 0;
-
-
-
-
-
-
- static const unsigned short punct_chars[] = {',','.','?','!',':',';',
- 0x00a1,
- 0x00bf,
- 0x2013,
- 0x2014,
- 0x2026,
-
- 0x037e,
- 0x0387,
- 0x0964,
-
- 0x0589,
- 0x055d,
- 0x055c,
- 0x055e,
- 0x055b,
-
- 0x060c,
- 0x061b,
- 0x061f,
- 0x06d4,
-
- 0x0df4,
- 0x0f0d,
- 0x0f0e,
-
- 0x1362,
- 0x1363,
- 0x1364,
- 0x1365,
- 0x1366,
- 0x1367,
- 0x1368,
- 0x10fb,
-
- 0x3001,
- 0x3002,
-
- 0xff01,
- 0xff0c,
- 0xff0e,
- 0xff1a,
- 0xff1b,
- 0xff1f,
-
- 0};
-
-
-
-
- static const unsigned int punct_attributes [] = { 0,
- CLAUSE_COMMA, CLAUSE_PERIOD, CLAUSE_QUESTION, CLAUSE_EXCLAMATION, CLAUSE_COLON, CLAUSE_SEMICOLON,
- CLAUSE_SEMICOLON | 0x8000,
- CLAUSE_SEMICOLON | 0x8000,
- CLAUSE_SEMICOLON,
- CLAUSE_SEMICOLON,
- CLAUSE_SEMICOLON | PUNCT_SAY_NAME | 0x8000,
-
- CLAUSE_QUESTION,
- CLAUSE_SEMICOLON,
- CLAUSE_PERIOD | 0x8000,
-
- CLAUSE_PERIOD | 0x8000,
- CLAUSE_COMMA,
- CLAUSE_EXCLAMATION | PUNCT_IN_WORD,
- CLAUSE_QUESTION | PUNCT_IN_WORD,
- CLAUSE_PERIOD | PUNCT_IN_WORD,
-
- CLAUSE_COMMA,
- CLAUSE_SEMICOLON,
- CLAUSE_QUESTION,
- CLAUSE_PERIOD,
-
- CLAUSE_PERIOD+0x8000,
- CLAUSE_PERIOD+0x8000,
- CLAUSE_PARAGRAPH,
-
- CLAUSE_PERIOD,
- CLAUSE_COMMA,
- CLAUSE_SEMICOLON,
- CLAUSE_COLON,
- CLAUSE_COLON,
- CLAUSE_QUESTION,
- CLAUSE_PARAGRAPH,
- CLAUSE_PARAGRAPH,
-
- CLAUSE_COMMA+0x8000,
- CLAUSE_PERIOD+0x8000,
-
- CLAUSE_EXCLAMATION+0x8000,
- CLAUSE_COMMA+0x8000,
- CLAUSE_PERIOD+0x8000,
- CLAUSE_COLON+0x8000,
- CLAUSE_SEMICOLON+0x8000,
- CLAUSE_QUESTION+0x8000,
-
- CLAUSE_SEMICOLON,
- 0 };
-
-
-
-
- typedef struct {
- int tag_type;
- int voice_variant_number;
- int voice_gender;
- int voice_age;
- char voice_name[40];
- char language[20];
- } SSML_STACK;
-
- #define N_SSML_STACK 20
- static int n_ssml_stack;
- static SSML_STACK ssml_stack[N_SSML_STACK];
-
- static espeak_VOICE base_voice;
- static char base_voice_variant_name[40] = {0};
- static char current_voice_id[40] = {0};
-
-
- #define N_PARAM_STACK 20
- static int n_param_stack;
- PARAM_STACK param_stack[N_PARAM_STACK];
-
- static int speech_parameters[N_SPEECH_PARAM];
- int saved_parameters[N_SPEECH_PARAM];
-
- const int param_defaults[N_SPEECH_PARAM] = {
- 0,
- 175,
- 100,
- 50,
- 50,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- };
-
-
-
- #define MAX_WALPHA 0x24f
-
-
-
- static unsigned char walpha_tab[MAX_WALPHA-0x7f] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xfe, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0xff, 0, 0, 0, 0, 0xfe, 0, 0, 0, 0, 0,
- 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 0, 32, 32, 32, 32, 32, 32, 32, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 0xfd, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 0xfe, 1, 0xff, 1, 0xff, 1, 0xff, 1,
- 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 0xfe, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 0xfd, 1, 0xff, 1, 0xff, 1, 0xff, 0xff,
- 0xff, 210, 1, 0xff, 1, 0xff, 206, 1, 0xff, 205, 205, 1, 0xff, 0xfe, 79, 202,
- 203, 1, 0xff, 205, 207, 0xff, 211, 209, 1, 0xff, 0xff, 0xfe, 211, 213, 0xff, 214,
- 1, 0xff, 1, 0xff, 1, 0xff, 218, 1, 0xff, 218, 0xfe, 0xfe, 1, 0xff, 218, 1,
- 0xff, 217, 217, 1, 0xff, 1, 0xff, 219, 1, 0xff, 0xfe, 0xfe, 1, 0xff, 0xfe, 0xff,
- 0xfe, 0xfe, 0xfe, 0xfe, 2, 0xff, 0xff, 2, 0xff, 0xff, 2, 0xff, 0xff, 1, 0xff, 1,
- 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 0xfe, 2, 0xff, 0xff, 1, 0xff, 0xfd, 0xfd, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 0xfd, 0xfe, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff,
- 1, 0xff, 1, 0xff, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 1, 0xff, 0xfd, 0xfd, 0xfe,
- 0xfe, 1, 0xff, 0xfd, 69, 71, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff, 1, 0xff};
-
- static const short wchar_tolower[] = {
- 0x130, 0x069,
- 0x178, 0x0ff,
- 0x1f6, 0x195,
- 0x1f7, 0x1bf,
- 0x220, 0x19e,
- 0x23a, 0x2c65,
- 0x23d, 0x19a,
- 0x23e, 0x2c66,
- 0x243, 0x180,
- 0,0 };
-
- static const short wchar_toupper[] = {
- 0x0b5, 0x39c,
- 0x0df, 0x0df,
- 0x0ff, 0x178,
- 0x131, 0x049,
- 0x17f, 0x053,
- 0x180, 0x243,
- 0x195, 0x1f6,
- 0x19a, 0x23d,
- 0x19e, 0x220,
- 0x1bf, 0x1f7,
- 0x1c6, 0x1c4,
- 0x1c9, 0x1c7,
- 0x1cc, 0x1ca,
- 0x1dd, 0x18e,
- 0x1f3, 0x1f1,
- 0,0 };
-
-
- #ifdef NEED_WCHAR_FUNCTIONS
-
-
- int iswalpha(int c)
- {
- if(c < 0x80)
- return(isalpha(c));
- if((c > 0x3040) && (c <= 0xa700))
- return(1);
- if(c > MAX_WALPHA)
- return(0);
- return(walpha_tab[c-0x80]);
- }
-
- int iswdigit(int c)
- {
- if(c < 0x80)
- return(isdigit(c));
- return(0);
- }
-
- int iswalnum(int c)
- {
- if(iswdigit(c))
- return(1);
- return(iswalpha(c));
- }
-
- int towlower(int c)
- {
- int x;
- int ix;
-
- if(c < 0x80)
- return(tolower(c));
-
- if((c > MAX_WALPHA) || ((x = walpha_tab[c-0x80]) >= 0xfe))
- return(c);
-
- if(x == 0xfd)
- {
-
- for(ix=0; wchar_tolower[ix] != 0; ix+=2)
- {
- if(wchar_tolower[ix] == c)
- return(wchar_tolower[ix+1]);
- }
- }
- return(c + x);
- }
-
- int towupper(int c)
- {
- int ix;
-
- if(towlower(c-32) == c)
- return(c-32);
- if(towlower(c-1) == c)
- return(c-1);
- for(ix=0; wchar_toupper[ix] != 0; ix+=2)
- {
- if(wchar_toupper[ix] == c)
- return(wchar_toupper[ix+1]);
- }
- return(c);
- }
-
- int iswupper(int c)
- {
- int x;
- if(c < 0x80)
- return(isupper(c));
- if(((c > MAX_WALPHA) || (x = walpha_tab[c-0x80])==0) || (x == 0xff))
- return(0);
- return(1);
- }
-
- int iswlower(int c)
- {
- if(c < 0x80)
- return(islower(c));
- if((c > MAX_WALPHA) || (walpha_tab[c-0x80] != 0xff))
- return(0);
- return(1);
- }
-
- int iswspace(int c)
- {
- if(c < 0x80)
- return(isspace(c));
- if(c == 0xa0)
- return(1);
- return(0);
- }
-
- int iswpunct(int c)
- {
- if(c < 0x100)
- return(ispunct(c));
- return(0);
- }
-
- const wchar_t *wcschr(const wchar_t *str, int c)
- {
- while(*str != 0)
- {
- if(*str == c)
- return(str);
- str++;
- }
- return(NULL);
- }
-
- #ifndef WINCE
-
- const int wcslen(const wchar_t *str)
- {
- int ix=0;
-
- while(*str != 0)
- {
- ix++;
- }
- return(ix);
- }
- #endif
-
- float wcstod(const wchar_t *str, wchar_t **tailptr)
- {
- int ix;
- char buf[80];
- while(isspace(*str)) str++;
- for(ix=0; ix<80; ix++)
- {
- buf[ix] = str[ix];
- if(isspace(buf[ix]))
- break;
- }
- *tailptr = (wchar_t *)&str[ix];
- return(atof(buf));
- }
- #endif
-
-
-
-
- int iswalpha2(int c)
- {
- if(c < 0x80)
- return(isalpha(c));
- if((c > 0x3040) && (c <= 0xa700))
- return(1);
- if(c > MAX_WALPHA)
- return(iswalpha(c));
- return(walpha_tab[c-0x80]);
- }
-
- int iswlower2(int c)
- {
- if(c < 0x80)
- return(islower(c));
- if(c > MAX_WALPHA)
- return(iswlower(c));
- if(walpha_tab[c-0x80] == 0xff)
- return(1);
- return(0);
- }
-
- int iswupper2(int c)
- {
- int x;
- if(c < 0x80)
- return(isupper(c));
- if(c > MAX_WALPHA)
- return(iswupper(c));
- if(((x = walpha_tab[c-0x80]) > 0) && (x < 0xfe))
- return(1);
- return(0);
- }
-
- int towlower2(unsigned int c)
- {
- int x;
- int ix;
-
-
- if(c == 'I')
- {
- if(translator->langopts.dotless_i)
- {
- c = 0x131;
- }
- }
-
- if(c < 0x80)
- return(tolower(c));
-
- if(c > MAX_WALPHA)
- return(towlower(c));
-
- if((x = walpha_tab[c-0x80]) >= 0xfe)
- return(c);
-
- if(x == 0xfd)
- {
-
- for(ix=0; wchar_tolower[ix] != 0; ix+=2)
- {
- if(wchar_tolower[ix] == (int)c)
- return(wchar_tolower[ix+1]);
- }
- }
- return(c + x);
- }
-
- int towupper2(unsigned int c)
- {
- int ix;
- if(c > MAX_WALPHA)
- return(towupper(c));
-
-
- if(towlower2(c-32) == (int)c)
- return(c-32);
- if(towlower2(c-1) == (int)c)
- return(c-1);
- for(ix=0; wchar_toupper[ix] != 0; ix+=2)
- {
- if(wchar_toupper[ix] == (int)c)
- return(wchar_toupper[ix+1]);
- }
- return(c);
- }
-
- static int IsRomanU(unsigned int c)
- {
- if((c=='I') || (c=='V') || (c=='X') || (c=='L'))
- return(1);
- return(0);
- }
-
-
- static void GetC_unget(int c)
- {
-
- if(f_input != NULL)
- ungetc(c,f_input);
- else
- {
- p_textinput--;
- *p_textinput = c;
- end_of_input = 0;
- }
- }
-
- int Eof(void)
- {
- if(ungot_char != 0)
- return(0);
-
- if(f_input != 0)
- return(feof(f_input));
-
- return(end_of_input);
- }
-
-
- static int GetC_get(void)
- {
- unsigned int c;
- unsigned int c2;
-
- if(f_input != NULL)
- {
- c = fgetc(f_input);
- if(feof(f_input)) c = ' ';
-
- if(option_multibyte == espeakCHARS_16BIT)
- {
- c2 = fgetc(f_input);
- if(feof(f_input)) c2 = 0;
- c = c + (c2 << 8);
- }
- return(c);
- }
-
- if(option_multibyte == espeakCHARS_WCHAR)
- {
- if(*p_wchar_input == 0)
- {
- end_of_input = 1;
- return(0);
- }
-
- if(!end_of_input)
- return(*p_wchar_input++);
- }
- else
- {
- if(*p_textinput == 0)
- {
- end_of_input = 1;
- return(0);
- }
-
- if(!end_of_input)
- {
- if(option_multibyte == espeakCHARS_16BIT)
- {
- c = p_textinput[0] + (p_textinput[1] << 8);
- p_textinput += 2;
- return(c);
- }
- return(*p_textinput++ & 0xff);
- }
- }
- return(0);
- }
-
-
- static int GetC(void)
- {
-
-
-
- int c;
- int c1;
- int c2;
- int cbuf[4];
- int ix;
- int n_bytes;
- static int ungot2 = 0;
- static const unsigned char mask[4] = {0xff,0x1f,0x0f,0x07};
-
- if((c1 = ungot_char) != 0)
- {
- ungot_char = 0;
- return(c1);
- }
-
- if(ungot2 != 0)
- {
- c1 = ungot2;
- ungot2 = 0;
- }
- else
- {
- c1 = GetC_get();
- }
-
- if((option_multibyte == espeakCHARS_WCHAR) || (option_multibyte == espeakCHARS_16BIT))
- {
- count_characters++;
- return(c1);
- }
-
- if((option_multibyte < 2) && (c1 & 0x80))
- {
-
- n_bytes = 0;
-
- if(((c1 & 0xe0) == 0xc0) && ((c1 & 0x1e) != 0))
- n_bytes = 1;
- else
- if((c1 & 0xf0) == 0xe0)
- n_bytes = 2;
- else
- if(((c1 & 0xf8) == 0xf0) && ((c1 & 0x0f) <= 4))
- n_bytes = 3;
-
- if((ix = n_bytes) > 0)
- {
- c = c1 & mask[ix];
- while(ix > 0)
- {
- if((c2 = cbuf[ix] = GetC_get()) == 0)
- {
- if(option_multibyte==espeakCHARS_AUTO)
- option_multibyte=espeakCHARS_8BIT;
- GetC_unget(' ');
- break;
- }
-
- if((c2 & 0xc0) != 0x80)
- {
-
- if((n_bytes == 2) && (ix == 1))
- ungot2 = cbuf[2];
- GetC_unget(c2);
- break;
- }
- c = (c << 6) + (c2 & 0x3f);
- ix--;
- }
- if(ix == 0)
- {
- count_characters++;
- return(c);
- }
- }
-
- if((option_multibyte==espeakCHARS_AUTO) && !Eof())
- option_multibyte=espeakCHARS_8BIT;
- }
-
-
- count_characters++;
- if(c1 >= 0xa0)
- return(translator->charset_a0[c1-0xa0]);
- return(c1);
- }
-
-
- static void UngetC(int c)
- {
- ungot_char = c;
- }
-
-
- const char *WordToString2(unsigned int word)
- {
-
- int ix;
- static char buf[5];
- char *p;
-
- p = buf;
- for(ix=3; ix>=0; ix--)
- {
- if((*p = word >> (ix*8)) != 0)
- p++;
- }
- *p = 0;
- return(buf);
- }
-
-
- static const char *LookupSpecial(Translator *tr, const char *string, char* text_out)
- {
- unsigned int flags[2];
- char phonemes[55];
- char phonemes2[55];
- char *string1 = (char *)string;
-
- flags[0] = flags[1] = 0;
- if(LookupDictList(tr,&string1,phonemes,flags,0,NULL))
- {
- SetWordStress(tr, phonemes, flags, -1, 0);
- DecodePhonemes(phonemes,phonemes2);
- sprintf(text_out,"[\002%s]]",phonemes2);
- return(text_out);
- }
- return(NULL);
- }
-
-
- static const char *LookupCharName(Translator *tr, int c, int only)
- {
-
-
-
- int ix;
- unsigned int flags[2];
- char single_letter[24];
- char phonemes[60];
- char phonemes2[60];
- const char *lang_name = NULL;
- char *string;
- static char buf[60];
-
- buf[0] = 0;
- flags[0] = 0;
- flags[1] = 0;
- single_letter[0] = 0;
- single_letter[1] = '_';
- ix = utf8_out(c,&single_letter[2]);
- single_letter[2+ix]=0;
-
- if(only)
- {
- string = &single_letter[2];
- LookupDictList(tr, &string, phonemes, flags, 0, NULL);
- }
- else
- {
- string = &single_letter[1];
- if(LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0)
- {
-
- string = &single_letter[2];
- if(LookupDictList(tr, &string, phonemes, flags, 0, NULL) == 0)
- {
-
- single_letter[1] = ' ';
- TranslateRules(tr, &single_letter[2], phonemes, sizeof(phonemes), NULL,0,NULL);
- }
- }
- }
-
- if((only==0) && ((phonemes[0] == 0) || (phonemes[0] == phonSWITCH)) && (tr->translator_name != L('e','n')))
- {
-
- SetTranslator2("en");
- string = &single_letter[1];
- single_letter[1] = '_';
- if(LookupDictList(translator2, &string, phonemes, flags, 0, NULL) == 0)
- {
- string = &single_letter[2];
- LookupDictList(translator2, &string, phonemes, flags, 0, NULL);
- }
- if(phonemes[0])
- {
- lang_name = "en";
- }
- else
- {
- SelectPhonemeTable(voice->phoneme_tab_ix);
- }
- }
-
- if(phonemes[0])
- {
- if(lang_name)
- {
- SetWordStress(translator2, phonemes, flags, -1, 0);
- DecodePhonemes(phonemes,phonemes2);
- sprintf(buf,"[\002_^_%s %s _^_%s]]","en",phonemes2,WordToString2(tr->translator_name));
- SelectPhonemeTable(voice->phoneme_tab_ix);
- }
- else
- {
- SetWordStress(tr, phonemes, flags, -1, 0);
- DecodePhonemes(phonemes,phonemes2);
- sprintf(buf,"[\002%s]] ",phonemes2);
- }
- }
- else
- if(only == 0)
- {
- strcpy(buf,"[\002(X1)(X1)(X1)]]");
- }
-
- return(buf);
- }
-
- int Read4Bytes(FILE *f)
- {
-
- int ix;
- unsigned char c;
- int acc=0;
-
- for(ix=0; ix<4; ix++)
- {
- c = fgetc(f) & 0xff;
- acc += (c << (ix*8));
- }
- return(acc);
- }
-
-
- static int LoadSoundFile(const char *fname, int index)
- {
- FILE *f;
- char *p;
- int *ip;
- int length;
- char fname_temp[100];
- char fname2[sizeof(path_home)+13+40];
-
- if(fname == NULL)
- {
-
- fname = soundicon_tab[index].filename;
- }
-
- if(fname==NULL)
- return(1);
-
- if(fname[0] != '/')
- {
-
- sprintf(fname2,"%s%csoundicons%c%s",path_home,PATHSEP,PATHSEP,fname);
- fname = fname2;
- }
-
- f = NULL;
- #ifdef PLATFORM_POSIX
- if((f = fopen(fname,"rb")) != NULL)
- {
- int ix;
- int fd_temp;
- int header[3];
- char command[sizeof(fname2)+sizeof(fname2)+40];
-
- fseek(f,20,SEEK_SET);
- for(ix=0; ix<3; ix++)
- header[ix] = Read4Bytes(f);
-
-
- if((header[0] != 0x10001) || (header[1] != samplerate) || (header[2] != samplerate*2))
- {
- fclose(f);
- f = NULL;
-
- strcpy(fname_temp,"/tmp/espeakXXXXXX");
- if((fd_temp = mkstemp(fname_temp)) >= 0)
- {
- close(fd_temp);
- sprintf(command,"sox \"%s\" -r %d -c1 -t wav %s\n", fname, samplerate, fname_temp);
- if(system(command) == 0)
- {
- fname = fname_temp;
- }
- }
- }
- }
- #endif
-
- if(f == NULL)
- {
- f = fopen(fname,"rb");
- if(f == NULL)
- {
-
- return(3);
- }
- }
-
- length = GetFileLength(fname);
- fseek(f,0,SEEK_SET);
- if((p = (char *)realloc(soundicon_tab[index].data, length)) == NULL)
- {
- fclose(f);
- return(4);
- }
- length = fread(p,1,length,f);
- fclose(f);
- remove(fname_temp);
-
- ip = (int *)(&p[40]);
- soundicon_tab[index].length = (*ip) / 2;
- soundicon_tab[index].data = p;
- return(0);
- }
-
-
- static int LookupSoundicon(int c)
- {
-
- int ix;
-
- for(ix=N_SOUNDICON_SLOTS; ix<n_soundicon_tab; ix++)
- {
- if(soundicon_tab[ix].name == c)
- {
- if(soundicon_tab[ix].length == 0)
- {
- if(LoadSoundFile(NULL,ix)!=0)
- return(-1);
- }
- return(ix);
- }
- }
- return(-1);
- }
-
-
- static int LoadSoundFile2(const char *fname)
- {
-
-
-
- int ix;
- static int slot = -1;
-
- for(ix=0; ix<n_soundicon_tab; ix++)
- {
- if(((soundicon_tab[ix].filename != NULL) && strcmp(fname, soundicon_tab[ix].filename) == 0))
- return(ix);
- }
-
-
- slot++;
- if(slot >= N_SOUNDICON_SLOTS)
- slot = 0;
-
- if(LoadSoundFile(fname, slot) != 0)
- return(-1);
-
- soundicon_tab[slot].filename = (char *)realloc(soundicon_tab[ix].filename, strlen(fname)+1);
- strcpy(soundicon_tab[slot].filename, fname);
- return(slot);
- }
-
-
-
- static int AnnouncePunctuation(Translator *tr, int c1, int *c2_ptr, char *output, int *bufix, int end_clause)
- {
-
-
-
-
- int punct_count;
- const char *punctname = NULL;
- int soundicon;
- int attributes;
- int short_pause;
- int c2;
- int len;
- int bufix1;
- char buf[200];
- char buf2[80];
- char ph_buf[30];
-
- c2 = *c2_ptr;
- buf[0] = 0;
-
- if((soundicon = LookupSoundicon(c1)) >= 0)
- {
-
- sprintf(buf,"\001%dI ",soundicon);
- UngetC(c2);
- }
- else
- {
- if((c1 == '.') && (end_clause) && (c2 != '.'))
- {
- if(LookupSpecial(tr, "_.p", ph_buf))
- {
- punctname = ph_buf;
- }
- }
- if(punctname == NULL)
- {
- punctname = LookupCharName(tr, c1, 0);
- }
-
- if(punctname == NULL)
- return(-1);
-
- if((*bufix==0) || (end_clause ==0) || (tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2))
- {
- punct_count=1;
- while((c2 == c1) && (c1 != '<'))
- {
- punct_count++;
- c2 = GetC();
- }
- *c2_ptr = c2;
- if(end_clause)
- {
- UngetC(c2);
- }
-
- if(punct_count==1)
- {
-
- sprintf(buf," %s",punctname);
- }
- else
- if(punct_count < 4)
- {
- buf[0] = 0;
- if(embedded_value[EMBED_S] < 300)
- sprintf(buf,"\001+10S");
-
- while(punct_count-- > 0)
- {
- sprintf(buf2," %s",punctname);
- strcat(buf, buf2);
- }
-
- if(embedded_value[EMBED_S] < 300)
- {
- sprintf(buf2," \001-10S");
- strcat(buf, buf2);
- }
- }
- else
- {
- sprintf(buf," %s %d %s",
- punctname,punct_count,punctname);
- }
- }
- else
- {
-
- UngetC(c2);
- if(option_ssml)
- {
- if((c1 == '<') || (c1 == '&'))
- ssml_ignore_l_angle = c1;
- }
- ungot_char2 = c1;
- buf[0] = ' ';
- buf[1] = 0;
- }
- }
-
- bufix1 = *bufix;
- len = strlen(buf);
- strcpy(&output[*bufix],buf);
- *bufix += len;
-
- if(end_clause==0)
- return(-1);
-
- if(c1 == '-')
- return(CLAUSE_NONE);
-
- attributes = punct_attributes[lookupwchar(punct_chars,c1)];
-
- short_pause = CLAUSE_SHORTFALL;
- if((attributes & CLAUSE_BITS_INTONATION) == 0x1000)
- short_pause = CLAUSE_SHORTCOMMA;
-
- if((bufix1 > 0) && !(tr->langopts.param[LOPT_ANNOUNCE_PUNCT] & 2))
- {
- if((attributes & ~0x8000) == CLAUSE_SEMICOLON)
- return(CLAUSE_SHORTFALL);
- return(short_pause);
- }
-
- if(attributes & CLAUSE_BIT_SENTENCE)
- return(attributes);
-
- return(short_pause);
- }
-
- #define SSML_SPEAK 1
- #define SSML_VOICE 2
- #define SSML_PROSODY 3
- #define SSML_SAYAS 4
- #define SSML_MARK 5
- #define SSML_SENTENCE 6
- #define SSML_PARAGRAPH 7
- #define SSML_PHONEME 8
- #define SSML_SUB 9
- #define SSML_STYLE 10
- #define SSML_AUDIO 11
- #define SSML_EMPHASIS 12
- #define SSML_BREAK 13
- #define SSML_IGNORE_TEXT 14
- #define HTML_BREAK 15
- #define HTML_NOSPACE 16
- #define SSML_CLOSE 0x20
-
-
- 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};
-
-
- static MNEM_TAB ssmltags[] = {
- {"speak", SSML_SPEAK},
- {"voice", SSML_VOICE},
- {"prosody", SSML_PROSODY},
- {"say-as", SSML_SAYAS},
- {"mark", SSML_MARK},
- {"s", SSML_SENTENCE},
- {"p", SSML_PARAGRAPH},
- {"phoneme", SSML_PHONEME},
- {"sub", SSML_SUB},
- {"tts:style", SSML_STYLE},
- {"audio", SSML_AUDIO},
- {"emphasis", SSML_EMPHASIS},
- {"break", SSML_BREAK},
- {"metadata", SSML_IGNORE_TEXT},
-
- {"br", HTML_BREAK},
- {"li", HTML_BREAK},
- {"dd", HTML_BREAK},
- {"img", HTML_BREAK},
- {"td", HTML_BREAK},
- {"h1", SSML_PARAGRAPH},
- {"h2", SSML_PARAGRAPH},
- {"h3", SSML_PARAGRAPH},
- {"h4", SSML_PARAGRAPH},
- {"hr", SSML_PARAGRAPH},
- {"script", SSML_IGNORE_TEXT},
- {"style", SSML_IGNORE_TEXT},
- {"font", HTML_NOSPACE},
- {"b", HTML_NOSPACE},
- {"i", HTML_NOSPACE},
- {"strong", HTML_NOSPACE},
- {"em", HTML_NOSPACE},
- {"code", HTML_NOSPACE},
- {NULL,0}};
-
-
-
-
- static const char *VoiceFromStack()
- {
-
-
- int ix;
- const char *p;
- SSML_STACK *sp;
- const char *v_id;
- int voice_name_specified;
- int voice_found;
- espeak_VOICE voice_select;
- static char voice_name[40];
- char language[40];
- char buf[80];
-
- strcpy(voice_name,ssml_stack[0].voice_name);
- strcpy(language,ssml_stack[0].language);
- voice_select.age = ssml_stack[0].voice_age;
- voice_select.gender = ssml_stack[0].voice_gender;
- voice_select.variant = ssml_stack[0].voice_variant_number;
- voice_select.identifier = NULL;
-
- for(ix=0; ix<n_ssml_stack; ix++)
- {
- sp = &ssml_stack[ix];
- voice_name_specified = 0;
-
- if((sp->voice_name[0] != 0) && (SelectVoiceByName(NULL,sp->voice_name) != NULL))
- {
- voice_name_specified = 1;
- strcpy(voice_name, sp->voice_name);
- language[0] = 0;
- voice_select.gender = 0;
- voice_select.age = 0;
- voice_select.variant = 0;
- }
- if(sp->language[0] != 0)
- {
- strcpy(language, sp->language);
-
-
- p = base_voice.languages;
- while(*p++ != 0)
- {
- if(strcmp(p, language) == 0)
- {
-
- strcpy(language, &base_voice.languages[1]);
- break;
- }
- p += (strlen(p) + 1);
- }
-
- if(voice_name_specified == 0)
- voice_name[0] = 0;
- }
- if(sp->voice_gender != 0)
- {
- voice_select.gender = sp->voice_gender;
- }
-
- if(sp->voice_age != 0)
- voice_select.age = sp->voice_age;
- if(sp->voice_variant_number != 0)
- voice_select.variant = sp->voice_variant_number;
- }
-
- voice_select.name = voice_name;
- voice_select.languages = language;
- v_id = SelectVoice(&voice_select, &voice_found);
- if(v_id == NULL)
- return("default");
-
- if((strchr(v_id, '+') == NULL) && ((voice_select.gender == 0) || (voice_select.gender == base_voice.gender)) && (base_voice_variant_name[0] != 0))
- {
-
- sprintf(buf, "%s+%s", v_id, base_voice_variant_name);
- strncpy0(voice_name, buf, sizeof(voice_name));
- return(voice_name);
- }
- return(v_id);
- }
-
-
-
- static void ProcessParamStack(char *outbuf, int &outix)
- {
-
- int param;
- int ix;
- int value;
- char buf[20];
- int new_parameters[N_SPEECH_PARAM];
- static char cmd_letter[N_SPEECH_PARAM] = {0, 'S','A','P','R', 0, 'C', 0, 0, 0, 0, 0, 'F'};
-
-
- for(param=0; param<N_SPEECH_PARAM; param++)
- new_parameters[param] = -1;
-
- for(ix=0; ix<n_param_stack; ix++)
- {
- for(param=0; param<N_SPEECH_PARAM; param++)
- {
- if(param_stack[ix].parameter[param] >= 0)
- new_parameters[param] = param_stack[ix].parameter[param];
- }
- }
-
- for(param=0; param<N_SPEECH_PARAM; param++)
- {
- if((value = new_parameters[param]) != speech_parameters[param])
- {
- buf[0] = 0;
-
- switch(param)
- {
- case espeakPUNCTUATION:
- option_punctuation = value-1;
- break;
-
- case espeakCAPITALS:
- option_capitals = value;
- break;
-
- case espeakRATE:
- case espeakVOLUME:
- case espeakPITCH:
- case espeakRANGE:
- case espeakEMPHASIS:
- sprintf(buf,"%c%d%c",CTRL_EMBEDDED,value,cmd_letter[param]);
- break;
- }
-
- speech_parameters[param] = new_parameters[param];
- strcpy(&outbuf[outix],buf);
- outix += strlen(buf);
- }
- }
- }
-
-
- static PARAM_STACK *PushParamStack(int tag_type)
- {
- int ix;
- PARAM_STACK *sp;
-
- sp = ¶m_stack[n_param_stack];
- if(n_param_stack < (N_PARAM_STACK-1))
- n_param_stack++;
-
- sp->type = tag_type;
- for(ix=0; ix<N_SPEECH_PARAM; ix++)
- {
- sp->parameter[ix] = -1;
- }
- return(sp);
- }
-
-
- static void PopParamStack(int tag_type, char *outbuf, int &outix)
- {
-
- int ix;
- int top = 0;
-
- if(tag_type >= SSML_CLOSE)
- tag_type -= SSML_CLOSE;
-
- for(ix=0; ix<n_param_stack; ix++)
- {
- if(param_stack[ix].type == tag_type)
- {
- top = ix;
- }
- }
- if(top > 0)
- {
- n_param_stack = top;
- }
- ProcessParamStack(outbuf, outix);
- }
-
-
-
- static wchar_t *GetSsmlAttribute(wchar_t *pw, const char *name)
- {
-
-
- int ix;
- static wchar_t empty[1] = {0};
-
- while(*pw != 0)
- {
- if(iswspace(pw[-1]))
- {
- ix = 0;
- while(*pw == name[ix])
- {
- pw++;
- ix++;
- }
- if(name[ix]==0)
- {
-
- while(iswspace(*pw)) pw++;
- if(*pw == '=') pw++;
- while(iswspace(*pw)) pw++;
- if((*pw == '"') || (*pw == '\''))
- return(pw+1);
- else
- return(empty);
- }
- }
- pw++;
- }
- return(NULL);
- }
-
-
- static int attrcmp(const wchar_t *string1, const char *string2)
- {
- int ix;
-
- if(string1 == NULL)
- return(1);
-
- for(ix=0; (string1[ix] == string2[ix]) && (string1[ix] != 0); ix++)
- {
- }
- if(((string1[ix]=='"') || (string1[ix]=='\'')) && (string2[ix]==0))
- return(0);
- return(1);
- }
-
-
- static int attrlookup(const wchar_t *string1, const MNEM_TAB *mtab)
- {
- int ix;
-
- for(ix=0; mtab[ix].mnem != NULL; ix++)
- {
- if(attrcmp(string1,mtab[ix].mnem) == 0)
- return(mtab[ix].value);
- }
- return(mtab[ix].value);
- }
-
-
- static int attrnumber(const wchar_t *pw, int default_value, int type)
- {
- int value = 0;
-
- if((pw == NULL) || !IsDigit09(*pw))
- return(default_value);
-
- while(IsDigit09(*pw))
- {
- value = value*10 + *pw++ - '0';
- }
- if((type==1) && (towlower(*pw)=='s'))
- {
-
- value *= 1000;
- }
- return(value);
- }
-
-
-
- static int attrcopy_utf8(char *buf, const wchar_t *pw, int len)
- {
-
- unsigned int c;
- int ix = 0;
- int n;
- int prev_c = 0;
-
- if(pw != NULL)
- {
- while((ix < (len-4)) && ((c = *pw++) != 0))
- {
- if((c=='"') && (prev_c != '\\'))
- break;
- n = utf8_out(c,&buf[ix]);
- ix += n;
- prev_c = c;
- }
- }
- buf[ix] = 0;
- return(ix);
- }
-
-
-
- static int attr_prosody_value(int param_type, const wchar_t *pw, int *value_out)
- {
- int sign = 0;
- wchar_t *tail;
- double value;
-
- while(iswspace(*pw)) pw++;
- if(*pw == '+')
- {
- pw++;
- sign = 1;
- }
- if(*pw == '-')
- {
- pw++;
- sign = -1;
- }
- value = (double)wcstod(pw,&tail);
- if(tail == pw)
- {
-
- *value_out = 100;
- return(2);
- }
-
- if(*tail == '%')
- {
- if(sign != 0)
- value = 100 + (sign * value);
- *value_out = (int)value;
- return(2);
- }
-
- if((tail[0]=='s') && (tail[1]=='t'))
- {
- double x;
-
- x = pow(double(2.0),double((value*sign)/12)) * 100;
- *value_out = (int)x;
- return(2);
- }
-
- if(param_type == espeakRATE)
- {
- if(sign == 0)
- *value_out = (int)(value * 100);
- else
- *value_out = 100 + (int)(sign * value * 100);
- return(2);
- }
-
- *value_out = (int)value;
- return(sign);
- }
-
-
- int AddNameData(const char *name, int wide)
- {
-
-
- int ix;
- int len;
- void *vp;
-
- if(wide)
- {
- len = (wcslen((const wchar_t *)name)+1)*sizeof(wchar_t);
- n_namedata = (n_namedata + sizeof(wchar_t) - 1) % sizeof(wchar_t);
- }
- else
- {
- len = strlen(name)+1;
- }
-
- if(namedata_ix+len >= n_namedata)
- {
-
- if((vp = realloc(namedata, namedata_ix+len + 1000)) == NULL)
- return(-1);
-
-
- namedata = (char *)vp;
- n_namedata = namedata_ix+len + 1000;
- }
- memcpy(&namedata[ix = namedata_ix],name,len);
- namedata_ix += len;
- return(ix);
- }
-
-
- void SetVoiceStack(espeak_VOICE *v, const char *variant_name)
- {
- SSML_STACK *sp;
- sp = &ssml_stack[0];
-
- if(v == NULL)
- {
- memset(sp,0,sizeof(ssml_stack[0]));
- return;
- }
- if(v->languages != NULL)
- strcpy(sp->language,v->languages);
- if(v->name != NULL)
- strncpy0(sp->voice_name, v->name, sizeof(sp->voice_name));
- sp->voice_variant_number = v->variant;
- sp->voice_age = v->age;
- sp->voice_gender = v->gender;
-
- if(memcmp(variant_name, "!v", 2) == 0)
- variant_name += 3;
- strncpy0(base_voice_variant_name, variant_name, sizeof(base_voice_variant_name));
- memcpy(&base_voice, ¤t_voice_selected, sizeof(base_voice));
- }
-
-
- static int GetVoiceAttributes(wchar_t *pw, int tag_type)
- {
-
-
-
-
-
-
- wchar_t *lang;
- wchar_t *gender;
- wchar_t *name;
- wchar_t *age;
- wchar_t *variant;
- int value;
- const char *new_voice_id;
- SSML_STACK *ssml_sp;
-
- static const MNEM_TAB mnem_gender[] = {
- {"male", 1},
- {"female", 2},
- {"neutral", 3},
- {NULL, 0}};
-
- if(tag_type & SSML_CLOSE)
- {
-
- if(n_ssml_stack > 1)
- {
- n_ssml_stack--;
- }
- }
- else
- {
-
- lang = GetSsmlAttribute(pw,"xml:lang");
-
- if(tag_type != SSML_VOICE)
- {
-
- name = NULL;
- variant = NULL;
- age = NULL;
- gender = NULL;
- }
- else
- {
- name = GetSsmlAttribute(pw,"name");
- variant = GetSsmlAttribute(pw,"variant");
- age = GetSsmlAttribute(pw,"age");
- gender = GetSsmlAttribute(pw,"gender");
- }
-
- if((tag_type != SSML_VOICE) && (lang==NULL))
- return(0);
-
- ssml_sp = &ssml_stack[n_ssml_stack++];
-
- attrcopy_utf8(ssml_sp->language,lang,sizeof(ssml_sp->language));
- attrcopy_utf8(ssml_sp->voice_name,name,sizeof(ssml_sp->voice_name));
- if((value = attrnumber(variant,1,0)) > 0)
- value--;
- ssml_sp->voice_variant_number = value;
- ssml_sp->voice_age = attrnumber(age,0,0);
- ssml_sp->voice_gender = attrlookup(gender,mnem_gender);
- ssml_sp->tag_type = tag_type;
- }
-
- new_voice_id = VoiceFromStack();
- if(strcmp(new_voice_id,current_voice_id) != 0)
- {
-
- strcpy(current_voice_id,new_voice_id);
- return(CLAUSE_BIT_VOICE);
- }
-
- return(0);
- }
-
-
- static void SetProsodyParameter(int param_type, wchar_t *attr1, PARAM_STACK *sp)
- {
- int value;
- int sign;
-
- static const MNEM_TAB mnem_volume[] = {
- {"default",100},
- {"silent",0},
- {"x-soft",30},
- {"soft",65},
- {"medium",100},
- {"loud",150},
- {"x-loud",230},
- {NULL, -1}};
-
- static const MNEM_TAB mnem_rate[] = {
- {"default",100},
- {"x-slow",60},
- {"slow",80},
- {"medium",100},
- {"fast",125},
- {"x-fast",160},
- {NULL, -1}};
-
- static const MNEM_TAB mnem_pitch[] = {
- {"default",100},
- {"x-low",70},
- {"low",85},
- {"medium",100},
- {"high",110},
- {"x-high",120},
- {NULL, -1}};
-
- static const MNEM_TAB mnem_range[] = {
- {"default",100},
- {"x-low",20},
- {"low",50},
- {"medium",100},
- {"high",140},
- {"x-high",180},
- {NULL, -1}};
-
- static const MNEM_TAB *mnem_tabs[5] = {
- NULL, mnem_rate, mnem_volume, mnem_pitch, mnem_range };
-
-
- if((value = attrlookup(attr1,mnem_tabs[param_type])) >= 0)
- {
-
- sp->parameter[param_type] = (param_stack[0].parameter[param_type] * value)/100;
- }
- else
- {
- sign = attr_prosody_value(param_type,attr1,&value);
-
- if(sign == 0)
- sp->parameter[param_type] = value;
- else
- if(sign == 2)
- {
-
- sp->parameter[param_type] = (speech_parameters[param_type] * value)/100;
- }
- else
- {
-
- sp->parameter[param_type] = speech_parameters[param_type] + (value*sign);
- }
- }
- }
-
-
- static int ReplaceKeyName(char *outbuf, int index, int &outix)
- {
-
- static MNEM_TAB keynames[] = {
- {"space ",0xe020},
- {"tab ", 0xe009},
- {"underscore ", 0xe05f},
- {"double-quote ", '"'},
- {NULL, 0}};
-
- int ix;
- int letter;
- char *p;
-
- p = &outbuf[index];
-
- if((letter = LookupMnem(keynames, p)) != 0)
- {
- ix = utf8_out(letter, p);
- outix = index + ix;
- return(letter);
- }
- return(0);
- }
-
-
- static int ProcessSsmlTag(wchar_t *xml_buf, char *outbuf, int &outix, int n_outbuf, int self_closing)
- {
-
-
-
- unsigned int ix;
- int index;
- int c;
- int tag_type;
- int value;
- int value2;
- int value3;
- int voice_change_flag;
- wchar_t *px;
- wchar_t *attr1;
- wchar_t *attr2;
- wchar_t *attr3;
- int terminator;
- char *uri;
- int param_type;
- char tag_name[40];
- char buf[80];
- PARAM_STACK *sp;
- SSML_STACK *ssml_sp;
-
- static const MNEM_TAB mnem_punct[] = {
- {"none", 1},
- {"all", 2},
- {"some", 3},
- {NULL, -1}};
-
- static const MNEM_TAB mnem_capitals[] = {
- {"no", 0},
- {"spelling", 2},
- {"icon", 1},
- {"pitch", 20},
- {NULL, -1}};
-
- static const MNEM_TAB mnem_interpret_as[] = {
- {"characters",SAYAS_CHARS},
- {"tts:char",SAYAS_SINGLE_CHARS},
- {"tts:key",SAYAS_KEY},
- {"tts:digits",SAYAS_DIGITS},
- {"telephone",SAYAS_DIGITS1},
- {NULL, -1}};
-
- static const MNEM_TAB mnem_sayas_format[] = {
- {"glyphs",1},
- {NULL, -1}};
-
- static const MNEM_TAB mnem_break[] = {
- {"none",0},
- {"x-weak",1},
- {"weak",2},
- {"medium",3},
- {"strong",4},
- {"x-strong",5},
- {NULL,-1}};
-
- static const MNEM_TAB mnem_emphasis[] = {
- {"none",1},
- {"reduced",2},
- {"moderate",3},
- {"strong",4},
- {"x-strong",5},
- {NULL,-1}};
-
- static const char *prosody_attr[5] = {
- NULL, "rate", "volume", "pitch", "range" };
-
- for(ix=0; ix<(sizeof(tag_name)-1); ix++)
- {
- if(((c = xml_buf[ix]) == 0) || iswspace(c))
- break;
- tag_name[ix] = tolower((char)c);
- }
- tag_name[ix] = 0;
-
- px = &xml_buf[ix];
-
- if(tag_name[0] == '/')
- {
-
- if((tag_type = LookupMnem(ssmltags,&tag_name[1])) != HTML_NOSPACE)
- {
- outbuf[outix++] = ' ';
- }
- tag_type += SSML_CLOSE;
- }
- else
- {
- if((tag_type = LookupMnem(ssmltags,tag_name)) != HTML_NOSPACE)
- {
-
- outbuf[outix++] = ' ';
- }
-
- if(self_closing && ignore_if_self_closing[tag_type])
- return(0);
- }
-
-
- voice_change_flag = 0;
- terminator = CLAUSE_NONE;
- ssml_sp = &ssml_stack[n_ssml_stack-1];
-
- switch(tag_type)
- {
- case SSML_STYLE:
- sp = PushParamStack(tag_type);
- attr1 = GetSsmlAttribute(px,"field");
- attr2 = GetSsmlAttribute(px,"mode");
-
-
- if(attrcmp(attr1,"punctuation")==0)
- {
- value = attrlookup(attr2,mnem_punct);
- sp->parameter[espeakPUNCTUATION] = value;
- }
- else
- if(attrcmp(attr1,"capital_letters")==0)
- {
- value = attrlookup(attr2,mnem_capitals);
- sp->parameter[espeakCAPITALS] = value;
- }
- ProcessParamStack(outbuf, outix);
- break;
-
- case SSML_PROSODY:
- sp = PushParamStack(tag_type);
-
-
- for(param_type=espeakRATE; param_type <= espeakRANGE; param_type++)
- {
- if((attr1 = GetSsmlAttribute(px,prosody_attr[param_type])) != NULL)
- {
- SetProsodyParameter(param_type, attr1, sp);
- }
- }
-
- ProcessParamStack(outbuf, outix);
- break;
-
- case SSML_EMPHASIS:
- sp = PushParamStack(tag_type);
- value = 3;
- if((attr1 = GetSsmlAttribute(px,"level")) != NULL)
- {
- value = attrlookup(attr1,mnem_emphasis);
- }
-
- if(translator->langopts.tone_language == 1)
- {
- static unsigned char emphasis_to_pitch_range[] = {50,50,40,70,90,100};
- static unsigned char emphasis_to_volume[] = {100,100,70,110,135,150};
-
- sp->parameter[espeakRANGE] = emphasis_to_pitch_range[value];
- sp->parameter[espeakVOLUME] = emphasis_to_volume[value];
- }
- else
- {
- static unsigned char emphasis_to_volume2[] = {100,100,75,100,120,150};
- sp->parameter[espeakVOLUME] = emphasis_to_volume2[value];
- sp->parameter[espeakEMPHASIS] = value;
- }
- ProcessParamStack(outbuf, outix);
- break;
-
- case SSML_STYLE + SSML_CLOSE:
- case SSML_PROSODY + SSML_CLOSE:
- case SSML_EMPHASIS + SSML_CLOSE:
- PopParamStack(tag_type, outbuf, outix);
- break;
-
- case SSML_SAYAS:
- attr1 = GetSsmlAttribute(px,"interpret-as");
- attr2 = GetSsmlAttribute(px,"format");
- attr3 = GetSsmlAttribute(px,"detail");
- value = attrlookup(attr1,mnem_interpret_as);
- value2 = attrlookup(attr2,mnem_sayas_format);
- if(value2 == 1)
- value = SAYAS_GLYPHS;
-
- value3 = attrnumber(attr3,0,0);
-
- if(value == SAYAS_DIGITS)
- {
- if(value3 <= 1)
- value = SAYAS_DIGITS1;
- else
- value = SAYAS_DIGITS + value3;
- }
-
- sprintf(buf,"%c%dY",CTRL_EMBEDDED,value);
- strcpy(&outbuf[outix],buf);
- outix += strlen(buf);
-
- sayas_start = outix;
- sayas_mode = value;
- break;
-
- case SSML_SAYAS + SSML_CLOSE:
- if(sayas_mode == SAYAS_KEY)
- {
- outbuf[outix] = 0;
- ReplaceKeyName(outbuf, sayas_start, outix);
- }
-
- outbuf[outix++] = CTRL_EMBEDDED;
- outbuf[outix++] = 'Y';
- sayas_mode = 0;
- break;
-
- case SSML_SUB:
- if((attr1 = GetSsmlAttribute(px,"alias")) != NULL)
- {
-
- ignore_text = 1;
- outix += attrcopy_utf8(&outbuf[outix],attr1,n_outbuf-outix);
- }
- break;
-
- case SSML_IGNORE_TEXT:
- ignore_text = 1;
- break;
-
- case SSML_SUB + SSML_CLOSE:
- case SSML_IGNORE_TEXT + SSML_CLOSE:
- ignore_text = 0;
- break;
-
- case SSML_MARK:
- if((attr1 = GetSsmlAttribute(px,"name")) != NULL)
- {
-
- attrcopy_utf8(buf,attr1,sizeof(buf));
-
- if(strcmp(skip_marker,buf)==0)
- {
-
- clear_skipping_text = 1;
- skip_marker[0] = 0;
- return(CLAUSE_NONE);
- }
-
- if((index = AddNameData(buf,0)) >= 0)
- {
- sprintf(buf,"%c%dM",CTRL_EMBEDDED,index);
- strcpy(&outbuf[outix],buf);
- outix += strlen(buf);
- }
- }
- break;
-
- case SSML_AUDIO:
- sp = PushParamStack(tag_type);
-
- if((attr1 = GetSsmlAttribute(px,"src")) != NULL)
- {
- char fname[256];
- attrcopy_utf8(buf,attr1,sizeof(buf));
-
- if(uri_callback == NULL)
- {
- if((xmlbase != NULL) && (buf[0] != '/'))
- {
- sprintf(fname,"%s/%s",xmlbase,buf);
- index = LoadSoundFile2(fname);
- }
- else
- {
- index = LoadSoundFile2(buf);
- }
- if(index >= 0)
- {
- sprintf(buf,"%c%dI",CTRL_EMBEDDED,index);
- strcpy(&outbuf[outix],buf);
- outix += strlen(buf);
- sp->parameter[espeakSILENCE] = 1;
- }
- }
- else
- {
- if((index = AddNameData(buf,0)) >= 0)
- {
- uri = &namedata[index];
- if(uri_callback(1,uri,xmlbase) == 0)
- {
- sprintf(buf,"%c%dU",CTRL_EMBEDDED,index);
- strcpy(&outbuf[outix],buf);
- outix += strlen(buf);
- sp->parameter[espeakSILENCE] = 1;
- }
- }
- }
- }
- ProcessParamStack(outbuf, outix);
-
- if(self_closing)
- PopParamStack(tag_type, outbuf, outix);
- else
- audio_text = 1;
- return(CLAUSE_NONE);
-
- case SSML_AUDIO + SSML_CLOSE:
- PopParamStack(tag_type, outbuf, outix);
- audio_text = 0;
- return(CLAUSE_NONE);
-
- case SSML_BREAK:
- value = 21;
- terminator = CLAUSE_NONE;
-
- if((attr1 = GetSsmlAttribute(px,"strength")) != NULL)
- {
- static int break_value[6] = {0,7,14,21,40,80};
- value = attrlookup(attr1,mnem_break);
- if(value < 3)
- {
-
- sprintf(&outbuf[outix],"%c%dB",CTRL_EMBEDDED,value);
- outix += 3;
- terminator = 0;
- }
- value = break_value[value];
- }
- if((attr2 = GetSsmlAttribute(px,"time")) != NULL)
- {
- value = (attrnumber(attr2,0,1) * 25) / speed.pause_factor;
-
- if(terminator == 0)
- terminator = CLAUSE_NONE;
- }
- if(terminator)
- {
- if(value > 0xfff)
- value = 0xfff;
- return(terminator + value);
- }
- break;
-
- case SSML_SPEAK:
- if((attr1 = GetSsmlAttribute(px,"xml:base")) != NULL)
- {
- attrcopy_utf8(buf,attr1,sizeof(buf));
- if((index = AddNameData(buf,0)) >= 0)
- {
- xmlbase = &namedata[index];
- }
- }
- if(GetVoiceAttributes(px, tag_type) == 0)
- return(0);
- return(CLAUSE_VOICE);
-
- case SSML_VOICE:
- if(GetVoiceAttributes(px, tag_type) == 0)
- return(0);
- return(CLAUSE_VOICE);
-
- case SSML_SPEAK + SSML_CLOSE:
-
- while((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_SPEAK))
- {
- n_ssml_stack--;
- }
- return(CLAUSE_PERIOD + GetVoiceAttributes(px, tag_type));
-
- case SSML_VOICE + SSML_CLOSE:
-
- while((n_ssml_stack > 1) && (ssml_stack[n_ssml_stack-1].tag_type != SSML_VOICE))
- {
- n_ssml_stack--;
- }
-
- terminator=0;
- return(terminator + GetVoiceAttributes(px, tag_type));
-
- case HTML_BREAK:
- case HTML_BREAK + SSML_CLOSE:
- return(CLAUSE_COLON);
-
- case SSML_SENTENCE:
- if(ssml_sp->tag_type == SSML_SENTENCE)
- {
-
- voice_change_flag = GetVoiceAttributes(px, SSML_SENTENCE+SSML_CLOSE);
- }
- voice_change_flag |= GetVoiceAttributes(px, tag_type);
- return(CLAUSE_PARAGRAPH + voice_change_flag);
-
-
- case SSML_PARAGRAPH:
- if(ssml_sp->tag_type == SSML_SENTENCE)
- {
-
- voice_change_flag = GetVoiceAttributes(px, SSML_SENTENCE+SSML_CLOSE);
- }
- if(ssml_sp->tag_type == SSML_PARAGRAPH)
- {
-
- voice_change_flag |= GetVoiceAttributes(px, SSML_PARAGRAPH+SSML_CLOSE);
- }
- voice_change_flag |= GetVoiceAttributes(px, tag_type);
- return(CLAUSE_PARAGRAPH + voice_change_flag);
-
-
- case SSML_SENTENCE + SSML_CLOSE:
- if(ssml_sp->tag_type == SSML_SENTENCE)
- {
-
- voice_change_flag = GetVoiceAttributes(px, tag_type);
- }
- return(CLAUSE_PERIOD + voice_change_flag);
-
-
- case SSML_PARAGRAPH + SSML_CLOSE:
- if((ssml_sp->tag_type == SSML_SENTENCE) || (ssml_sp->tag_type == SSML_PARAGRAPH))
- {
-
-
- return(GetVoiceAttributes(px, tag_type) + CLAUSE_PARAGRAPH);
- }
- return(CLAUSE_PARAGRAPH);
- }
- return(0);
- }
-
-
- static void RemoveChar(char *p)
- {
-
- int c;
-
- memset(p, ' ', utf8_in(&c, p));
- }
-
-
- static MNEM_TAB xml_char_mnemonics[] = {
- {"gt",'>'},
- {"lt", 0xe000 + '<'},
- {"amp", '&'},
- {"quot", '"'},
- {"nbsp", ' '},
- {"apos", '\''},
- {NULL,-1}};
-
-
- int ReadClause(Translator *tr, FILE *f_in, char *buf, short *charix, int *charix_top, int n_buf, int *tone_type, char *voice_change)
- {
-
- int c1=' ';
- int c2;
- int cprev=' ';
- int cprev2=' ';
- int c_next;
- int parag;
- int ix = 0;
- int j;
- int nl_count;
- int linelength = 0;
- int phoneme_mode = 0;
- int n_xml_buf;
- int terminator;
- int punct;
- int found;
- int any_alnum = 0;
- int self_closing;
- int punct_data = 0;
- int is_end_clause;
- int announced_punctuation = 0;
- int stressed_word = 0;
- int end_clause_after_tag = 0;
- int end_clause_index = 0;
- wchar_t xml_buf[N_XML_BUF+1];
-
- #define N_XML_BUF2 20
- char xml_buf2[N_XML_BUF2+2];
- static char ungot_string[N_XML_BUF2+4];
- static int ungot_string_ix = -1;
-
- if(clear_skipping_text)
- {
- skipping_text = 0;
- clear_skipping_text = 0;
- }
-
- tr->phonemes_repeat_count = 0;
- tr->clause_upper_count = 0;
- tr->clause_lower_count = 0;
- end_of_input = 0;
- *tone_type = 0;
- *voice_change = 0;
-
- f_input = f_in;
-
- if(ungot_word != NULL)
- {
- strcpy(buf,ungot_word);
- ix += strlen(ungot_word);
- ungot_word = NULL;
- }
-
- if(ungot_char2 != 0)
- {
- c2 = ungot_char2;
- }
- else
- {
- c2 = GetC();
- }
-
- while(!Eof() || (ungot_char != 0) || (ungot_char2 != 0) || (ungot_string_ix >= 0))
- {
- if(!iswalnum(c1))
- {
- if((end_character_position > 0) && (count_characters > end_character_position))
- {
- end_of_input = 1;
- return(CLAUSE_EOF);
- }
-
- if((skip_characters > 0) && (count_characters >= skip_characters))
- {
-
-
- clear_skipping_text = 1;
- skip_characters = 0;
- UngetC(c2);
- return(CLAUSE_NONE);
- }
- }
-
- cprev2 = cprev;
- cprev = c1;
- c1 = c2;
-
- if(ungot_string_ix >= 0)
- {
- if(ungot_string[ungot_string_ix] == 0)
- ungot_string_ix = -1;
- }
-
- if((ungot_string_ix == 0) && (ungot_char2 == 0))
- {
- c1 = ungot_string[ungot_string_ix++];
- }
- if(ungot_string_ix >= 0)
- {
- c2 = ungot_string[ungot_string_ix++];
- }
- else
- {
- c2 = GetC();
-
- if(Eof())
- {
- c2 = ' ';
- }
- }
- ungot_char2 = 0;
-
- if((option_ssml) && (phoneme_mode==0))
- {
- if((ssml_ignore_l_angle != '&') && (c1 == '&') && ((c2=='#') || ((c2 >= 'a') && (c2 <= 'z'))))
- {
- n_xml_buf = 0;
- c1 = c2;
- while(!Eof() && (iswalnum(c1) || (c1=='#')) && (n_xml_buf < N_XML_BUF2))
- {
- xml_buf2[n_xml_buf++] = c1;
- c1 = GetC();
- }
- xml_buf2[n_xml_buf] = 0;
- c2 = GetC();
- sprintf(ungot_string,"%s%c%c",&xml_buf2[0],c1,c2);
-
- if(c1 == ';')
- {
- if(xml_buf2[0] == '#')
- {
-
- if(xml_buf2[1] == 'x')
- found = sscanf(&xml_buf2[2],"%x",(unsigned int *)(&c1));
- else
- found = sscanf(&xml_buf2[1],"%d",&c1);
- }
- else
- {
- if((found = LookupMnem(xml_char_mnemonics,xml_buf2)) != -1)
- {
- c1 = found;
- if(c2 == 0)
- c2 = ' ';
- }
- }
- }
- else
- {
- found = -1;
- }
-
- if(found <= 0)
- {
- ungot_string_ix = 0;
- c1 = '&';
- c2 = ' ';
- }
-
- if((c1 <= 0x20) && ((sayas_mode == SAYAS_SINGLE_CHARS) || (sayas_mode == SAYAS_KEY)))
- {
- c1 += 0xe000;
- }
- }
- else
- if((c1 == '<') && (ssml_ignore_l_angle != '<'))
- {
- if(c2 == '!')
- {
-
- while(!Eof() && (c1 != '>'))
- {
- c1 = GetC();
- }
- c2 = ' ';
- }
- else
- if((c2 == '/') || iswalpha2(c2))
- {
-
- if(ix > (n_buf - 20))
- {
-
- UngetC(c2);
- ungot_char2 = c1;
- buf[ix] = ' ';
- buf[ix+1] = 0;
- return(CLAUSE_NONE);
- }
-
-
- n_xml_buf = 0;
- c1 = c2;
- while(!Eof() && (c1 != '>') && (n_xml_buf < N_XML_BUF))
- {
- xml_buf[n_xml_buf++] = c1;
- c1 = GetC();
- }
- xml_buf[n_xml_buf] = 0;
- c2 = ' ';
-
- self_closing = 0;
- if(xml_buf[n_xml_buf-1] == '/')
- {
-
- xml_buf[n_xml_buf-1] = ' ';
- self_closing = 1;
- }
-
- terminator = ProcessSsmlTag(xml_buf,buf,ix,n_buf,self_closing);
-
- if(terminator != 0)
- {
- if(end_clause_after_tag)
- ix = end_clause_index;
-
- buf[ix] = ' ';
- buf[ix++] = 0;
-
- if(terminator & CLAUSE_BIT_VOICE)
- {
- strcpy(voice_change, current_voice_id);
- }
- return(terminator);
- }
- c1 = ' ';
- c2 = GetC();
- continue;
- }
- }
- }
- ssml_ignore_l_angle=0;
-
- if(ignore_text)
- continue;
-
- if((c2=='\n') && (option_linelength == -1))
- {
-
- if((punct = lookupwchar(punct_chars,c1)) == 0)
- {
- charix[ix] = count_characters - clause_start_char;
- *charix_top = ix;
- ix += utf8_out(c1,&buf[ix]);
- terminator = CLAUSE_PERIOD;
- }
- else
- {
- terminator = punct_attributes[punct];
- }
- buf[ix] = ' ';
- buf[ix+1] = 0;
- return(terminator);
- }
-
- if((c1 == CTRL_EMBEDDED) || (c1 == ctrl_embedded))
- {
-
- if(c2 == 'V')
- {
- buf[ix++] = 0;
- while(!iswspace(c1 = GetC()) && !Eof() && (ix < (n_buf-1)))
- buf[ix++] = c1;
- buf[ix++] = 0;
- return(CLAUSE_VOICE);
- }
- else
- if(c2 == 'B')
- {
-
-
- strcpy(&buf[ix]," ");
- ix += 3;
-
- if((c2 = GetC()) == '0')
- option_punctuation = 0;
- else
- {
- option_punctuation = 1;
- option_punctlist[0] = 0;
- if(c2 != '1')
- {
-
- j = 0;
- while(!iswspace(c2) && !Eof())
- {
- option_punctlist[j++] = c2;
- c2 = GetC();
- buf[ix++] = ' ';
- }
- option_punctlist[j] = 0;
- option_punctuation = 2;
- }
- }
- c2 = GetC();
- continue;
- }
- }
-
- linelength++;
-
- if(iswalnum(c1))
- any_alnum = 1;
- else
- {
- if(stressed_word)
- {
- stressed_word = 0;
- c1 = CHAR_EMPHASIS;
- UngetC(c2);
- c2 = ' ';
- }
-
- if((j = lookupwchar2(tr->chars_ignore,c1)) != 0)
- {
- if(j == 1)
- {
-
- continue;
- }
- c1 = j;
- }
-
- if(c1 == 0xf0b)
- c1 = ' ';
-
- if(iswspace(c1))
- {
- char *p_word;
-
- if(tr->translator_name == 0x6a626f)
- {
-
-
- p_word = &buf[ix-1];
- if(p_word[0] == 'i')
- {
- if(p_word[-1] == '.')
- p_word--;
- if(p_word[-1] == ' ')
- {
- ungot_word = "i ";
- UngetC(c2);
- p_word[0] = 0;
- return(CLAUSE_PERIOD);
- }
- }
- }
- }
-
- if(c1 == 0xd4d)
- {
-
- if(c2 == 0x200d)
- {
- c1 = 0xd4e;
- }
- }
- }
-
- if(iswupper2(c1))
- {
- tr->clause_upper_count++;
- if((option_capitals == 2) && (sayas_mode == 0) && !iswupper2(cprev))
- {
- char text_buf[40];
- char text_buf2[30];
- if(LookupSpecial(tr, "_cap", text_buf2) != NULL)
- {
- sprintf(text_buf,"%s",text_buf2);
- j = strlen(text_buf);
- if((ix + j) < n_buf)
- {
- strcpy(&buf[ix],text_buf);
- ix += j;
- }
- }
- }
- }
- else
- if(iswalpha2(c1))
- tr->clause_lower_count++;
-
- if(option_phoneme_input)
- {
- if(phoneme_mode > 0)
- phoneme_mode--;
- else
- if((c1 == '[') && (c2 == '['))
- phoneme_mode = -1;
- else
- if((c1 == ']') && (c2 == ']'))
- phoneme_mode = 2;
- }
-
- if(c1 == '\n')
- {
- parag = 0;
-
-
- while(!Eof() && iswspace(c2))
- {
- if(c2 == '\n')
- parag++;
- c2 = GetC();
- }
- if(parag > 0)
- {
-
- UngetC(c2);
-
- if(end_clause_after_tag)
- {
- RemoveChar(&buf[end_clause_index]);
- }
- buf[ix] = ' ';
- buf[ix+1] = 0;
- if(parag > 3)
- parag = 3;
- if(option_ssml) parag=1;
- return((CLAUSE_PARAGRAPH-30) + 30*parag);
- }
-
- if(linelength <= option_linelength)
- {
-
- UngetC(c2);
- buf[ix] = ' ';
- buf[ix+1] = 0;
- return(CLAUSE_COLON);
- }
-
- linelength = 0;
- }
-
- announced_punctuation = 0;
-
- if((phoneme_mode==0) && (sayas_mode==0))
- {
- is_end_clause = 0;
-
- if(end_clause_after_tag)
- {
-
-
-
-
- if(!iswspace(c1))
- {
- if(!IsAlpha(c1) || !iswlower2(c1))
-
- {
- UngetC(c2);
- ungot_char2 = c1;
- buf[end_clause_index] = ' ';
- buf[end_clause_index+1] = 0;
- return(end_clause_after_tag);
- }
- end_clause_after_tag = 0;
- }
- }
-
- if((c1 == '.') && (c2 == '.'))
- {
- while((c_next = GetC()) == '.')
- {
-
- c1 = 0x2026;
- c2 = ' ';
- }
- if(c1 == 0x2026)
- c2 = c_next;
- else
- UngetC(c_next);
- }
-
- punct_data = 0;
- if((punct = lookupwchar(punct_chars,c1)) != 0)
- {
- punct_data = punct_attributes[punct];
-
- if(punct_data & PUNCT_IN_WORD)
- {
-
- stressed_word = 1;
- *tone_type = punct_data >> 12 & 0xf;
- continue;
- }
-
- if((iswspace(c2) || (punct_data & 0x8000) || IsBracket(c2) || (c2=='?') || Eof() || (c2 == ctrl_embedded)))
-
- {
-
- is_end_clause = 1;
- }
- }
-
-
- if(c1 == 0xe000+'<') c1 = '<';
- if(option_punctuation && iswpunct(c1) && (audio_text == 0))
- {
-
-
- if((option_punctuation == 1) || (wcschr(option_punctlist,c1) != NULL))
- {
- tr->phonemes_repeat_count = 0;
- if((terminator = AnnouncePunctuation(tr, c1, &c2, buf, &ix, is_end_clause)) >= 0)
- return(terminator);
- announced_punctuation = c1;
- }
- }
-
- if((punct_data & PUNCT_SAY_NAME) && (announced_punctuation == 0))
- {
-
- char *p2;
-
- p2 = &buf[ix];
- sprintf(p2,"%s",LookupCharName(tr, c1, 1));
- if(p2[0] != 0)
- {
- ix += strlen(p2);
- announced_punctuation = c1;
- punct_data = punct_data & ~CLAUSE_BITS_INTONATION;
- }
- }
-
- if(is_end_clause)
- {
- nl_count = 0;
- c_next = c2;
-
- if(iswspace(c_next))
- {
- while(!Eof() && iswspace(c_next))
- {
- if(c_next == '\n')
- nl_count++;
- c_next = GetC();
- }
- }
-
- if((c1 == '.') && (nl_count < 2))
- {
- punct_data |= CLAUSE_DOT;
- }
-
- if(nl_count==0)
- {
- if((c1 == ',') && (cprev == '.') && (tr->translator_name == L('h','u')) && iswdigit(cprev2) && (iswdigit(c_next) || (iswlower2(c_next))))
- {
-
- c1 = CHAR_COMMA_BREAK;
- is_end_clause = 0;
- }
-
- if(c1 == '.')
- {
- if((tr->langopts.numbers & NUM_ORDINAL_DOT) &&
- (iswdigit(cprev) || (IsRomanU(cprev) && (IsRomanU(cprev2) || iswspace(cprev2)))))
- {
-
- if(!iswdigit(cprev))
- {
- is_end_clause = 0;
- }
- else
- {
- if (iswlower2(c_next) || (c_next=='-'))
- is_end_clause = 0;
- }
- }
- else
- if(c_next == '\'')
- {
- is_end_clause = 0;
- }
- if(iswlower2(c_next))
- {
-
-
- is_end_clause = 0;
- }
- if(any_alnum==0)
- {
-
-
- c1 = ' ';
- is_end_clause = 0;
- }
- }
- else
- {
- if(any_alnum==0)
- {
-
- is_end_clause = 0;
- }
- }
-
- if(is_end_clause && (c1 == '.') && (c_next == '<') && option_ssml)
- {
-
- is_end_clause = 0;
- end_clause_index = ix;
- end_clause_after_tag = punct_data;
- }
- }
-
- if(is_end_clause)
- {
- UngetC(c_next);
- buf[ix] = ' ';
- buf[ix+1] = 0;
-
- if(iswdigit(cprev) && !IsAlpha(c_next))
- {
- punct_data &= ~CLAUSE_DOT;
- }
- if(nl_count > 1)
- {
- if((punct_data == CLAUSE_QUESTION) || (punct_data == CLAUSE_EXCLAMATION))
- return(punct_data + 35);
- return(CLAUSE_PARAGRAPH);
- }
- return(punct_data);
- }
- else
- {
- if(!Eof())
- {
- if(iswspace(c2))
- UngetC(c_next);
- }
- }
- }
- }
-
- if(speech_parameters[espeakSILENCE]==1)
- continue;
-
- if(c1 == announced_punctuation)
- {
-
-
- if(IsBracket(c1))
- {
- c1 = 0xe000 + '(';
- }
- else
- if(c1 != '-')
- {
- c1 = ' ';
- }
- }
-
- j = ix+1;
-
- if(c1 == 0xe000 + '<') c1 = '<';
-
- ix += utf8_out(c1,&buf[ix]);
- if(!iswspace(c1) && !IsBracket(c1))
- {
- charix[ix] = count_characters - clause_start_char;
- while(j < ix)
- charix[j++] = -1;
- }
- *charix_top = ix;
-
- if(((ix > (n_buf-75)) && !IsAlpha(c1) && !iswdigit(c1)) || (ix >= (n_buf-4)))
- {
-
-
-
- buf[ix] = ' ';
- buf[ix+1] = 0;
- UngetC(c2);
- return(CLAUSE_NONE);
- }
- }
-
- if(stressed_word)
- {
- ix += utf8_out(CHAR_EMPHASIS, &buf[ix]);
- }
- if(end_clause_after_tag)
- {
- RemoveChar(&buf[end_clause_index]);
- }
- buf[ix] = ' ';
- buf[ix+1] = 0;
- return(CLAUSE_EOF);
- }
-
-
- void InitNamedata(void)
- {
- namedata_ix = 0;
- if(namedata != NULL)
- {
- free(namedata);
- namedata = NULL;
- n_namedata = 0;
- }
- }
-
-
- void InitText2(void)
- {
- int param;
-
- ungot_char = 0;
- ungot_char2 = 0;
-
- n_ssml_stack =1;
- n_param_stack = 1;
- ssml_stack[0].tag_type = 0;
-
- for(param=0; param<N_SPEECH_PARAM; param++)
- speech_parameters[param] = param_stack[0].parameter[param];
-
- option_punctuation = speech_parameters[espeakPUNCTUATION];
- option_capitals = speech_parameters[espeakCAPITALS];
-
- current_voice_id[0] = 0;
-
- ignore_text = 0;
- audio_text = 0;
- clear_skipping_text = 0;
- count_characters = -1;
- sayas_mode = 0;
-
- xmlbase = NULL;
- }
|