/[zanavi_public1]/navit/navit/support/espeak/speak.c
ZANavi

Contents of /navit/navit/support/espeak/speak.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 20804 byte(s)
import files
1 /***************************************************************************
2 * Copyright (C) 2005 to 2007 by Jonathan Duddington *
3 * email: jonsd@users.sourceforge.net *
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
20 #include "StdAfx.h"
21
22 #include "speech.h"
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #ifndef PLATFORM_DOS
29 #ifdef PLATFORM_WINDOWS
30 #include <windows.h>
31 #include <winreg.h>
32 #else
33 #include <unistd.h>
34 #endif
35 #endif
36
37 #ifndef NEED_GETOPT
38 #include <getopt.h>
39 #endif
40 #include <time.h>
41 #include <signal.h>
42 #include <locale.h>
43 #include <sys/stat.h>
44
45 #include "speak_lib.h"
46 #include "phoneme.h"
47 #include "synthesize.h"
48 #include "voice.h"
49 #include "translate.h"
50
51
52
53 extern void Write4Bytes(FILE *f, int value);
54 char path_home[N_PATH_HOME]; // this is the espeak-data directory
55
56 char filetype[5];
57 char wavefile[200];
58 int (* uri_callback)(int, const char *, const char *) = NULL;
59 int (* phoneme_callback)(const char *) = NULL;
60
61 FILE *f_wave = NULL;
62 int quiet = 0;
63 unsigned int samples_total = 0;
64 unsigned int samples_split = 0;
65 unsigned int wavefile_count = 0;
66 int end_of_sentence = 0;
67
68 static const char *help_text =
69 "\nspeak [options] [\"<words>\"]\n\n"
70 "-f <text file> Text file to speak\n"
71 "--stdin Read text input from stdin instead of a file\n\n"
72 "If neither -f nor --stdin, <words> are spoken, or if none then text is\n"
73 "spoken from stdin, each line separately.\n\n"
74 "-a <integer>\n"
75 "\t Amplitude, 0 to 200, default is 100\n"
76 "-g <integer>\n"
77 "\t Word gap. Pause between words, units of 10mS at the default speed\n"
78 "-l <integer>\n"
79 "\t Line length. If not zero (which is the default), consider\n"
80 "\t lines less than this length as end-of-clause\n"
81 "-p <integer>\n"
82 "\t Pitch adjustment, 0 to 99, default is 50\n"
83 "-s <integer>\n"
84 "\t Speed in words per minute 80 to 390, default is 170\n"
85 "-v <voice name>\n"
86 "\t Use voice file of this name from espeak-data/voices\n"
87 "-w <wave file name>\n"
88 "\t Write output to this WAV file, rather than speaking it directly\n"
89 "-b\t Input text encoding, 1=UTF8, 2=8 bit, 4=16 bit \n"
90 "-m\t Interpret SSML markup, and ignore other < > tags\n"
91 "-q\t Quiet, don't produce any speech (may be useful with -x)\n"
92 "-x\t Write phoneme mnemonics to stdout\n"
93 "-X\t Write phonemes mnemonics and translation trace to stdout\n"
94 "-z\t No final sentence pause at the end of the text\n"
95 "--stdout Write speech output to stdout\n"
96 "--compile=<voice name>\n"
97 "\t Compile the pronunciation rules and dictionary in the current\n"
98 "\t directory. =<voice name> is optional and specifies which language\n"
99 "--path=\"<path>\"\n"
100 "\t Specifies the directory containing the espeak-data directory\n"
101 "--phonout=\"<filename>\"\n"
102 "\t Write output from -x -X commands and mbrola phoneme data to this file\n"
103 "--punct=\"<characters>\"\n"
104 "\t Speak the names of punctuation characters during speaking. If\n"
105 "\t =<characters> is omitted, all punctuation is spoken.\n"
106 "--split=\"<minutes>\"\n"
107 "\t Starts a new WAV file every <minutes>. Used with -w\n"
108 "--voices=<language>\n"
109 "\t List the available voices for the specified language.\n"
110 "\t If <language> is omitted, then list all voices.\n"
111 "-k <integer>\n"
112 "\t Indicate capital letters with: 1=sound, 2=the word \"capitals\",\n"
113 "\t higher values = a pitch increase (try -k20).\n";
114
115
116 void DisplayVoices(FILE *f_out, char *language);
117
118 USHORT voice_pcnt[N_PEAKS+1][3];
119
120
121
122 int GetFileLength(const char *filename)
123 {//====================================
124 struct stat statbuf;
125
126 if(stat(filename,&statbuf) != 0)
127 return(0);
128
129 if((statbuf.st_mode & S_IFMT) == S_IFDIR)
130 // if(S_ISDIR(statbuf.st_mode))
131 return(-2); // a directory
132
133 return(statbuf.st_size);
134 } // end of GetFileLength
135
136
137 char *Alloc(int size)
138 {//==================
139 char *p;
140 if((p = (char *)malloc(size)) == NULL)
141 fprintf(stderr,"Can't allocate memory\n");
142 return(p);
143 }
144
145 void Free(void *ptr)
146 {//=================
147 if(ptr != NULL)
148 free(ptr);
149 }
150
151
152 void DisplayVoices(FILE *f_out, char *language)
153 {//============================================
154 int ix;
155 const char *p;
156 int len;
157 int count;
158 int scores = 0;
159 const espeak_VOICE *v;
160 const char *lang_name;
161 char age_buf[12];
162 const espeak_VOICE **voices;
163 espeak_VOICE voice_select;
164
165 static char genders[4] = {' ','M','F',' '};
166
167 if((language != NULL) && (language[0] != 0))
168 {
169 // display only voices for the specified language, in order of priority
170 voice_select.languages = language;
171 voice_select.age = 0;
172 voice_select.gender = 0;
173 voice_select.name = NULL;
174 voices = espeak_ListVoices(&voice_select);
175 scores = 1;
176 }
177 else
178 {
179 voices = espeak_ListVoices(NULL);
180 }
181
182 fprintf(f_out,"Pty Language Age/Gender VoiceName File Other Langs\n");
183
184 for(ix=0; (v = voices[ix]) != NULL; ix++)
185 {
186 count = 0;
187 p = v->languages;
188 while(*p != 0)
189 {
190 len = strlen(p+1);
191 lang_name = p+1;
192
193 if(v->age == 0)
194 strcpy(age_buf," ");
195 else
196 sprintf(age_buf,"%3d",v->age);
197
198 if(count==0)
199 {
200 fprintf(f_out,"%2d %-12s%s%c %-17s %-11s ",
201 p[0],lang_name,age_buf,genders[v->gender],v->name,v->identifier);
202 }
203 else
204 {
205 fprintf(f_out,"(%s %d)",lang_name,p[0]);
206 }
207 count++;
208 p += len+2;
209 }
210 // if(scores)
211 // fprintf(f_out,"%3d ",v->score);
212 fputc('\n',f_out);
213 }
214 } // end of DisplayVoices
215
216
217
218
219 static int OpenWaveFile(const char *path, int rate)
220 //=================================================
221 {
222 // Set the length of 0x7ffff000 for --stdout
223 // This will be changed to the correct length for -w (write to file)
224 static unsigned char wave_hdr[44] = {
225 'R','I','F','F',0x24,0xf0,0xff,0x7f,'W','A','V','E','f','m','t',' ',
226 0x10,0,0,0,1,0,1,0, 9,0x3d,0,0,0x12,0x7a,0,0,
227 2,0,0x10,0,'d','a','t','a', 0x00,0xf0,0xff,0x7f};
228
229 if(path == NULL)
230 return(2);
231
232 if(strcmp(path,"stdout")==0)
233 f_wave = stdout;
234 else
235 f_wave = fopen(path,"wb");
236
237 if(f_wave != NULL)
238 {
239 fwrite(wave_hdr,1,24,f_wave);
240 Write4Bytes(f_wave,rate);
241 Write4Bytes(f_wave,rate * 2);
242 fwrite(&wave_hdr[32],1,12,f_wave);
243 return(0);
244 }
245 return(1);
246 } // end of OpenWaveFile
247
248
249
250
251 static void CloseWaveFile()
252 //=========================
253 {
254 unsigned int pos;
255
256 if((f_wave == NULL) || (f_wave == stdout))
257 return;
258
259 fflush(f_wave);
260 pos = ftell(f_wave);
261
262 fseek(f_wave,4,SEEK_SET);
263 Write4Bytes(f_wave,pos - 8);
264
265 fseek(f_wave,40,SEEK_SET);
266 Write4Bytes(f_wave,pos - 44);
267
268
269 fclose(f_wave);
270 f_wave = NULL;
271
272 } // end of CloseWaveFile
273
274
275
276
277 void MarkerEvent(int type, unsigned int char_position, int value, unsigned char *out_ptr)
278 {//======================================================================================
279 // Do nothing in the command-line version.
280 if(type == 2)
281 end_of_sentence = 1;
282 } // end of MarkerEvent
283
284
285 static int WavegenFile(void)
286 {//=========================
287 int finished;
288 unsigned char wav_outbuf[512];
289 char fname[210];
290
291 out_ptr = out_start = wav_outbuf;
292 out_end = wav_outbuf + sizeof(wav_outbuf);
293
294 finished = WavegenFill(0);
295
296 if(quiet)
297 return(finished);
298
299 if(f_wave == NULL)
300 {
301 sprintf(fname,"%s_%.2d%s",wavefile,++wavefile_count,filetype);
302 if(OpenWaveFile(fname, samplerate) != 0)
303 return(1);
304 }
305
306 if(end_of_sentence)
307 {
308 end_of_sentence = 0;
309 if((samples_split > 0 ) && (samples_total > samples_split))
310 {
311 CloseWaveFile();
312 samples_total = 0;
313 }
314 }
315
316 if(f_wave != NULL)
317 {
318 samples_total += (out_ptr - wav_outbuf)/2;
319 fwrite(wav_outbuf, 1, out_ptr - wav_outbuf, f_wave);
320 }
321 return(finished);
322 } // end of WavegenFile
323
324
325
326 static void init_path(char *argv0, char *path_specified)
327 {//=====================================================
328
329 if(path_specified)
330 {
331 sprintf(path_home,"%s/espeak-data",path_specified);
332 return;
333 }
334
335 #ifdef PLATFORM_WINDOWS
336 HKEY RegKey;
337 unsigned long size;
338 unsigned long var_type;
339 char *p;
340 char *env;
341 unsigned char buf[sizeof(path_home)-12];
342
343 #if 0
344 if(((env = getenv("ESPEAK_DATA_PATH")) != NULL) && ((strlen(env)+12) < sizeof(path_home)))
345 {
346 sprintf(path_home,"%s\\espeak-data",env);
347 if(GetFileLength(path_home) == -2)
348 return; // an espeak-data directory exists in the directory specified by environment variable
349 }
350 #endif
351
352 strcpy(path_home,argv0);
353 if((p = strrchr(path_home,'\\')) != NULL)
354 {
355 strcpy(&p[1],"espeak-data");
356 if(GetFileLength(path_home) == -2)
357 return; // an espeak-data directory exists in the same directory as the espeak program
358 }
359
360 // otherwise, look in the Windows Registry
361 buf[0] = 0;
362 RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak", 0, KEY_READ, &RegKey);
363 size = sizeof(buf);
364 var_type = REG_SZ;
365 RegQueryValueEx(RegKey, "path", 0, &var_type, buf, &size);
366
367 sprintf(path_home,"%s\\espeak-data",buf);
368 #else
369 #ifdef PLATFORM_DOS
370 strcpy(path_home,PATH_ESPEAK_DATA);
371 #else
372 char *env;
373 #if 0
374 if((env = getenv("ESPEAK_DATA_PATH")) != NULL)
375 {
376 snprintf(path_home,sizeof(path_home),"%s/espeak-data",env);
377 if(GetFileLength(path_home) == -2)
378 return; // an espeak-data directory exists
379 }
380 #endif
381
382 #if 0
383 snprintf(path_home,sizeof(path_home),"%s/espeak-data",getenv("HOME"));
384 if(access(path_home,R_OK) != 0)
385 {
386 strcpy(path_home,PATH_ESPEAK_DATA);
387 }
388 #endif
389 #endif
390 #endif
391 }
392
393
394 static int initialise(void)
395 {//========================
396 int param;
397 int result;
398
399 // It seems that the wctype functions don't work until the locale has been set
400 // to something other than the default "C". Then, not only Latin1 but also the
401 // other characters give the correct results with iswalpha() etc.
402 #ifdef PLATFORM_RISCOS
403 setlocale(LC_CTYPE,"ISO8859-1");
404 #else
405 #if 0
406 if(setlocale(LC_CTYPE,"en_US.UTF-8") == NULL)
407 {
408 if(setlocale(LC_CTYPE,"UTF-8") == NULL)
409 setlocale(LC_CTYPE,"");
410 }
411 #endif
412 #endif
413
414
415 WavegenInit(22050,0); // 22050
416 if((result = LoadPhData()) != 1)
417 {
418 if(result == -1)
419 {
420 fprintf(stderr,"Failed to load espeak-data\n");
421 exit(1);
422 }
423 else
424 fprintf(stderr,"Wrong version of espeak-data 0x%x (expects 0x%x) at %s\n",result,version_phdata,path_home);
425 }
426 LoadConfig();
427 SetVoiceStack(NULL);
428 SynthesizeInit();
429
430 for(param=0; param<N_SPEECH_PARAM; param++)
431 param_stack[0].parameter[param] = param_defaults[param];
432
433 return(0);
434 }
435
436
437 static void StopSpeak(int unused)
438 {//==============================
439 // signal(SIGINT,SIG_IGN);
440 // DEBUG
441 // printf("\n*** Interrupting speech output (use Ctrl-D to actually quit).\n");
442 fflush(stdout);
443 SpeakNextClause(NULL,NULL,5);
444 // signal(SIGINT,StopSpeak);
445 } // end of StopSpeak()
446
447 #ifdef NEED_GETOPT
448 struct option {
449 char *name;
450 int has_arg;
451 int *flag;
452 int val;
453 };
454 int optind;
455 static int optional_argument;
456 static const char *arg_opts = "abfgklpsvw"; // which options have arguments
457 static char *opt_string="";
458 #define no_argument 0
459 #define required_argument 1
460 #define optional_argument 2
461 #endif
462
463 int main (int argc, char **argv)
464 //==============================
465 {
466 static struct option long_options[] =
467 {
468 /* These options set a flag. */
469 // {"verbose", no_argument, &verbose_flag, 1},
470 // {"brief", no_argument, &verbose_flag, 0},
471
472 /* These options don't set a flag.
473 We distinguish them by their indices. */
474 {"help", no_argument, 0, 'h'},
475 {"stdin", no_argument, 0, 0x100},
476 {"compile-debug", optional_argument, 0, 0x101},
477 {"compile", optional_argument, 0, 0x102},
478 {"punct", optional_argument, 0, 0x103},
479 {"voices", optional_argument, 0, 0x104},
480 {"stdout", no_argument, 0, 0x105},
481 {"split", optional_argument, 0, 0x106},
482 {"path", required_argument, 0, 0x107},
483 {"phonout", required_argument, 0, 0x108},
484 {0, 0, 0, 0}
485 };
486
487 static const char *err_load = "Failed to read ";
488
489 FILE *f_text=NULL;
490 const char *p_text=NULL;
491 char *data_path = NULL; // use default path for espeak-data
492
493 int option_index = 0;
494 int c;
495 int value;
496 int speed=170;
497 int ix;
498 char *optarg2;
499 int amp = 100; // default
500 int wordgap = 0;
501 int speaking = 0;
502 int flag_stdin = 0;
503 int flag_compile = 0;
504 int pitch_adjustment = 50;
505 espeak_VOICE voice_select;
506 char filename[200];
507 char voicename[40];
508 char dictname[40];
509
510 voicename[0] = 0;
511 mbrola_name[0] = 0;
512 dictname[0] = 0;
513 wavefile[0] = 0;
514 filename[0] = 0;
515 option_linelength = 0;
516 option_phonemes = 0;
517 option_waveout = 0;
518 option_wordgap = 0;
519 option_endpause = 1;
520 option_phoneme_input = 1;
521 option_multibyte = espeakCHARS_AUTO; // auto
522 f_trans = stdout;
523
524 #ifdef NEED_GETOPT
525 optind = 1;
526 opt_string = "";
527 while(optind < argc)
528 {
529 int len;
530 char *p;
531
532 if((c = *opt_string) == 0)
533 {
534 opt_string = argv[optind];
535 if(opt_string[0] != '-')
536 break;
537
538 optind++;
539 opt_string++;
540 c = *opt_string;
541 }
542 opt_string++;
543 p = optarg2 = opt_string;
544
545 if(c == '-')
546 {
547 opt_string="";
548 for(ix=0; ;ix++)
549 {
550 if(long_options[ix].name == 0)
551 break;
552 len = strlen(long_options[ix].name);
553 if(memcmp(long_options[ix].name,p,len)==0)
554 {
555 c = long_options[ix].val;
556 optarg2 = NULL;
557
558 if((long_options[ix].has_arg != 0) && (p[len]=='='))
559 {
560 optarg2 = &p[len+1];
561 }
562 break;
563 }
564 }
565 }
566 else
567 if(strchr(arg_opts,c) != NULL)
568 {
569 opt_string="";
570 if(optarg2[0]==0)
571 {
572 // the option's value is in the next argument
573 optarg2 = argv[optind++];
574 }
575 }
576 #else
577 while(1)
578 {
579 c = getopt_long (argc, argv, "a:b:f:g:hk:l:p:qs:v:w:xXmz", // NOTE: also change arg_opts to indicate which commands have a numeric value
580 long_options, &option_index);
581
582 /* Detect the end of the options. */
583 if (c == -1)
584 break;
585 optarg2 = optarg;
586 #endif
587
588 switch (c)
589 {
590 case 'b':
591 // input character encoding, 8bit, 16bit, UTF8
592 option_multibyte = espeakCHARS_8BIT;
593 if((sscanf(optarg2,"%d",&value) == 1) && (value <= 4))
594 option_multibyte= value;
595 break;
596
597 case 'h':
598 printf("\nspeak text-to-speech: %s\n%s",version_string,help_text);
599 exit(0);
600 break;
601
602 case 'k':
603 option_capitals = atoi(optarg2);
604 break;
605
606 case 'x':
607 option_phonemes = 1;
608 break;
609
610 case 'X':
611 option_phonemes = 2;
612 break;
613
614 case 'm':
615 option_ssml = 1;
616 break;
617
618 case 'p':
619 pitch_adjustment = atoi(optarg2);
620 if(pitch_adjustment > 99) pitch_adjustment = 99;
621 break;
622
623 case 'q':
624 quiet = 1;
625 break;
626
627 case 'f':
628 strncpy0(filename,optarg2,sizeof(filename));
629 break;
630
631 case 'l':
632 value = 0;
633 value = atoi(optarg2);
634 option_linelength = value;
635 break;
636
637 case 'a':
638 amp = atoi(optarg2);
639 break;
640
641 case 's':
642 speed = atoi(optarg2);
643 break;
644
645 case 'g':
646 wordgap = atoi(optarg2);
647 break;
648
649 case 'v':
650 strncpy0(voicename,optarg2,sizeof(voicename));
651 break;
652
653 case 'w':
654 option_waveout = 1;
655 strncpy0(wavefile,optarg2,sizeof(wavefile));
656 break;
657
658 case 'z':
659 option_endpause = 0;
660 break;
661
662 case 0x100: // --stdin
663 flag_stdin = 1;
664 break;
665
666 case 0x105: // --stdout
667 option_waveout = 1;
668 strcpy(wavefile,"stdout");
669 break;
670
671 case 0x101: // --compile-debug
672 case 0x102: // --compile
673 if(optarg2 != NULL)
674 strncpy0(voicename,optarg2,sizeof(voicename));
675 flag_compile = c;
676 break;
677
678 case 0x103: // --punct
679 option_punctuation = 1;
680 if(optarg2 != NULL)
681 {
682 ix = 0;
683 while((ix < N_PUNCTLIST) && ((option_punctlist[ix] = optarg2[ix]) != 0)) ix++;
684 option_punctlist[N_PUNCTLIST-1] = 0;
685 option_punctuation = 2;
686 }
687 break;
688
689 case 0x104: // --voices
690 init_path(argv[0],data_path);
691 DisplayVoices(stdout,optarg2);
692 exit(0);
693
694 case 0x106: // -- split
695 if(optarg2 == NULL)
696 samples_split = 30; // default 30 minutes
697 else
698 samples_split = atoi(optarg2);
699 break;
700
701 case 0x107: // --path
702 data_path = optarg2;
703 break;
704
705 case 0x108: // --phonout
706 if((f_trans = fopen(optarg2,"w")) == NULL)
707 {
708 fprintf(stderr,"Can't write to: %s\n",optarg2);
709 f_trans = stderr;
710 }
711 break;
712
713 default:
714 exit(0);
715 }
716 }
717
718 init_path(argv[0],data_path);
719 initialise();
720
721
722 if(flag_compile)
723 {
724 LoadVoice(voicename,5);
725
726 #ifdef PLATFORM_DOS
727 char path_dsource[sizeof(path_home)+20];
728 strcpy(path_dsource,path_home);
729 path_dsource[strlen(path_home)-11] = 0; // remove "espeak-data" from the end
730 strcat(path_dsource,"dictsource\\");
731 CompileDictionary(path_dsource,dictionary_name,NULL,NULL, flag_compile & 0x1);
732 #else
733 #ifdef PLATFORM_WINDOWS
734 char path_dsource[sizeof(path_home)+20];
735 strcpy(path_dsource,path_home);
736 path_dsource[strlen(path_home)-11] = 0; // remove "espeak-data" from the end
737 strcat(path_dsource,"dictsource\\");
738 CompileDictionary(path_dsource,dictionary_name,NULL,NULL, flag_compile & 0x1);
739 #else
740 CompileDictionary(NULL,dictionary_name,NULL,NULL, flag_compile & 0x1);
741 #endif
742 #endif
743 exit(0);
744 }
745
746
747 if(voicename[0] == 0)
748 strcpy(voicename,"default");
749
750 if(SetVoiceByName(voicename) != EE_OK)
751 {
752 memset(&voice_select,0,sizeof(voice_select));
753 voice_select.languages = voicename;
754 if(SetVoiceByProperties(&voice_select) != EE_OK)
755 {
756 fprintf(stderr,"%svoice '%s'\n",err_load,voicename);
757 exit(2);
758 }
759 }
760
761 SetParameter(espeakRATE,speed,0);
762 SetParameter(espeakVOLUME,amp,0);
763 SetParameter(espeakCAPITALS,option_capitals,0);
764 SetParameter(espeakPUNCTUATION,option_punctuation,0);
765 SetParameter(espeakWORDGAP,wordgap,0);
766
767 if(pitch_adjustment != 50)
768 {
769 SetParameter(espeakPITCH,pitch_adjustment,0);
770 }
771 DoVoiceChange(voice);
772
773 if(filename[0]==0)
774 {
775 if((optind < argc) && (flag_stdin == 0))
776 {
777 // there's a non-option parameter, and no -f or --stdin
778 // use it as text
779 p_text = argv[optind];
780 }
781 else
782 {
783 f_text = stdin;
784 if(flag_stdin == 0)
785 option_linelength = -1; // single input lines on stdin
786 }
787 }
788 else
789 {
790 f_text = fopen(filename,"r");
791 }
792
793 if((f_text == NULL) && (p_text == NULL))
794 {
795 fprintf(stderr,"%sfile '%s'\n",err_load,filename);
796 exit(1);
797 }
798
799 if(option_waveout || quiet)
800 {
801 if(quiet)
802 {
803 // no sound output
804 OpenWaveFile(NULL,samplerate);
805 option_waveout = 1;
806 }
807 else
808 {
809 // write sound output to a WAV file
810 samples_split = (samplerate * samples_split) * 60;
811
812 if(samples_split)
813 {
814 // don't open the wav file until we start generating speech
815 char *extn;
816 extn = strrchr(wavefile,'.');
817 if((extn != NULL) && ((wavefile + strlen(wavefile) - extn) <= 4))
818 {
819 strcpy(filetype,extn);
820 *extn = 0;
821 }
822 }
823 else
824 if(OpenWaveFile(wavefile,samplerate) != 0)
825 {
826 fprintf(stderr,"Can't write to output file '%s'\n'",wavefile);
827 exit(3);
828 }
829 }
830
831 InitText(0);
832 SpeakNextClause(f_text,p_text,0);
833
834 ix = 1;
835 for(;;)
836 {
837 if(WavegenFile() != 0)
838 {
839 if(ix == 0)
840 break; // finished, wavegen command queue is empty
841 }
842
843 if(Generate(phoneme_list,&n_phoneme_list,1)==0)
844 {
845 ix = SpeakNextClause(NULL,NULL,1);
846 }
847 }
848
849 CloseWaveFile();
850 }
851 else
852 {
853 // Silence on ^C or SIGINT
854 // signal(SIGINT,StopSpeak);
855
856 // output sound using portaudio
857 WavegenInitSound();
858
859 InitText(0);
860 SpeakNextClause(f_text,p_text,0);
861
862 if(option_quiet)
863 {
864 while(SpeakNextClause(NULL,NULL,1) != 0);
865 return(0);
866 }
867
868 #ifdef USE_PORTAUDIO
869 speaking = 1;
870 while(speaking)
871 {
872 // NOTE: if nanosleep() isn't recognised on your system, try replacing
873 // this by sleep(1);
874 #ifdef PLATFORM_WINDOWS
875 Sleep(300); // 0.3s
876 #else
877 #ifdef USE_NANOSLEEP
878 struct timespec period;
879 struct timespec remaining;
880 period.tv_sec = 0;
881 period.tv_nsec = 300000000; // 0.3 sec
882 nanosleep(&period,&remaining);
883 #else
884 sleep(1);
885 #endif
886 #endif
887 if(SynthOnTimer() != 0)
888 speaking = 0;
889 }
890 #else
891 fprintf(stderr,"-w option must be used because the program was built without a sound interface\n");
892 #endif // USE_PORTAUDIO
893 }
894
895 if((f_trans != stdout) && (f_trans != stderr))
896 fclose(f_trans); // needed for WinCe
897 return(0);
898 }

Properties

Name Value
svn:executable *

   
Visit the ZANavi Wiki