Debian Codegraph @

3rdparty/flite_hts_engine/flite/src/synth/cst_synth.c

raw symbols SCIP
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2000 */
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 /* CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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 ([email protected]) */
34 /* Date: September 2000 */
35 /*************************************************************************/
36 /* */
37 /* General synthesis control */
38 /* */
39 /*************************************************************************/
40
41 /* ----------------------------------------------------------------- */
42 /* The English TTS System "Flite+hts_engine" */
43 /* developed by HTS Working Group */
44 /* http://hts-engine.sourceforge.net/ */
45 /* ----------------------------------------------------------------- */
46 /* */
47 /* Copyright (c) 2005-2013 Nagoya Institute of Technology */
48 /* Department of Computer Science */
49 /* */
50 /* 2005-2008 Tokyo Institute of Technology */
51 /* Interdisciplinary Graduate School of */
52 /* Science and Engineering */
53 /* */
54 /* All rights reserved. */
55 /* */
56 /* Redistribution and use in source and binary forms, with or */
57 /* without modification, are permitted provided that the following */
58 /* conditions are met: */
59 /* */
60 /* - Redistributions of source code must retain the above copyright */
61 /* notice, this list of conditions and the following disclaimer. */
62 /* - Redistributions in binary form must reproduce the above */
63 /* copyright notice, this list of conditions and the following */
64 /* disclaimer in the documentation and/or other materials provided */
65 /* with the distribution. */
66 /* - Neither the name of the HTS working group nor the names of its */
67 /* contributors may be used to endorse or promote products derived */
68 /* from this software without specific prior written permission. */
69 /* */
70 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
71 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
72 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
73 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
74 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
75 /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
76 /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
77 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
78 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
79 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
80 /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
81 /* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
82 /* POSSIBILITY OF SUCH DAMAGE. */
83 /* ----------------------------------------------------------------- */
84
85 #include "cst_hrg.h"
86 #include "cst_cart.h"
87 #include "cst_tokenstream.h"
88 #include "cst_utt_utils.h"
89 #include "cst_lexicon.h"
90 #ifndef FLITE_PLUS_HTS_ENGINE
91 #include "cst_units.h"
92 #endif /* !FLITE_PLUS_HTS_ENIGINE */
93 #include "cst_synth.h"
94 #include "cst_phoneset.h"
95
96 CST_VAL_REGISTER_FUNCPTR(breakfunc,cst_breakfunc)
97
98 #ifndef SYNTH_MODULES_DEBUG
99 #define SYNTH_MODULES_DEBUG 0
100 #endif
101
102 #if SYNTH_MODULES_DEBUG > 0
103 #define DPRINTF(l,x) if (SYNTH_MODULES_DEBUG > l) cst_dbgmsg x
104 #else
105 #define DPRINTF(l,x)
106 #endif
107
108 static cst_utterance *tokentosegs(cst_utterance *u);
109
110 static const cst_synth_module synth_method_text[] = {
111 { "tokenizer_func", default_tokenization },
112 { "textanalysis_func", default_textanalysis },
113 { "pos_tagger_func", default_pos_tagger },
114 { "phrasing_func", default_phrasing },
115 { "lexical_insertion_func", default_lexical_insertion },
116 { "pause_insertion_func", default_pause_insertion },
117 { "intonation_func", cart_intonation },
118 { "postlex_func", NULL },
119 #ifndef FLITE_PLUS_HTS_ENGINE
120 { "duration_model_func", cart_duration },
121 { "f0_model_func", NULL },
122 { "wave_synth_func", NULL },
123 { "post_synth_hook_func", NULL },
124 #endif /* !FLITE_PLUS_HTS_ENIGINE */
125 { NULL, NULL }
126 };
127
128 #ifndef FLITE_PLUS_HTS_ENGINE
129 static const cst_synth_module synth_method_text2segs[] = {
130 { "tokenizer_func", default_tokenization },
131 { "textanalysis_func", default_textanalysis },
132 { "pos_tagger_func", default_pos_tagger },
133 { "phrasing_func", default_phrasing },
134 { "lexical_insertion_func", default_lexical_insertion },
135 { "pause_insertion_func", default_pause_insertion },
136 { NULL, NULL }
137 };
138
139 static const cst_synth_module synth_method_tokens[] = {
140 { "textanalysis_func", default_textanalysis },
141 { "pos_tagger_func", default_pos_tagger },
142 { "phrasing_func", default_phrasing },
143 { "lexical_insertion_func", default_lexical_insertion },
144 { "pause_insertion_func", default_pause_insertion },
145 { "intonation_func", cart_intonation },
146 { "postlex_func", NULL },
147 { "duration_model_func", cart_duration },
148 { "f0_model_func", NULL },
149 { "wave_synth_func", NULL },
150 { "post_synth_hook_func", NULL },
151 { NULL, NULL }
152 };
153
154 static const cst_synth_module synth_method_phones[] = {
155 { "tokenizer_func", default_tokenization },
156 { "textanalysis_func", tokentosegs },
157 { "pos_tagger_func", default_pos_tagger },
158 { "intonation_func", NULL },
159 { "duration_model_func", cart_duration },
160 { "f0_model_func", flat_prosody },
161 { "wave_synth_func", NULL },
162 { "post_synth_hook_func", NULL },
163 { NULL, NULL }
164 };
165 #endif /* !FLITE_PLUS_HTS_ENGINE */
166
167 cst_utterance *apply_synth_module(cst_utterance *u,
168 const cst_synth_module *mod)
169 {
170 const cst_val *v;
171
172 v = feat_val(u->features, mod->hookname);
173 if (v)
174 return (*val_uttfunc(v))(u);
175 if (mod->defhook)
176 return (*mod->defhook)(u);
177 return u;
178 }
179
180 cst_utterance *apply_synth_method(cst_utterance *u,
181 const cst_synth_module meth[])
182 {
183 while (meth->hookname)
184 {
185 if ((u = apply_synth_module(u, meth)) == NULL)
186 return NULL;
187 ++meth;
188 }
189
190 return u;
191 }
192
193 cst_utterance *utt_init(cst_utterance *u, cst_voice *vox)
194 {
195 feat_copy_into(vox->features,u->features);
196 feat_copy_into(vox->ffunctions,u->ffunctions);
197 if (vox->utt_init)
198 vox->utt_init(u, vox);
199
200 return u;
201 }
202
203 cst_utterance *utt_synth(cst_utterance *u)
204 {
205 return apply_synth_method(u, synth_method_text);
206 }
207
208 #ifndef FLITE_PLUS_HTS_ENGINE
209 cst_utterance *utt_synth_tokens(cst_utterance *u)
210 {
211 return apply_synth_method(u, synth_method_tokens);
212 }
213
214 cst_utterance *utt_synth_text2segs(cst_utterance *u)
215 {
216 return apply_synth_method(u, synth_method_text2segs);
217 }
218
219 cst_utterance *utt_synth_phones(cst_utterance *u)
220 {
221 return apply_synth_method(u, synth_method_phones);
222 }
223 #endif /* !FLITE_PLUS_HTS_ENGINE */
224
225 cst_utterance *default_tokenization(cst_utterance *u)
226 {
227 const char *text,*token;
228 cst_tokenstream *fd;
229 cst_item *t;
230 cst_relation *r;
231
232 text = utt_input_text(u);
233 r = utt_relation_create(u,"Token");
234 fd = ts_open_string(text,
235 get_param_string(u->features,"text_whitespace",NULL),
236 get_param_string(u->features,"text_singlecharsymbols",NULL),
237 get_param_string(u->features,"text_prepunctuation",NULL),
238 get_param_string(u->features,"text_postpunctuation",NULL));
239
240 while(!ts_eof(fd))
241 {
242 token = ts_get(fd);
243 if (cst_strlen(token) > 0)
244 {
245 t = relation_append(r,NULL);
246 item_set_string(t,"name",token);
247 item_set_string(t,"whitespace",fd->whitespace);
248 item_set_string(t,"prepunctuation",fd->prepunctuation);
249 item_set_string(t,"punc",fd->postpunctuation);
250 item_set_int(t,"file_pos",fd->file_pos);
251 item_set_int(t,"line_number",fd->line_number);
252 }
253 }
254
255 ts_close(fd);
256
257 return u;
258 }
259
260 cst_val *default_tokentowords(cst_item *i)
261 {
262 return cons_val(string_val(item_feat_string(i,"name")), NULL);
263 }
264
265 cst_utterance *default_textanalysis(cst_utterance *u)
266 {
267 cst_item *t,*word;
268 cst_relation *word_rel;
269 cst_val *words;
270 const cst_val *w;
271 const cst_val *ttwv;
272
273 word_rel = utt_relation_create(u,"Word");
274 ttwv = feat_val(u->features, "tokentowords_func");
275
276 for (t=relation_head(utt_relation(u,"Token")); t; t=item_next(t))
277 {
278 if (ttwv)
279 words = (cst_val *)(*val_itemfunc(ttwv))(t);
280 else
281 words = default_tokentowords(t);
282
283 for (w=words; w; w=val_cdr(w))
284 {
285 word = item_add_daughter(t,NULL);
286 if (cst_val_consp(val_car(w)))
287 { /* Has extra features */
288 item_set_string(word,"name",val_string(val_car(val_car(w))));
289 feat_copy_into(val_features(val_cdr(val_car(w))),
290 item_feats(word));
291 }
292 else
293 item_set_string(word,"name",val_string(val_car(w)));
294 relation_append(word_rel,word);
295 }
296 delete_val(words);
297 }
298
299 return u;
300 }
301
302 cst_utterance *default_phrasing(cst_utterance *u)
303 {
304 cst_relation *r;
305 cst_item *w, *p, *lp=NULL;
306 const cst_val *v;
307 cst_cart *phrasing_cart;
308
309 r = utt_relation_create(u,"Phrase");
310 phrasing_cart = val_cart(feat_val(u->features,"phrasing_cart"));
311
312 for (p=NULL,w=relation_head(utt_relation(u,"Word")); w; w=item_next(w))
313 {
314 if (p == NULL)
315 {
316 p = relation_append(r,NULL);
317 lp = p;
318 #ifdef FLITE_PLUS_HTS_ENGINE
319 item_set_string(p,"name","BB");
320 #else
321 item_set_string(p,"name","B");
322 #endif /* FLITE_PLUS_HTS_ENGINE */
323 }
324 item_add_daughter(p,w);
325 v = cart_interpret(w,phrasing_cart);
326 if (cst_streq(val_string(v),"BB"))
327 p = NULL;
328 }
329
330 if (lp && item_prev(lp)) /* follow festival */
331 item_set_string(lp,"name","BB");
332
333 return u;
334 }
335
336 cst_utterance *default_pause_insertion(cst_utterance *u)
337 {
338 /* Add initial silences and silence at each phrase break */
339 const char *silence;
340 const cst_item *w;
341 cst_item *p, *s;
342
343 silence = val_string(feat_val(u->features,"silence"));
344
345 /* Insert initial silence */
346 s = relation_head(utt_relation(u,"Segment"));
347 if (s == NULL)
348 s = relation_append(utt_relation(u,"Segment"),NULL);
349 else
350 s = item_prepend(s,NULL);
351 item_set_string(s,"name",silence);
352
353 for (p=relation_head(utt_relation(u,"Phrase")); p; p=item_next(p))
354 {
355 for (w = item_last_daughter(p); w; w=item_prev(w))
356 {
357 s = path_to_item(w,"R:SylStructure.daughtern.daughtern.R:Segment");
358 if (s)
359 {
360 s = item_append(s,NULL);
361 item_set_string(s,"name",silence);
362 break;
363 }
364 }
365 }
366
367 return u;
368 }
369
370 cst_utterance *cart_intonation(cst_utterance *u)
371 {
372 cst_cart *accents, *tones;
373 cst_item *s;
374 const cst_val *v;
375
376 if (feat_present(u->features,"no_intonation_accent_model"))
377 return u; /* not all languages have intonation models */
378
379 accents = val_cart(feat_val(u->features,"int_cart_accents"));
380 tones = val_cart(feat_val(u->features,"int_cart_tones"));
381
382 for (s=relation_head(utt_relation(u,"Syllable")); s; s=item_next(s))
383 {
384 v = cart_interpret(s,accents);
385 if (!cst_streq("NONE",val_string(v)))
386 item_set_string(s,"accent",val_string(v));
387 v = cart_interpret(s,tones);
388 if (!cst_streq("NONE",val_string(v)))
389 item_set_string(s,"endtone",val_string(v));
390 DPRINTF(0,("word %s gpos %s stress %s ssyl_in %s ssyl_out %s accent %s endtone %s\n",
391 ffeature_string(s,"R:SylStructure.parent.name"),
392 ffeature_string(s,"R:SylStructure.parent.gpos"),
393 ffeature_string(s,"stress"),
394 ffeature_string(s,"ssyl_in"),
395 ffeature_string(s,"ssyl_out"),
396 ffeature_string(s,"accent"),
397 ffeature_string(s,"endtone")));
398 }
399
400 return u;
401 }
402
403 CST_VAL_REGISTER_TYPE_NODEL(dur_stats,dur_stats)
404
405 #ifndef FLITE_PLUS_HTS_ENGINE
406 const dur_stat *phone_dur_stat(const dur_stats *ds,const char *ph)
407 {
408 int i;
409 for (i=0; ds[i]; i++)
410 if (cst_streq(ph,ds[i]->phone))
411 return ds[i];
412
413 return ds[0];
414 }
415
416 cst_utterance *cart_duration(cst_utterance *u)
417 {
418 cst_cart *dur_tree;
419 cst_item *s;
420 float zdur, dur_stretch, local_dur_stretch, dur;
421 float end;
422 dur_stats *ds;
423 const dur_stat *dur_stat;
424
425 end = 0;
426
427 if (feat_present(u->features,"no_segment_duration_model"))
428 return u; /* not all methods need segment durations */
429
430 dur_tree = val_cart(feat_val(u->features,"dur_cart"));
431 dur_stretch = get_param_float(u->features,"duration_stretch", 1.0);
432 ds = val_dur_stats(feat_val(u->features,"dur_stats"));
433
434 for (s=relation_head(utt_relation(u,"Segment")); s; s=item_next(s))
435 {
436 zdur = val_float(cart_interpret(s,dur_tree));
437 dur_stat = phone_dur_stat(ds,item_name(s));
438
439 local_dur_stretch = ffeature_float(s, "R:SylStructure.parent.parent."
440 "R:Token.parent.local_duration_stretch");
441 if (local_dur_stretch)
442 local_dur_stretch *= dur_stretch;
443 else
444 local_dur_stretch = dur_stretch;
445
446 dur = local_dur_stretch * ((zdur*dur_stat->stddev)+dur_stat->mean);
447 DPRINTF(0,("phone %s accent %s stress %s pdur %f stretch %f mean %f std %f dur %f\n",
448 item_name(s),
449 ffeature_string(s,"R:SylStructure.parent.accented"),
450 ffeature_string(s,"R:SylStructure.parent.stress"),
451 zdur, local_dur_stretch, dur_stat->mean,
452 dur_stat->stddev, dur));
453 end += dur;
454 item_set_float(s,"end",end);
455 }
456 return u;
457 }
458 #endif /* !FLITE_PLUS_HTS_ENIGINE */
459
460 cst_utterance *default_pos_tagger(cst_utterance *u)
461 {
462 cst_item *word;
463 const cst_val *p;
464 const cst_cart *tagger;
465
466 p = get_param_val(u->features,"pos_tagger_cart",NULL);
467 if (p == NULL)
468 return u;
469 tagger = val_cart(p);
470
471 for (word=relation_head(utt_relation(u,"Word"));
472 word; word=item_next(word))
473 {
474 p = cart_interpret(word,tagger);
475 item_set_string(word,"pos",val_string(p));
476 }
477
478 return u;
479 }
480
481 cst_utterance *default_lexical_insertion(cst_utterance *u)
482 {
483 cst_item *word;
484 cst_relation *sylstructure,*seg,*syl;
485 cst_lexicon *lex;
486 const cst_val *lex_addenda = NULL;
487 const cst_val *p, *wp = NULL;
488 char *phone_name;
489 char *stress = "0";
490 const char *pos;
491 cst_val *phones;
492 cst_item *ssword, *sssyl, *segitem, *sylitem, *seg_in_syl;
493
494 lex = val_lexicon(feat_val(u->features,"lexicon"));
495 if (lex->lex_addenda)
496 lex_addenda = lex->lex_addenda;
497
498 syl = utt_relation_create(u,"Syllable");
499 sylstructure = utt_relation_create(u,"SylStructure");
500 seg = utt_relation_create(u,"Segment");
501
502 for (word=relation_head(utt_relation(u,"Word"));
503 word; word=item_next(word))
504 {
505 ssword = relation_append(sylstructure,word);
506 pos = ffeature_string(word,"pos");
507 phones = NULL;
508 wp = NULL;
509
510 /* printf("awb_debug word %s pos %s gpos %s\n",
511 item_feat_string(word,"name"),
512 pos,
513 ffeature_string(word,"gpos")); */
514
515 /* FIXME: need to make sure that textanalysis won't split
516 tokens with explicit pronunciation (or that it will
517 propagate such to words, then we can remove the path here) */
518 if (item_feat_present(item_parent(item_as(word, "Token")), "phones"))
519 phones = (cst_val *) item_feat(item_parent(item_as(word, "Token")), "phones");
520 else
521 {
522 wp = val_assoc_string(item_feat_string(word, "name"),lex_addenda);
523 if (wp)
524 phones = (cst_val *)val_cdr(val_cdr(wp));
525 else
526 phones = lex_lookup(lex,item_feat_string(word,"name"),pos);
527 }
528
529 for (sssyl=NULL,sylitem=NULL,p=phones; p; p=val_cdr(p))
530 {
531 if (sylitem == NULL)
532 {
533 sylitem = relation_append(syl,NULL);
534 sssyl = item_add_daughter(ssword,sylitem);
535 stress = "0";
536 }
537 segitem = relation_append(seg,NULL);
538 phone_name = cst_strdup(val_string(val_car(p)));
539 if (phone_name[cst_strlen(phone_name)-1] == '1')
540 {
541 stress = "1";
542 phone_name[cst_strlen(phone_name)-1] = '\0';
543 }
544 else if (phone_name[cst_strlen(phone_name)-1] == '0')
545 {
546 stress = "0";
547 phone_name[cst_strlen(phone_name)-1] = '\0';
548 }
549 item_set_string(segitem,"name",phone_name);
550 seg_in_syl = item_add_daughter(sssyl,segitem);
551 #if 0
552 printf("awb_debug ph %s\n",phone_name);
553 #endif
554 if ((lex->syl_boundary)(seg_in_syl,val_cdr(p)))
555 {
556 #if 0
557 printf("awb_debug SYL\n");
558 #endif
559 sylitem = NULL;
560 if (sssyl)
561 item_set_string(sssyl,"stress",stress);
562 }
563 cst_free(phone_name);
564 }
565 if (!item_feat_present(item_parent(item_as(word, "Token")), "phones")
566 && ! wp)
567 delete_val(phones);
568 }
569
570 return u;
571 }
572
573 #ifndef FLITE_PLUS_HTS_ENGINE
574 /* Dummy F0 modelling for phones, copied directly from us_f0_model.c */
575 cst_utterance *flat_prosody(cst_utterance *u)
576 {
577 /* F0 target model */
578 cst_item *s,*t;
579 cst_relation *targ_rel;
580 float mean, stddev;
581
582 targ_rel = utt_relation_create(u,"Target");
583 mean = get_param_float(u->features,"target_f0_mean", 100.0);
584 mean *= get_param_float(u->features,"f0_shift", 1.0);
585 stddev = get_param_float(u->features,"target_f0_stddev", 12.0);
586
587 s=relation_head(utt_relation(u,"Segment"));
588 t = relation_append(targ_rel,NULL);
589 item_set_float(t,"pos",0.0);
590 item_set_float(t,"f0",mean+stddev);
591
592 s=relation_tail(utt_relation(u,"Segment"));
593 t = relation_append(targ_rel,NULL);
594
595 item_set_float(t,"pos",item_feat_float(s,"end"));
596 item_set_float(t,"f0",mean-stddev);
597
598 return u;
599 }
600
601 static cst_utterance *tokentosegs(cst_utterance *u)
602 {
603 cst_item *t;
604 cst_relation *seg, *syl, *sylstructure, *word;
605 cst_item *sylitem, *sylstructureitem, *worditem, *sssyl;
606 cst_phoneset *ps;
607
608 ps = val_phoneset(utt_feat_val(u, "phoneset"));
609 /* Just copy tokens into the Segment relation */
610 seg = utt_relation_create(u, "Segment");
611 syl = utt_relation_create(u, "Syllable");
612 word = utt_relation_create(u, "Word");
613 sylstructure = utt_relation_create(u, "SylStructure");
614 sssyl = sylitem = worditem = sylstructureitem = 0;
615 for (t = relation_head(utt_relation(u, "Token")); t; t = item_next(t))
616 {
617 cst_item *segitem = relation_append(seg, NULL);
618 char const *pname = item_feat_string(t, "name");
619 char *name = cst_strdup(pname);
620
621 if (worditem == 0)
622 {
623 worditem = relation_append(word,NULL);
624 item_set_string(worditem, "name", "phonestring");
625 sylstructureitem = relation_append(sylstructure,worditem);
626 }
627 if (sylitem == 0)
628 {
629 sylitem = relation_append(syl,NULL);
630 sssyl = item_add_daughter(sylstructureitem,sylitem);
631 }
632
633 if (name[cst_strlen(name)-1] == '1')
634 {
635 item_set_string(sssyl,"stress","1");
636 name[cst_strlen(name)-1] = '\0';
637 }
638 else if (name[cst_strlen(name)-1] == '0')
639 {
640 item_set_string(sssyl,"stress","0");
641 name[cst_strlen(name)-1] = '\0';
642 }
643
644 if (cst_streq(name,"-"))
645 {
646 sylitem = 0; /* syllable break */
647 }
648 else if (phone_id(ps, name) == -1)
649 {
650 cst_errmsg("Phone `%s' not in phoneset\n", pname);
651 cst_error();
652 }
653 else
654 {
655 item_add_daughter(sssyl,segitem);
656 item_set_string(segitem, "name", name);
657 }
658
659 cst_free(name);
660 }
661
662 return u;
663 }
664 #endif /* !FLITE_PLUS_HTS_ENIGINE */
665
666 int default_utt_break(cst_tokenstream *ts,
667 const char *token,
668 cst_relation *tokens)
669 {
670 /* This is the default utt break functions, languages may override this */
671 /* This will be ok for some latin based languages */
672 const char *postpunct = item_feat_string(relation_tail(tokens), "punc");
673 const char *ltoken = item_name(relation_tail(tokens));
674
675 if (cst_strchr(ts->whitespace,'\n') != cst_strrchr(ts->whitespace,'\n'))
676 /* contains two new lines */
677 return TRUE;
678 else if (strchr(postpunct,':') ||
679 strchr(postpunct,'?') ||
680 strchr(postpunct,'!'))
681 return TRUE;
682 else if (strchr(postpunct,'.') &&
683 (cst_strlen(ts->whitespace) > 1) &&
684 strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",token[0]))
685 return TRUE;
686 else if (strchr(postpunct,'.') &&
687 /* next word starts with a capital */
688 strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",token[0]) &&
689 /* last word isn't an abbreviation */
690 !(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ltoken[cst_strlen(ltoken)-1])||
691 ((cst_strlen(ltoken) < 4) &&
692 strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",ltoken[0]))))
693 return TRUE;
694 else
695 return FALSE;
696 }