| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
{ |
| 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 |
| 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)) |
| 331 |
item_set_string(lp,"name","BB"); |
| 332 |
|
| 333 |
return u; |
| 334 |
} |
| 335 |
|
| 336 |
cst_utterance *default_pause_insertion(cst_utterance *u) |
| 337 |
{ |
| 338 |
|
| 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 |
|
| 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; |
| 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; |
| 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 |
| 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 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 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 |
|
| 575 |
cst_utterance *flat_prosody(cst_utterance *u) |
| 576 |
{ |
| 577 |
|
| 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 |
|
| 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; |
| 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 |
| 665 |
|
| 666 |
int default_utt_break(cst_tokenstream *ts, |
| 667 |
const char *token, |
| 668 |
cst_relation *tokens) |
| 669 |
{ |
| 670 |
|
| 671 |
|
| 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 |
|
| 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 |
|
| 688 |
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",token[0]) && |
| 689 |
|
| 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 |
} |