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.

espeak.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /***************************************************************************
  2. * Copyright (C) 2006 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #ifndef NEED_GETOPT
  23. #include <getopt.h>
  24. #endif
  25. #include <time.h>
  26. #include <sys/stat.h>
  27. #include "speak_lib.h"
  28. // This version of the command-line speak program uses the
  29. // libespeak.so.1 library
  30. static const char *help_text =
  31. "\nespeak [options] [\"<words>\"]\n\n"
  32. "-f <text file> Text file to speak\n"
  33. "--stdin Read text input from stdin instead of a file\n\n"
  34. "If neither -f nor --stdin, then <words> are spoken, or if none then text\n"
  35. "is spoken from stdin, each line separately.\n\n"
  36. "-a <integer>\n"
  37. "\t Amplitude, 0 to 200, default is 100\n"
  38. "-g <integer>\n"
  39. "\t Word gap. Pause between words, units of 10mS at the default speed\n"
  40. "-k <integer>\n"
  41. "\t Indicate capital letters with: 1=sound, 2=the word \"capitals\",\n"
  42. "\t higher values indicate a pitch increase (try -k20).\n"
  43. "-l <integer>\n"
  44. "\t Line length. If not zero (which is the default), consider\n"
  45. "\t lines less than this length as end-of-clause\n"
  46. "-p <integer>\n"
  47. "\t Pitch adjustment, 0 to 99, default is 50\n"
  48. "-s <integer>\n"
  49. "\t Speed in words per minute, 80 to 450, default is 175\n"
  50. "-v <voice name>\n"
  51. "\t Use voice file of this name from espeak-data/voices\n"
  52. "-w <wave file name>\n"
  53. "\t Write speech to this WAV file, rather than speaking it directly\n"
  54. "-b\t Input text encoding, 1=UTF8, 2=8 bit, 4=16 bit \n"
  55. "-m\t Interpret SSML markup, and ignore other < > tags\n"
  56. "-q\t Quiet, don't produce any speech (may be useful with -x)\n"
  57. "-x\t Write phoneme mnemonics to stdout\n"
  58. "-X\t Write phonemes mnemonics and translation trace to stdout\n"
  59. "-z\t No final sentence pause at the end of the text\n"
  60. "--compile=<voice name>\n"
  61. "\t Compile pronunciation rules and dictionary from the current\n"
  62. "\t directory. <voice name> specifies the language\n"
  63. "--ipa Write phonemes to stdout using International Phonetic Alphabet\n"
  64. "--path=\"<path>\"\n"
  65. "\t Specifies the directory containing the espeak-data directory\n"
  66. "--pho Write mbrola phoneme data (.pho) to stdout or to the file in --phonout\n"
  67. "--phonout=\"<filename>\"\n"
  68. "\t Write phoneme output from -x -X --ipa and --pho to this file\n"
  69. "--punct=\"<characters>\"\n"
  70. "\t Speak the names of punctuation characters during speaking. If\n"
  71. "\t =<characters> is omitted, all punctuation is spoken.\n"
  72. "--split=\"<minutes>\"\n"
  73. "\t Starts a new WAV file every <minutes>. Used with -w\n"
  74. "--stdout Write speech output to stdout\n"
  75. "--voices=<language>\n"
  76. "\t List the available voices for the specified language.\n"
  77. "\t If <language> is omitted, then list all voices.\n";
  78. int samplerate;
  79. int quiet = 0;
  80. unsigned int samples_total = 0;
  81. unsigned int samples_split = 0;
  82. unsigned int samples_split_seconds = 0;
  83. unsigned int wavefile_count = 0;
  84. FILE *f_wavfile = NULL;
  85. char filetype[5];
  86. char wavefile[200];
  87. int GetFileLength(const char *filename)
  88. {//====================================
  89. struct stat statbuf;
  90. if(stat(filename,&statbuf) != 0)
  91. return(0);
  92. if((statbuf.st_mode & S_IFMT) == S_IFDIR)
  93. return(-2); // a directory
  94. return(statbuf.st_size);
  95. } // end of GetFileLength
  96. void strncpy0(char *dest, const char *source, int size)
  97. {//====================================================
  98. if(source!=NULL)
  99. {
  100. strncpy(dest,source,size);
  101. dest[size-1] = 0;
  102. }
  103. }
  104. void DisplayVoices(FILE *f_out, char *language)
  105. {//============================================
  106. int ix;
  107. const char *p;
  108. int len;
  109. int count;
  110. const espeak_VOICE *v;
  111. const char *lang_name;
  112. char age_buf[12];
  113. const espeak_VOICE **voices;
  114. espeak_VOICE voice_select;
  115. static char genders[4] = {' ','M','F',' '};
  116. if((language != NULL) && (language[0] != 0))
  117. {
  118. // display only voices for the specified language, in order of priority
  119. voice_select.languages = language;
  120. voice_select.age = 0;
  121. voice_select.gender = 0;
  122. voice_select.name = NULL;
  123. voices = espeak_ListVoices(&voice_select);
  124. }
  125. else
  126. {
  127. voices = espeak_ListVoices(NULL);
  128. }
  129. fprintf(f_out,"Pty Language Age/Gender VoiceName File Other Langs\n");
  130. for(ix=0; (v = voices[ix]) != NULL; ix++)
  131. {
  132. count = 0;
  133. p = v->languages;
  134. while(*p != 0)
  135. {
  136. len = strlen(p+1);
  137. lang_name = p+1;
  138. if(v->age == 0)
  139. strcpy(age_buf," ");
  140. else
  141. sprintf(age_buf,"%3d",v->age);
  142. if(count==0)
  143. {
  144. fprintf(f_out,"%2d %-12s%s%c %-17s %-11s ",
  145. p[0],lang_name,age_buf,genders[v->gender],v->name,v->identifier);
  146. }
  147. else
  148. {
  149. fprintf(f_out,"(%s %d)",lang_name,p[0]);
  150. }
  151. count++;
  152. p += len+2;
  153. }
  154. fputc('\n',f_out);
  155. }
  156. } // end of DisplayVoices
  157. static void Write4Bytes(FILE *f, int value)
  158. {//=================================
  159. // Write 4 bytes to a file, least significant first
  160. int ix;
  161. for(ix=0; ix<4; ix++)
  162. {
  163. fputc(value & 0xff,f);
  164. value = value >> 8;
  165. }
  166. }
  167. int OpenWavFile(char *path, int rate)
  168. //===================================
  169. {
  170. static unsigned char wave_hdr[44] = {
  171. 'R','I','F','F',0x24,0xf0,0xff,0x7f,'W','A','V','E','f','m','t',' ',
  172. 0x10,0,0,0,1,0,1,0, 9,0x3d,0,0,0x12,0x7a,0,0,
  173. 2,0,0x10,0,'d','a','t','a', 0x00,0xf0,0xff,0x7f};
  174. if(path == NULL)
  175. return(2);
  176. if(path[0] == 0)
  177. return(0);
  178. if(strcmp(path,"stdout")==0)
  179. f_wavfile = stdout;
  180. else
  181. f_wavfile = fopen(path,"wb");
  182. if(f_wavfile == NULL)
  183. {
  184. fprintf(stderr,"Can't write to: '%s'\n",path);
  185. return(1);
  186. }
  187. fwrite(wave_hdr,1,24,f_wavfile);
  188. Write4Bytes(f_wavfile,rate);
  189. Write4Bytes(f_wavfile,rate * 2);
  190. fwrite(&wave_hdr[32],1,12,f_wavfile);
  191. return(0);
  192. } // end of OpenWavFile
  193. static void CloseWavFile()
  194. //========================
  195. {
  196. unsigned int pos;
  197. if((f_wavfile==NULL) || (f_wavfile == stdout))
  198. return;
  199. fflush(f_wavfile);
  200. pos = ftell(f_wavfile);
  201. fseek(f_wavfile,4,SEEK_SET);
  202. Write4Bytes(f_wavfile,pos - 8);
  203. fseek(f_wavfile,40,SEEK_SET);
  204. Write4Bytes(f_wavfile,pos - 44);
  205. fclose(f_wavfile);
  206. f_wavfile = NULL;
  207. } // end of CloseWavFile
  208. static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events)
  209. {//========================================================================
  210. char fname[210];
  211. if(quiet) return(0); // -q quiet mode
  212. if(wav == NULL)
  213. {
  214. CloseWavFile();
  215. return(0);
  216. }
  217. while(events->type != 0)
  218. {
  219. if(events->type == espeakEVENT_SAMPLERATE)
  220. {
  221. samplerate = events->id.number;
  222. samples_split = samples_split_seconds * samplerate;
  223. }
  224. else
  225. if(events->type == espeakEVENT_SENTENCE)
  226. {
  227. // start a new WAV file when the limit is reached, at this sentence boundary
  228. if((samples_split > 0) && (samples_total > samples_split))
  229. {
  230. CloseWavFile();
  231. samples_total = 0;
  232. wavefile_count++;
  233. }
  234. }
  235. events++;
  236. }
  237. if(f_wavfile == NULL)
  238. {
  239. if(samples_split > 0)
  240. {
  241. sprintf(fname,"%s_%.2d%s",wavefile,wavefile_count+1,filetype);
  242. if(OpenWavFile(fname, samplerate) != 0)
  243. return(1);
  244. }
  245. else
  246. {
  247. if(OpenWavFile(wavefile, samplerate) != 0)
  248. return(1);
  249. }
  250. }
  251. if(numsamples > 0)
  252. {
  253. samples_total += numsamples;
  254. fwrite(wav,numsamples*2,1,f_wavfile);
  255. }
  256. return(0);
  257. }
  258. static void PrintVersion()
  259. {//=======================
  260. const char *version;
  261. const char *path_data;
  262. espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, espeakINITIALIZE_DONT_EXIT);
  263. version = espeak_Info(&path_data);
  264. printf("eSpeak text-to-speech: %s Data at: %s\n", version, path_data);
  265. }
  266. #ifdef NEED_GETOPT
  267. struct option {
  268. char *name;
  269. int has_arg;
  270. int *flag;
  271. int val;
  272. };
  273. int optind;
  274. static int optional_argument;
  275. static const char *arg_opts = "abfgklpsvw"; // which options have arguments
  276. static char *opt_string="";
  277. #define no_argument 0
  278. #define required_argument 1
  279. #define optional_argument 2
  280. #endif
  281. int main (int argc, char **argv)
  282. //==============================
  283. {
  284. static struct option long_options[] =
  285. {
  286. /* These options set a flag. */
  287. // {"verbose", no_argument, &verbose_flag, 1},
  288. // {"brief", no_argument, &verbose_flag, 0},
  289. /* These options don't set a flag.
  290. We distinguish them by their indices. */
  291. {"help", no_argument, 0, 'h'},
  292. {"stdin", no_argument, 0, 0x100},
  293. {"compile-debug", optional_argument, 0, 0x101},
  294. {"compile", optional_argument, 0, 0x102},
  295. {"punct", optional_argument, 0, 0x103},
  296. {"voices", optional_argument, 0, 0x104},
  297. {"stdout", no_argument, 0, 0x105},
  298. {"split", optional_argument, 0, 0x106},
  299. {"path", required_argument, 0, 0x107},
  300. {"phonout", required_argument, 0, 0x108},
  301. {"pho", no_argument, 0, 0x109},
  302. {"ipa", no_argument, 0, 0x10a},
  303. {"version", no_argument, 0, 0x10b},
  304. {0, 0, 0, 0}
  305. };
  306. static const char* err_load = "Failed to read ";
  307. FILE *f_text=NULL;
  308. char *p_text=NULL;
  309. FILE *f_phonemes_out = stdout;
  310. char *data_path = NULL; // use default path for espeak-data
  311. int option_index = 0;
  312. int c;
  313. int ix;
  314. char *optarg2;
  315. int value;
  316. int flag_stdin = 0;
  317. int flag_compile = 0;
  318. int filesize = 0;
  319. int synth_flags = espeakCHARS_AUTO | espeakPHONEMES | espeakENDPAUSE;
  320. int volume = -1;
  321. int speed = -1;
  322. int pitch = -1;
  323. int wordgap = -1;
  324. int option_capitals = -1;
  325. int option_punctuation = -1;
  326. int option_phonemes = 0;
  327. int option_mbrola_phonemes = 0;
  328. int option_linelength = 0;
  329. int option_waveout = 0;
  330. espeak_VOICE voice_select;
  331. char filename[200];
  332. char voicename[40];
  333. #define N_PUNCTLIST 100
  334. wchar_t option_punctlist[N_PUNCTLIST];
  335. voicename[0] = 0;
  336. wavefile[0] = 0;
  337. filename[0] = 0;
  338. option_punctlist[0] = 0;
  339. #ifdef NEED_GETOPT
  340. optind = 1;
  341. opt_string = "";
  342. while(optind < argc)
  343. {
  344. int len;
  345. char *p;
  346. if((c = *opt_string) == 0)
  347. {
  348. opt_string = argv[optind];
  349. if(opt_string[0] != '-')
  350. break;
  351. optind++;
  352. opt_string++;
  353. c = *opt_string;
  354. }
  355. opt_string++;
  356. p = optarg2 = opt_string;
  357. if(c == '-')
  358. {
  359. if(p[0] == 0)
  360. break; // -- means don't interpret further - as commands
  361. opt_string="";
  362. for(ix=0; ;ix++)
  363. {
  364. if(long_options[ix].name == 0)
  365. break;
  366. len = strlen(long_options[ix].name);
  367. if(memcmp(long_options[ix].name,p,len)==0)
  368. {
  369. c = long_options[ix].val;
  370. optarg2 = NULL;
  371. if((long_options[ix].has_arg != 0) && (p[len]=='='))
  372. {
  373. optarg2 = &p[len+1];
  374. }
  375. break;
  376. }
  377. }
  378. }
  379. else
  380. if(strchr(arg_opts,c) != NULL)
  381. {
  382. opt_string="";
  383. if(optarg2[0]==0)
  384. {
  385. // the option's value is in the next argument
  386. optarg2 = argv[optind++];
  387. }
  388. }
  389. #else
  390. while(true)
  391. {
  392. c = getopt_long (argc, argv, "a:b:f:g:hk:l:mp:qs:v:w:xXz",
  393. long_options, &option_index);
  394. /* Detect the end of the options. */
  395. if (c == -1)
  396. break;
  397. optarg2 = optarg;
  398. #endif
  399. switch (c)
  400. {
  401. case 'b':
  402. // input character encoding, 8bit, 16bit, UTF8
  403. if((sscanf(optarg2,"%d",&value) == 1) && (value <= 4))
  404. synth_flags |= value;
  405. else
  406. synth_flags |= espeakCHARS_8BIT;
  407. break;
  408. case 'h':
  409. printf("\n");
  410. PrintVersion();
  411. printf("%s", help_text);
  412. exit(0);
  413. break;
  414. case 'k':
  415. option_capitals = atoi(optarg2);
  416. break;
  417. case 'x':
  418. option_phonemes = 1;
  419. break;
  420. case 'X':
  421. option_phonemes = 2;
  422. break;
  423. case 'm':
  424. synth_flags |= espeakSSML;
  425. break;
  426. case 'p':
  427. pitch = atoi(optarg2);
  428. break;
  429. case 'q':
  430. quiet = 1;
  431. break;
  432. case 'f':
  433. strncpy0(filename,optarg2,sizeof(filename));
  434. break;
  435. case 'l':
  436. option_linelength = atoi(optarg2);
  437. break;
  438. case 'a':
  439. volume = atoi(optarg2);
  440. break;
  441. case 's':
  442. speed = atoi(optarg2);
  443. break;
  444. case 'g':
  445. wordgap = atoi(optarg2);
  446. break;
  447. case 'v':
  448. strncpy0(voicename,optarg2,sizeof(voicename));
  449. break;
  450. case 'w':
  451. option_waveout = 1;
  452. strncpy0(wavefile,optarg2,sizeof(filename));
  453. break;
  454. case 'z': // remove pause from the end of a sentence
  455. synth_flags &= ~espeakENDPAUSE;
  456. break;
  457. case 0x100: // --stdin
  458. flag_stdin = 1;
  459. break;
  460. case 0x105: // --stdout
  461. option_waveout = 1;
  462. strcpy(wavefile,"stdout");
  463. break;
  464. case 0x101: // --compile-debug
  465. case 0x102: // --compile
  466. strncpy0(voicename,optarg2,sizeof(voicename));
  467. flag_compile = c;
  468. quiet = 1;
  469. break;
  470. case 0x103: // --punct
  471. option_punctuation = 1;
  472. if(optarg2 != NULL)
  473. {
  474. ix = 0;
  475. while((ix < N_PUNCTLIST) && ((option_punctlist[ix] = optarg2[ix]) != 0)) ix++;
  476. option_punctlist[N_PUNCTLIST-1] = 0;
  477. option_punctuation = 2;
  478. }
  479. break;
  480. case 0x104: // --voices
  481. espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,data_path,0);
  482. DisplayVoices(stdout,optarg2);
  483. exit(0);
  484. case 0x106: // -- split
  485. if(optarg2 == NULL)
  486. samples_split_seconds = 30 * 60; // default 30 minutes
  487. else
  488. samples_split_seconds = atoi(optarg2) * 60;
  489. break;
  490. case 0x107: // --path
  491. data_path = optarg2;
  492. break;
  493. case 0x108: // --phonout
  494. if((f_phonemes_out = fopen(optarg2,"w")) == NULL)
  495. {
  496. fprintf(stderr,"Can't write to: %s\n",optarg2);
  497. }
  498. break;
  499. case 0x109: // --pho
  500. option_mbrola_phonemes = 16;
  501. break;
  502. case 0x10a: // --ipa
  503. option_phonemes = 3;
  504. break;
  505. case 0x10b: // -version
  506. PrintVersion();
  507. exit(0);
  508. default:
  509. exit(0);
  510. }
  511. }
  512. if(option_waveout || quiet)
  513. {
  514. // writing to a file (or no output), we can use synchronous mode
  515. samplerate = espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS,0,data_path,0);
  516. samples_split = samplerate * samples_split_seconds;
  517. espeak_SetSynthCallback(SynthCallback);
  518. if(samples_split)
  519. {
  520. char *extn;
  521. extn = strrchr(wavefile,'.');
  522. if((extn != NULL) && ((wavefile + strlen(wavefile) - extn) <= 4))
  523. {
  524. strcpy(filetype,extn);
  525. *extn = 0;
  526. }
  527. }
  528. }
  529. else
  530. {
  531. // play the sound output
  532. samplerate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK,0,data_path,0);
  533. }
  534. if(voicename[0] == 0)
  535. strcpy(voicename,"default");
  536. if(espeak_SetVoiceByName(voicename) != EE_OK)
  537. {
  538. memset(&voice_select,0,sizeof(voice_select));
  539. voice_select.languages = voicename;
  540. if(espeak_SetVoiceByProperties(&voice_select) != EE_OK)
  541. {
  542. fprintf(stderr,"%svoice '%s'\n",err_load,voicename);
  543. exit(2);
  544. }
  545. }
  546. if(flag_compile)
  547. {
  548. // This must be done after the voice is set
  549. espeak_CompileDictionary("", stderr, flag_compile & 0x1);
  550. exit(0);
  551. }
  552. // set any non-default values of parameters. This must be done after espeak_Initialize()
  553. if(speed > 0)
  554. espeak_SetParameter(espeakRATE,speed,0);
  555. if(volume >= 0)
  556. espeak_SetParameter(espeakVOLUME,volume,0);
  557. if(pitch >= 0)
  558. espeak_SetParameter(espeakPITCH,pitch,0);
  559. if(option_capitals >= 0)
  560. espeak_SetParameter(espeakCAPITALS,option_capitals,0);
  561. if(option_punctuation >= 0)
  562. espeak_SetParameter(espeakPUNCTUATION,option_punctuation,0);
  563. if(wordgap >= 0)
  564. espeak_SetParameter(espeakWORDGAP,wordgap,0);
  565. if(option_linelength > 0)
  566. espeak_SetParameter(espeakLINELENGTH,option_linelength,0);
  567. if(option_punctuation == 2)
  568. espeak_SetPunctuationList(option_punctlist);
  569. espeak_SetPhonemeTrace(option_phonemes | option_mbrola_phonemes,f_phonemes_out);
  570. if(filename[0]==0)
  571. {
  572. if((optind < argc) && (flag_stdin == 0))
  573. {
  574. // there's a non-option parameter, and no -f or --stdin
  575. // use it as text
  576. p_text = argv[optind];
  577. }
  578. else
  579. {
  580. f_text = stdin;
  581. if(flag_stdin == 0)
  582. {
  583. flag_stdin = 2;
  584. }
  585. }
  586. }
  587. else
  588. {
  589. filesize = GetFileLength(filename);
  590. f_text = fopen(filename,"r");
  591. }
  592. if((f_text == NULL) && (p_text == NULL))
  593. {
  594. fprintf(stderr,"%sfile '%s'\n",err_load,filename);
  595. exit(1);
  596. }
  597. if(p_text != NULL)
  598. {
  599. int size;
  600. size = strlen(p_text);
  601. espeak_Synth(p_text,size+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL);
  602. }
  603. else
  604. if(flag_stdin)
  605. {
  606. int max = 1000;
  607. p_text = (char *)malloc(max);
  608. if(flag_stdin == 2)
  609. {
  610. // line by line input on stdin
  611. while(fgets(p_text,max,stdin) != NULL)
  612. {
  613. p_text[max-1] = 0;
  614. espeak_Synth(p_text,max,0,POS_CHARACTER,0,synth_flags,NULL,NULL);
  615. }
  616. }
  617. else
  618. {
  619. // bulk input on stdin
  620. ix = 0;
  621. while(!feof(stdin))
  622. {
  623. p_text[ix++] = fgetc(stdin);
  624. if(ix >= (max-1))
  625. {
  626. max += 1000;
  627. p_text = (char *)realloc(p_text,max);
  628. }
  629. }
  630. if(ix > 0)
  631. {
  632. p_text[ix-1] = 0;
  633. espeak_Synth(p_text,ix+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL);
  634. }
  635. }
  636. }
  637. else
  638. if(f_text != NULL)
  639. {
  640. if((p_text = (char *)malloc(filesize+1)) == NULL)
  641. {
  642. fprintf(stderr,"Failed to allocate memory %d bytes",filesize);
  643. exit(3);
  644. }
  645. fread(p_text,1,filesize,f_text);
  646. p_text[filesize]=0;
  647. espeak_Synth(p_text,filesize+1,0,POS_CHARACTER,0,synth_flags,NULL,NULL);
  648. fclose(f_text);
  649. }
  650. espeak_Synchronize();
  651. if(f_phonemes_out != stdout)
  652. fclose(f_phonemes_out); // needed for WinCE
  653. return(0);
  654. }