File: | modules/Text/text.cc |
Location: | line 210, column 5 |
Description: | Value stored to 'lutt' is never read |
1 | /*************************************************************************/ |
2 | /* */ |
3 | /* Centre for Speech Technology Research */ |
4 | /* University of Edinburgh, UK */ |
5 | /* Copyright (c) 1996,1997 */ |
6 | /* All Rights Reserved. */ |
7 | /* */ |
8 | /* Permission is hereby granted, free of charge, to use and distribute */ |
9 | /* this software and its documentation without restriction, including */ |
10 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
11 | /* distribute, sublicense, and/or sell copies of this work, and to */ |
12 | /* permit persons to whom this work is furnished to do so, subject to */ |
13 | /* the following conditions: */ |
14 | /* 1. The code must retain the above copyright notice, this list of */ |
15 | /* conditions and the following disclaimer. */ |
16 | /* 2. Any modifications must be clearly marked as such. */ |
17 | /* 3. Original authors' names are not deleted. */ |
18 | /* 4. The authors' names are not used to endorse or promote products */ |
19 | /* derived from this software without specific prior written */ |
20 | /* permission. */ |
21 | /* */ |
22 | /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */ |
23 | /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ |
24 | /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ |
25 | /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */ |
26 | /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ |
27 | /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ |
28 | /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ |
29 | /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ |
30 | /* THIS SOFTWARE. */ |
31 | /* */ |
32 | /*************************************************************************/ |
33 | /* Author : Alan W Black */ |
34 | /* Date : April 1996 */ |
35 | /*-----------------------------------------------------------------------*/ |
36 | /* */ |
37 | /* Basic text utilities */ |
38 | /* */ |
39 | /* This seems to be the only language specific part that cannot be */ |
40 | /* reasonably parameterized. I'd like to change this but I'm not sure */ |
41 | /* of the best way. Language-specific token processing module */ |
42 | /* generating Words (lexical items) from Tokens are current written as */ |
43 | /* FT_*_Token_Utt functions. A language-independent one is available */ |
44 | /* FT_Any_Token_Utt which depends heavily on the lexicon can be used */ |
45 | /* when you don't have the language specific version. */ |
46 | /* */ |
47 | /*=======================================================================*/ |
48 | #include <cstdio> |
49 | #include "festival.h" |
50 | #include "text.h" |
51 | |
52 | using namespace std; |
53 | |
54 | static void tts_raw_token(EST_Item *t); |
55 | static void tts_raw_utt(LISP utt); |
56 | |
57 | LISP FT_Text_Utt(LISP utt) |
58 | { |
59 | // Parse text into words |
60 | EST_Utterance *u = get_c_utt(utt)(utterance(utt)); |
61 | EST_String text; |
62 | EST_TokenStream ts; |
63 | LISP ws,punc,scs; |
64 | EST_Token tok; |
65 | |
66 | *cdebug << "Text module\n"; |
67 | |
68 | text = get_c_string(utt_iform(*u)); |
69 | |
70 | u->create_relation("Token"); |
71 | |
72 | ts.open_string(text); |
73 | ts.set_SingleCharSymbols(EST_Token_Default_SingleCharSymbols); |
74 | ts.set_PunctuationSymbols(EST_Token_Default_PunctuationSymbols); |
75 | ts.set_PrePunctuationSymbols(EST_Token_Default_PrePunctuationSymbols); |
76 | if ((ws = siod_get_lval("token.whitespace",NULL__null)) == NIL((struct obj *) 0)) |
77 | ts.set_WhiteSpaceChars(EST_Token_Default_WhiteSpaceChars); |
78 | else |
79 | ts.set_WhiteSpaceChars(get_c_string(ws)); |
80 | if ((punc = siod_get_lval("token.punctuation",NULL__null)) == NIL((struct obj *) 0)) |
81 | ts.set_PunctuationSymbols(EST_Token_Default_PunctuationSymbols); |
82 | else |
83 | ts.set_PunctuationSymbols(get_c_string(punc)); |
84 | if ((punc = siod_get_lval("token.prepunctuation",NULL__null)) == NIL((struct obj *) 0)) |
85 | ts.set_PrePunctuationSymbols(EST_Token_Default_PrePunctuationSymbols); |
86 | else |
87 | ts.set_PrePunctuationSymbols(get_c_string(punc)); |
88 | if ((scs = siod_get_lval("token.singlecharsymbols",NULL__null)) == NIL((struct obj *) 0)) |
89 | ts.set_SingleCharSymbols(EST_Token_Default_SingleCharSymbols); |
90 | else |
91 | ts.set_SingleCharSymbols(get_c_string(scs)); |
92 | |
93 | for (ts >> tok; tok.string() != ""; ts >> tok) |
94 | add_token(u,tok); |
95 | |
96 | return utt; |
97 | } |
98 | |
99 | LISP tts_file(LISP filename,LISP mode) |
100 | { |
101 | LISP user_text_modes,t_mode; |
102 | |
103 | user_text_modes = siod_get_lval("tts_text_modes",NULL__null); |
104 | |
105 | if ((mode == NIL((struct obj *) 0)) || |
106 | (streq(get_c_string(mode),"text")(strcmp(get_c_string(mode),"text")==0)) || |
107 | (streq(get_c_string(mode),"fundamental")(strcmp(get_c_string(mode),"fundamental")==0))) |
108 | tts_file_raw(filename); // Simple text file |
109 | else |
110 | { |
111 | t_mode = siod_assoc_str(get_c_string(mode),user_text_modes); |
112 | if (t_mode == NIL((struct obj *) 0)) |
113 | { |
114 | // Attempt to load it |
115 | leval(cons(rintern("request"), |
116 | cons(strintern(EST_String(get_c_string(mode))+ |
117 | "-mode"),NIL((struct obj *) 0))),NIL((struct obj *) 0)); |
118 | // get it again, and see if its defined |
119 | user_text_modes = siod_get_lval("tts_text_modes",NULL__null); |
120 | } |
121 | t_mode = siod_assoc_str(get_c_string(mode),user_text_modes); |
122 | if (t_mode == NIL((struct obj *) 0)) |
123 | { |
124 | cerr << "tts_file: can't find mode description \"" |
125 | << get_c_string(mode) << "\" using raw mode instead" << endl; |
126 | tts_file_raw(filename); // so read it as simple text file |
127 | } |
128 | else |
129 | tts_file_user_mode(filename,car(cdr(t_mode))); |
130 | } |
131 | |
132 | return NIL((struct obj *) 0); |
133 | } |
134 | |
135 | void tts_file_raw(LISP filename) |
136 | { |
137 | // Say the contents of a named file |
138 | EST_TokenStream ts; |
139 | LISP ws,prepunc,punc,scs; |
140 | LISP lutt,eou_tree; |
141 | LISP stream = NULL__null; |
142 | |
143 | |
144 | stream = fopen_c(get_c_string(filename), "rb"); |
145 | if (ts.open(stream->storage_as.c_file.f, FALSE(1==0)) == -1) |
146 | { |
147 | cerr << "tts_file: can't open file \"" << filename << "\"\n"; |
148 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
149 | } |
150 | ts.set_SingleCharSymbols(EST_Token_Default_SingleCharSymbols); |
151 | ts.set_PunctuationSymbols(EST_Token_Default_PunctuationSymbols); |
152 | ts.set_PrePunctuationSymbols(EST_Token_Default_PrePunctuationSymbols); |
153 | if ((ws = siod_get_lval("token.whitespace",NULL__null)) == NIL((struct obj *) 0)) |
154 | ts.set_WhiteSpaceChars(EST_Token_Default_WhiteSpaceChars); |
155 | else |
156 | ts.set_WhiteSpaceChars(get_c_string(ws)); |
157 | if ((punc = siod_get_lval("token.punctuation",NULL__null)) == NIL((struct obj *) 0)) |
158 | ts.set_PunctuationSymbols(EST_Token_Default_PunctuationSymbols); |
159 | else |
160 | ts.set_PunctuationSymbols(get_c_string(punc)); |
161 | if ((prepunc = siod_get_lval("token.prepunctuation",NULL__null)) == NIL((struct obj *) 0)) |
162 | ts.set_PrePunctuationSymbols(EST_Token_Default_PrePunctuationSymbols); |
163 | else |
164 | ts.set_PrePunctuationSymbols(get_c_string(prepunc)); |
165 | if ((scs = siod_get_lval("token.singlecharsymbols",NULL__null)) == NIL((struct obj *) 0)) |
166 | ts.set_SingleCharSymbols(EST_Token_Default_SingleCharSymbols); |
167 | else |
168 | ts.set_SingleCharSymbols(get_c_string(scs)); |
169 | eou_tree = siod_get_lval("eou_tree","No end of utterance tree set"); |
170 | |
171 | lutt = tts_chunk_stream(ts,tts_raw_token,tts_raw_utt,eou_tree,0); |
172 | |
173 | // The last one is returned because the chunker doesn't know if this |
174 | // is truly the end of an utterance or not, but here we do know. |
175 | tts_raw_utt(lutt); |
176 | |
177 | ts.close(); |
178 | if (stream) |
179 | fclose_l(stream); |
180 | } |
181 | |
182 | static void tts_raw_token(EST_Item *t) |
183 | { |
184 | // Do something to token, in this case nothing |
185 | (void)t; |
186 | } |
187 | |
188 | static void tts_raw_utt(LISP utt) |
189 | { |
190 | // Do (simple) tts on this utt |
191 | LISP lutt; |
192 | |
193 | // There are some pessimal cases when the utterance is empty |
194 | if ((utt == NIL((struct obj *) 0)) || |
195 | (get_c_utt(utt)(utterance(utt))->relation("Token")->length() == 0)) |
196 | return; // in this case do nothing. |
197 | |
198 | lutt = quote(utt); |
199 | lutt = cons(rintern("apply_hooks"), |
200 | cons(rintern("tts_hooks"), |
201 | cons(lutt,NIL((struct obj *) 0)))); |
202 | |
203 | |
204 | |
205 | lutt = cons(rintern("set!"), |
206 | cons(rintern("utt_tts"), |
207 | cons(lutt,NIL((struct obj *) 0)))); |
208 | |
209 | // Synth and Play it |
210 | lutt = leval(lutt,NIL((struct obj *) 0)); |
Value stored to 'lutt' is never read | |
211 | user_gc(NIL((struct obj *) 0)); |
212 | } |
213 | |
214 | LISP new_token_utt(void) |
215 | { |
216 | // An empty utterance ready to take Tokens |
217 | EST_Utterance *u = new EST_Utterance; |
218 | u->f.set("type","Tokens"); |
219 | u->create_relation("Token"); |
220 | return siod(u); |
221 | } |
222 | |
223 | LISP tts_chunk_stream(EST_TokenStream &ts, |
224 | TTS_app_tok app_tok, |
225 | TTS_app_utt app_utt, |
226 | LISP eou_tree, |
227 | LISP utt) |
228 | { |
229 | // Get tokens from ts and cummulate them in u. |
230 | // Apply app_tok to each token |
231 | // Apply app_utt to each utt signalled |
232 | // Return untermitated utterance potentially for next call |
233 | // Uses the wagon tree eou_tree to predict utterance termination on |
234 | // penultimate token. |
235 | EST_Item *tok, *ebo; |
236 | EST_Token t; |
237 | if (utt == NIL((struct obj *) 0)) |
238 | utt = new_token_utt(); |
239 | EST_Utterance *u = get_c_utt(utt)(utterance(utt)); |
240 | |
241 | while (!ts.eof()) |
242 | { |
243 | t = ts.get(); |
244 | tok = add_token(u,t); |
245 | app_tok(tok); // do what you do with the token |
246 | ebo = as(tok,"Token")->prev(); // end but one token |
247 | if ((ebo != 0) && |
248 | (wagon_predict(ebo,eou_tree) == 1)) |
249 | { |
250 | // Remove that extra token |
251 | remove_item(tok,"Token"); |
252 | app_utt(utt); // do what you do with the utt |
253 | utt = new_token_utt(); |
254 | u = get_c_utt(utt)(utterance(utt)); |
255 | add_token(u,t); // add that last token to the new utt. |
256 | } |
257 | } |
258 | |
259 | return utt; |
260 | } |
261 | |
262 | #if 0 |
263 | LISP memon(void) |
264 | { |
265 | printf("memon\n"); |
266 | putenv("MALLOC_TRACE=mallfile"); |
267 | mtrace(); |
268 | return NIL((struct obj *) 0); |
269 | } |
270 | |
271 | LISP memoff(void) |
272 | { |
273 | muntrace(); |
274 | printf("memoff\n"); |
275 | return NIL((struct obj *) 0); |
276 | } |
277 | #endif |
278 | |
279 | void festival_Text_init(void) |
280 | { |
281 | festival_token_init(); |
282 | festival_def_utt_module("Text",FT_Text_Utt, |
283 | "(Text UTT)\n\ |
284 | From string in input form tokenize and create a token stream."); |
285 | init_subr_2("tts_file",tts_file, |
286 | "(tts_file FILE MODE)\n\ |
287 | Low level access to tts function, you probably want to use the function\n\ |
288 | tts rather than this one. Render data in FILE as speech. Respect\n\ |
289 | MODE. Currently modes are defined through the variable tts_text_modes."); |
290 | #if 0 |
291 | init_subr_0("memon",memon, |
292 | "(tts_file FILE MODE)"); |
293 | init_subr_0("memoff",memoff, |
294 | "(tts_file FILE MODE)"); |
295 | #endif |
296 | init_subr_3("extract_tokens",extract_tokens, |
297 | "(extract_tokens FILE TOKENS OUTFILE)\n\ |
298 | Find all occurrences of TOKENS in FILE and output specified context around\n\ |
299 | the token. Results are appended to OUTFILE, if OUTFILE is nil, output\n\ |
300 | goes to stdout."); |
301 | } |
302 |