Debian Codegraph @

3rdparty/flite_hts_engine/bin/flite_hts_engine.c

raw symbols SCIP
1 /* ----------------------------------------------------------------- */
2 /* The English TTS System "Flite+hts_engine" */
3 /* developed by HTS Working Group */
4 /* http://hts-engine.sourceforge.net/ */
5 /* ----------------------------------------------------------------- */
6 /* */
7 /* Copyright (c) 2005-2013 Nagoya Institute of Technology */
8 /* Department of Computer Science */
9 /* */
10 /* 2005-2008 Tokyo Institute of Technology */
11 /* Interdisciplinary Graduate School of */
12 /* Science and Engineering */
13 /* */
14 /* All rights reserved. */
15 /* */
16 /* Redistribution and use in source and binary forms, with or */
17 /* without modification, are permitted provided that the following */
18 /* conditions are met: */
19 /* */
20 /* - Redistributions of source code must retain the above copyright */
21 /* notice, this list of conditions and the following disclaimer. */
22 /* - Redistributions in binary form must reproduce the above */
23 /* copyright notice, this list of conditions and the following */
24 /* disclaimer in the documentation and/or other materials provided */
25 /* with the distribution. */
26 /* - Neither the name of the HTS working group nor the names of its */
27 /* contributors may be used to endorse or promote products derived */
28 /* from this software without specific prior written permission. */
29 /* */
30 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
31 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
32 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
33 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
34 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
35 /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
36 /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
37 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
38 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
39 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
40 /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
41 /* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
42 /* POSSIBILITY OF SUCH DAMAGE. */
43 /* ----------------------------------------------------------------- */
44
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <stdarg.h>
49
50 #include "flite_hts_engine.h"
51
52 #define INPUT_BUFF_SIZE 1024
53
54 /* usage: output usage */
55 static void usage(void)
56 {
57 fprintf(stderr, "The English TTS System \"Flite+hts_engine\"\n");
58 fprintf(stderr, "Version 1.05 (http://hts-engine.sourceforge.net/)\n");
59 fprintf(stderr, "Copyright (C) 2005-2013 Nagoya Institute of Technology\n");
60 fprintf(stderr, " 2005-2008 Tokyo Institute of Technology\n");
61 fprintf(stderr, "All rights reserved.\n");
62 fprintf(stderr, "\n%s\n", HTS_COPYRIGHT);
63 fprintf(stderr, "CMU Flite\n");
64 fprintf(stderr, "Version 1.4 (http://www.speech.cs.cmu.edu/flite/)\n");
65 fprintf(stderr, "Copyright (C) 1999-2009 Carnegie Mellon University\n");
66 fprintf(stderr, "All rights reserved.\n");
67 fprintf(stderr, "\n");
68 fprintf(stderr, "flite_hts_engine - The English TTS system \"Flite+hts_engine\"\n");
69 fprintf(stderr, "\n");
70 fprintf(stderr, " usage:\n");
71 fprintf(stderr, " flite_hts_engine [ options ] [ infile ] \n");
72 fprintf(stderr, " options: [ def][ min-- max]\n");
73 fprintf(stderr, " -m htsvoice : HTS voice [ N/A]\n");
74 fprintf(stderr, " -o wav : filename of output wav audio (generated speech) [ N/A]\n");
75 fprintf(stderr, " -s i : sampling frequency [ auto][ 1-- ]\n");
76 fprintf(stderr, " -p i : frame period (point) [ auto][ 1-- ]\n");
77 fprintf(stderr, " -a f : all-pass constant [ auto][ 0.0-- 1.0]\n");
78 fprintf(stderr, " -b f : postfiltering coefficient [ 0.0][ 0.0-- 1.0]\n");
79 fprintf(stderr, " -r f : speech speed rate [ 1.0][ 0.0-- ]\n");
80 fprintf(stderr, " -fm : additional half-tone [ 0.0][ -- ]\n");
81 fprintf(stderr, " -u f : voiced/unvoiced threshold [ 0.5][ 0.0-- 1.0]\n");
82 fprintf(stderr, " -jm f : weight of GV for spectrum [ 1.0][ 0.0-- ]\n");
83 fprintf(stderr, " -jf f : weight of GV for Log F0 [ 1.0][ 0.0-- ]\n");
84 fprintf(stderr, " -z i : audio buffer size (if i==0, turn off) [ 0][ 0-- ]\n");
85 fprintf(stderr, " infile:\n");
86 fprintf(stderr, " text file [stdin]\n");
87 fprintf(stderr, "\n");
88
89 exit(0);
90 }
91
92 int main(int argc, char **argv)
93 {
94 size_t i;
95 char buff[INPUT_BUFF_SIZE];
96 FILE *fp_txt = stdin;
97 char *fn_txt = NULL;
98 char *fn_wav = NULL;
99 char *fn_voice = NULL;
100
101 /* Flite+hts_engine */
102 Flite_HTS_Engine engine;
103
104 /* parse command line */
105 if (argc == 1)
106 usage();
107
108 /* initialize engine */
109 Flite_HTS_Engine_initialize(&engine);
110
111 /* get HTS voice file name */
112 for (i = 0; i < argc; i++) {
113 if (argv[i][0] == '-' && argv[i][1] == 'm')
114 fn_voice = argv[++i];
115 if (argv[i][0] == '-' && argv[i][1] == 'h')
116 usage();
117 }
118 if (fn_voice == NULL) {
119 fprintf(stderr, "flite_hts_engine: HTS voice must be specified.\n");
120 exit(1);
121 }
122
123 /* load HTS voice */
124 if (Flite_HTS_Engine_load(&engine, fn_voice) != TRUE) {
125 fprintf(stderr, "flite_hts_engine: HTS voice cannot be loaded.\n");
126 Flite_HTS_Engine_clear(&engine);
127 exit(1);
128 }
129
130 /* read command */
131 while (--argc) {
132 if (**++argv == '-') {
133 switch (*(*argv + 1)) {
134 case 'm': /* HTS voice was already loaded */
135 ++argv;
136 --argc;
137 break;
138 case 'o':
139 fn_wav = *++argv;
140 --argc;
141 break;
142 case 'h':
143 usage();
144 break;
145 case 's':
146 Flite_HTS_Engine_set_sampling_frequency(&engine, (size_t) atoi(*++argv));
147 --argc;
148 break;
149 case 'p':
150 Flite_HTS_Engine_set_fperiod(&engine, (size_t) atoi(*++argv));
151 --argc;
152 break;
153 case 'a':
154 Flite_HTS_Engine_set_alpha(&engine, atof(*++argv));
155 --argc;
156 break;
157 case 'b':
158 Flite_HTS_Engine_set_beta(&engine, atof(*++argv));
159 --argc;
160 break;
161 case 'r':
162 Flite_HTS_Engine_set_speed(&engine, atof(*++argv));
163 --argc;
164 break;
165 case 'f':
166 switch (*(*argv + 2)) {
167 case 'm':
168 Flite_HTS_Engine_add_half_tone(&engine, atof(*++argv));
169 break;
170 default:
171 fprintf(stderr, "flite_hts_engine: Invalid option '-f%c'.\n", *(*argv + 2));
172 exit(1);
173 }
174 --argc;
175 break;
176 case 'u':
177 Flite_HTS_Engine_set_msd_threshold(&engine, 1, atof(*++argv));
178 --argc;
179 break;
180 case 'j':
181 switch (*(*argv + 2)) {
182 case 'm':
183 Flite_HTS_Engine_set_gv_weight(&engine, 0, atof(*++argv));
184 break;
185 case 'f':
186 case 'p':
187 Flite_HTS_Engine_set_gv_weight(&engine, 1, atof(*++argv));
188 break;
189 default:
190 fprintf(stderr, "flite_hts_engine: Invalid option '-j%c'.\n", *(*argv + 2));
191 exit(1);
192 }
193 --argc;
194 break;
195 case 'z':
196 Flite_HTS_Engine_set_audio_buff_size(&engine, atoi(*++argv));
197 --argc;
198 break;
199 default:
200 fprintf(stderr, "flite_hts_engine: Invalid option '-%c'.\n", *(*argv + 1));
201 exit(1);
202 }
203 } else {
204 fn_txt = *argv;
205 }
206 }
207
208 /* synthesis */
209 if (fn_txt != NULL)
210 fp_txt = fopen(fn_txt, "r");
211 if (fgets(buff, INPUT_BUFF_SIZE, fp_txt) != NULL && strlen(buff) > 0)
212 Flite_HTS_Engine_synthesize(&engine, buff, fn_wav);
213 if (fn_txt != NULL)
214 fclose(fp_txt);
215
216 /* free */
217 Flite_HTS_Engine_clear(&engine);
218
219 return 0;
220 }