cst_utterance *cart_intonation(cst_utterance *u) { cst_cart *accents, *tones; cst_item *s; const cst_val *v; if (feat_present(u->features,"no_intonation_accent_model")) return u; /* not all languages have intonation models */ accents = val_cart(feat_val(u->features,"int_cart_accents")); tones = val_cart(feat_val(u->features,"int_cart_tones")); for (s=relation_head(utt_relation(u,"Syllable")); s; s=item_next(s)) { v = cart_interpret(s,accents); if (!cst_streq("NONE",val_string(v))) item_set_string(s,"accent",val_string(v)); v = cart_interpret(s,tones); if (!cst_streq("NONE",val_string(v))) item_set_string(s,"endtone",val_string(v)); DPRINTF(0,("word %s gpos %s stress %s ssyl_in %s ssyl_out %s accent %s endtone %s\n", ffeature_string(s,"R:SylStructure.parent.name"), ffeature_string(s,"R:SylStructure.parent.gpos"), ffeature_string(s,"stress"), ffeature_string(s,"ssyl_in"), ffeature_string(s,"ssyl_out"), ffeature_string(s,"accent"), ffeature_string(s,"endtone"))); } return u; }
cst_utterance *cst_spamf0(cst_utterance *utt) { cst_track *spamf0_track = NULL; cst_track *param_track = NULL; cst_item *s; cst_cg_db *cg_db; const cst_cart *acc_tree, *phrase_tree; float end, f0val, syldur; int num_frames, f, i; cg_db = val_cg_db(utt_feat_val(utt, "cg_db")); spamf0_track = new_track(); cst_track_resize(spamf0_track, (utt_feat_int(utt, "param_track_num_frames")), 1); acc_tree = cg_db->spamf0_accent_tree; phrase_tree = cg_db->spamf0_phrase_tree; end = 0.0; num_frames = 0; for (s = utt_rel_head(utt, "Segment"); s; s = item_next(s)) { end = ffeature_float(s, "end"); if (cst_streq("pau", ffeature_string(s, "name"))) { f0val = 0; } else { f0val = val_float(cart_interpret(s, phrase_tree)); } for (; ((num_frames * cg_db->frame_advance) <= end) && (num_frames < utt_feat_int(utt, "param_track_num_frames")); num_frames++) { spamf0_track->frames[num_frames][0] = f0val; } } for (s = utt_rel_head(utt, "Syllable"); s; s = item_next(s)) { f = val_int(cart_interpret(s, acc_tree)); syldur = ffeature_float(s, "R:SylStructure.daughtern.R:Segment.end") - ffeature_float(s, "R:SylStructure.daughter1.R:Segment.p.end"); cst_synthtilt(cg_db, ffeature_float(s, "R:SylStructure.daughter1.R:Segment.p.end"), cg_db->spamf0_accent_vectors[f][0], cg_db->spamf0_accent_vectors[f][2], syldur, cg_db->spamf0_accent_vectors[f][6], spamf0_track); } param_track = val_track(utt_feat_val(utt, "param_track")); for (i = 0; i < utt_feat_int(utt, "param_track_num_frames"); i++) { param_track->frames[i][0] = spamf0_track->frames[i][0]; } delete_track(spamf0_track); return utt; }
cst_utterance *default_phrasing(cst_utterance *u) { cst_relation *r; cst_item *w, *p, *lp=NULL; const cst_val *v; cst_cart *phrasing_cart; r = utt_relation_create(u,"Phrase"); phrasing_cart = val_cart(feat_val(u->features,"phrasing_cart")); for (p=NULL,w=relation_head(utt_relation(u,"Word")); w; w=item_next(w)) { if (p == NULL) { p = relation_append(r,NULL); lp = p; #ifdef FLITE_PLUS_HTS_ENGINE item_set_string(p,"name","BB"); #else item_set_string(p,"name","B"); #endif /* FLITE_PLUS_HTS_ENGINE */ } item_add_daughter(p,w); v = cart_interpret(w,phrasing_cart); if (cst_streq(val_string(v),"BB")) p = NULL; } if (lp && item_prev(lp)) /* follow festival */ item_set_string(lp,"name","BB"); return u; }
static float cg_state_duration(cst_item *s, cst_cg_db *cg_db) { float zdur, dur; const char *n; int i, x; zdur = val_float(cart_interpret(s,cg_db->dur_cart)); n = item_feat_string(s,"name"); for (x=i=0; cg_db->dur_stats[i]; i++) { if (cst_streq(cg_db->dur_stats[i]->phone,n)) { x=i; break; } } if (!cg_db->dur_stats[i]) /* unknown type name */ x = 0; dur = (zdur*cg_db->dur_stats[x]->stddev)+cg_db->dur_stats[x]->mean; /* dur = 1.2 * (float)exp((float)dur); */ return dur; }
cst_utterance *default_phrasing(cst_utterance *u) { cst_relation *r; cst_item *w, *p; const cst_val *v; cst_cart *phrasing_cart; r = utt_relation_create(u,"Phrase"); phrasing_cart = val_cart(feat_val(u->features,"phrasing_cart")); for (p=NULL,w=relation_head(utt_relation(u,"Word")); w; w=item_next(w)) { if (p == NULL) { p = relation_append(r,NULL); item_set_string(p,"name","BB"); } item_add_daughter(p,w); v = cart_interpret(w,phrasing_cart); if (cst_streq(val_string(v),"BB")) p = NULL; } return u; }
static float cg_state_duration(cst_item *s, cst_cg_db *cg_db) { float zdur, dur; const char *n; int i, x; #ifdef STATICANALYZEDEPENDENCIES #define __clang_analyzer__ 1 #endif #if !defined(__clang_analyzer__) || defined(STATICANALYZEDEPENDENCIES) #undef __clang_analyzer__ zdur = val_float(cart_interpret(s,cg_db->dur_cart)); n = item_feat_string(s,"name"); for (x=i=0; cg_db->dur_stats[i]; i++) { if (cst_streq(cg_db->dur_stats[i]->phone,n)) { x=i; break; } } if (!cg_db->dur_stats[i]) /* unknown type name */ x = 0; dur = (zdur*cg_db->dur_stats[x]->stddev)+cg_db->dur_stats[x]->mean; /* dur = 1.2 * (float)exp((float)dur); */ return dur; }
cst_utterance *russian_postlex_function(cst_utterance *u) { const cst_item *word,*seg; const char *answer,*name,*pair; for(word=relation_head(utt_relation(u,"Transcription"));word;word=item_next(word)) { if(item_feat_present(word,"no_pl")||item_feat_present(word,"no_vr")) continue; for(seg=item_daughter(word);seg;seg=item_next(seg)) { name=item_feat_string(seg,"name"); if(cst_member_string(name,unstressed_vowels)) { answer=val_string(cart_interpret(item_as(seg,"Segment"),&ru_vowel_reduction_cart)); if(!cst_streq(answer,"N")) item_set_string(seg,"name",answer); } else { if(cst_streq(name,"ii")&& cst_streq(ffeature_string(seg,"R:Segment.p.ph_csoft"),"-")&& !(cst_streq(item_feat_string(word,"name"),"и")&& cst_streq(ffeature_string(word,"gpos"),"content"))) { item_set_string(seg,"name","yy"); } } } } for(word=relation_tail(utt_relation(u,"Transcription"));word;word=item_prev(word)) { if(item_feat_present(word,"no_pl")) continue; for(seg=item_last_daughter(word);seg;seg=item_prev(seg)) { name=item_feat_string(seg,"name"); pair=russian_vpair(name); if(pair!=NULL) { answer=val_string(cart_interpret(item_as(seg,"Segment"),&ru_vpair_cart)); if(cst_streq(answer,"Y")) item_set_string(seg,"name",pair); } } } return u; }
cst_utterance *cart_duration(cst_utterance *u) { cst_cart *dur_tree; cst_item *s; float zdur, dur_stretch, local_dur_stretch, dur; float end; dur_stats *ds; const dur_stat *dur_stat; end = 0; if (feat_present(u->features,"no_segment_duration_model")) return u; /* not all methods need segment durations */ dur_tree = val_cart(feat_val(u->features,"dur_cart")); dur_stretch = get_param_float(u->features,"duration_stretch", 1.0); ds = val_dur_stats(feat_val(u->features,"dur_stats")); for (s=relation_head(utt_relation(u,"Segment")); s; s=item_next(s)) { zdur = val_float(cart_interpret(s,dur_tree)); dur_stat = phone_dur_stat(ds,item_name(s)); local_dur_stretch = ffeature_float(s, "R:SylStructure.parent.parent." "R:Token.parent.local_duration_stretch"); if (local_dur_stretch) local_dur_stretch *= dur_stretch; else local_dur_stretch = dur_stretch; dur = local_dur_stretch * ((zdur*dur_stat->stddev)+dur_stat->mean); DPRINTF(0,("phone %s accent %s stress %s pdur %f stretch %f mean %f std %f dur %f\n", item_name(s), ffeature_string(s,"R:SylStructure.parent.accented"), ffeature_string(s,"R:SylStructure.parent.stress"), zdur, local_dur_stretch, dur_stat->mean, dur_stat->stddev, dur)); end += dur; item_set_float(s,"end",end); } return u; }
cst_utterance *default_pos_tagger(cst_utterance *u) { cst_item *word; const cst_val *p; const cst_cart *tagger; p = get_param_val(u->features,"pos_tagger_cart",NULL); if (p == NULL) return u; tagger = val_cart(p); for (word=relation_head(utt_relation(u,"Word")); word; word=item_next(word)) { p = cart_interpret(word,tagger); item_set_string(word,"pos",val_string(p)); } return u; }
static cst_utterance *cg_predict_params(cst_utterance *utt) { cst_cg_db *cg_db; cst_track *param_track; cst_track *str_track = NULL; cst_item *mcep; const cst_cart *mcep_tree, *f0_tree; int i,j,f,p,fd,o; const char *mname; float f0_val; int fff; int extra_feats = 0; cg_db = val_cg_db(utt_feat_val(utt,"cg_db")); param_track = new_track(); if (cg_db->do_mlpg) /* which should be the default */ fff = 1; /* copy details with stddevs */ else fff = 2; /* copy details without stddevs */ extra_feats = 1; /* voicing */ if (cg_db->mixed_excitation) { extra_feats += 5; str_track = new_track(); cst_track_resize(str_track, utt_feat_int(utt,"param_track_num_frames"), 5); } cst_track_resize(param_track, utt_feat_int(utt,"param_track_num_frames"), (cg_db->num_channels0/fff)- (2 * extra_feats));/* no voicing or str */ for (i=0,mcep=utt_rel_head(utt,"mcep"); mcep; i++,mcep=item_next(mcep)) { mname = item_feat_string(mcep,"name"); for (p=0; cg_db->types[p]; p++) if (cst_streq(mname,cg_db->types[p])) break; if (cg_db->types[0] == NULL) p=0; /* if there isn't a matching tree, use the first one */ /* Predict F0 */ f0_tree = cg_db->f0_trees[p]; f0_val = val_float(cart_interpret(mcep,f0_tree)); param_track->frames[i][0] = f0_val; /* what about stddev ? */ if (cg_db->multimodel) { /* MULTI model */ f = val_int(cart_interpret(mcep,cg_db->param_trees0[p])); fd = val_int(cart_interpret(mcep,cg_db->param_trees1[p])); item_set_int(mcep,"clustergen_param_frame",f); param_track->frames[i][0] = (param_track->frames[i][0]+ CG_MODEL_VECTOR(cg_db,model_vectors0,f,0)+ CG_MODEL_VECTOR(cg_db,model_vectors1,fd,0))/3.0; for (j=2; j<param_track->num_channels; j++) param_track->frames[i][j] = (CG_MODEL_VECTOR(cg_db,model_vectors0,f,(j)*fff)+ CG_MODEL_VECTOR(cg_db,model_vectors1,fd,(j)*fff))/2.0; if (cg_db->mixed_excitation) { o = j; for (j=0; j<5; j++) { str_track->frames[i][j] = (CG_MODEL_VECTOR(cg_db,model_vectors0,f,(o+(2*j))*fff)+ CG_MODEL_VECTOR(cg_db,model_vectors1,fd,(o+(2*j))*fff))/2.0; } } } else { /* SINGLE model */ /* Predict Spectral */ mcep_tree = cg_db->param_trees0[p]; f = val_int(cart_interpret(mcep,mcep_tree)); item_set_int(mcep,"clustergen_param_frame",f); param_track->frames[i][0] = (param_track->frames[i][0]+ CG_MODEL_VECTOR(cg_db,model_vectors0,f,0))/2.0; for (j=2; j<param_track->num_channels; j++) param_track->frames[i][j] = CG_MODEL_VECTOR(cg_db,model_vectors0,f,(j)*fff); if (cg_db->mixed_excitation) { o = j; for (j=0; j<5; j++) { str_track->frames[i][j] = CG_MODEL_VECTOR(cg_db,model_vectors0,f,(o+(2*j))*fff); } } } /* last coefficient is average voicing for cluster */ item_set_float(mcep,"voicing", CG_MODEL_VECTOR(cg_db,model_vectors0,f, cg_db->num_channels0-2)); param_track->times[i] = i * cg_db->frame_advance; } cg_smooth_F0(utt,cg_db,param_track); utt_set_feat(utt,"param_track",track_val(param_track)); if (cg_db->mixed_excitation) utt_set_feat(utt,"str_track",track_val(str_track)); return utt; }
static void assign_stress(cst_item *word) { int numsyls=ffeature_int(word,"word_numsyls"); const char *gpos=ffeature_string(word,"gpos"); const cst_item *word_in_phrase=item_as(word,"Phrase"); const cst_item *syls=item_as(word,"SylStructure"); const cst_item *syl=item_daughter(syls); const cst_item *transcription=item_as(word,"Transcription"); int stressed=FALSE; int n=item_feat_present(word,"stressed_syl_num")?item_feat_int(word,"stressed_syl_num"):0; const char *name=item_name(word); const char *pname=ffeature_string(word,"R:Phrase.p.name"); const char *nname=ffeature_string(word,"R:Phrase.n.name"); if(cst_streq(ffeature_string(word,"R:Token.p.name"),"по")&& (cst_streq(name,"моему")||cst_streq(name,"своему")||cst_streq(name,"твоему"))) { item_set_string(syl,"stress","1"); return; } else if((cst_streq(name,"не")||cst_streq(name,"ни"))&& (cst_streq(nname,"был")||cst_streq(nname,"были")||cst_streq(nname,"было"))) { item_set_string(syl,"stress","1"); return; } else if((cst_streq(name,"был")||cst_streq(name,"были")||cst_streq(name,"было"))&& (cst_streq(pname,"не")||cst_streq(pname,"ни"))) return; else if(cst_streq(gpos,"enc")&&item_prev(word_in_phrase)) return; else if(cst_streq(gpos,"proc")&&item_next(word_in_phrase)) return; if(!vowel_seg_between(item_daughter(transcription),item_last_daughter(transcription))) return; if(numsyls==1) { item_set_string(syl,"stress","1"); return; } for(;syl;syl=item_next(syl)) { if(is_stressed_vowel(item_feat_string(item_daughter(item_as(syl,"SylVowel")),"name"))) { item_set_string(syl,"stress","1"); stressed=TRUE; } } if(n==0) { if(stressed) return; n=val_int(cart_interpret(word,&ru_stress_cart)); if((numsyls+n) < 0) { if(numsyls <= 4) n=-2; else if(numsyls <= 6) n=-3; else n=-4; } } item_set_string(item_nth_daughter(syls,(numsyls+n)),"stress","1"); }