📄 time_align.c
字号:
char *word; char *alt_marker; int compound_word_cnt; int *compound_word_id; COMPOUND_WORD_T *compound_word_list; E_INFO("Scanning dictionary for compound words: "); for (i = 0, compound_word_cnt = 0; i < word_dict->dict_entry_count; i++) { word = dict_list[i]->word; if (strchr(word + 1, '_') != NULL) { /* there is at least one underscore in the word beginning at the second character onward. Assume this is a compound word */ ++compound_word_cnt; } } E_INFO("%d compound words found\n", compound_word_cnt); compound_word_id = (int *) calloc(compound_word_cnt, sizeof(int)); /* rescan the dict to find the word id's of the compound words */ for (i = 0, j = 0; i < word_dict->dict_entry_count; i++) { word = dict_list[i]->word; if (strchr(word + 1, '_') != NULL) { /* there is at least one underscore in the word beginning at the second character onward. Assume this is a compound word */ alt_marker = strchr(word, '('); if (alt_marker == NULL) { compound_word_id[j++] = i; E_INFO("\tadding c. %s to list\n", word); } else { if (alt_marker[strlen(alt_marker) - 1] == ')') { E_INFO("skipping c. alt pron %s\n", word); } else { E_WARN ("unusual word format %s. Word not added to compound list\n", word); } } } } compound_word_cnt = j; compound_word_list = calloc(compound_word_cnt, sizeof(COMPOUND_WORD_T)); for (i = 0; i < compound_word_cnt; i++) { compound_word_list[i].word_id = compound_word_id[i]; compound_word_list[i].word_str = dict_list[compound_word_id[i]]->word; compound_word_list[i].match_str = cvt_uscores_to_sp(compound_word_list[i].word_str); compound_word_list[i].word_cnt = constituent_cnt(compound_word_list[i].word_str); } qsort(compound_word_list, compound_word_cnt, sizeof(COMPOUND_WORD_T), descending_order_by_len); free(compound_word_id); *out_cnt = compound_word_cnt; return compound_word_list;}static COMPOUND_WORD_T *compound_word_list;static int compound_word_cnt;inttime_align_init(void){ static char const *rcsid = "$Id: time_align.c,v 1.1.1.1 2006/05/23 18:45:01 dhuggins Exp $";#if SHOW&SHOW_INVOKATION E_INFO("time_align_init() called\n");#endif E_INFO("rcsid == %s\n", rcsid); sil_word_id = kb_get_word_id("SIL"); start_word_id = kb_get_word_id("<s>"); end_word_id = kb_get_word_id("</s>"); sil_phone_id = phone_to_id("SIL", FALSE); silb_phone_id = phone_to_id("SILb", FALSE); sile_phone_id = phone_to_id("SILe", FALSE); state_bp_table = ckd_calloc(max_state_bp_table_size, sizeof(BACK_POINTER_T)); E_INFO("state_bp_table size %dK\n", max_state_bp_table_size * sizeof(BACK_POINTER_T) / 1024); phone_bp_table = ckd_calloc(max_phone_bp_table_size, sizeof(BACK_POINTER_T)); E_INFO("phone_bp_table size %dK\n", max_phone_bp_table_size * sizeof(BACK_POINTER_T) / 1024); word_bp_table = ckd_calloc(max_word_bp_table_size, sizeof(BACK_POINTER_T)); E_INFO("word_bp_table size %dK\n", max_word_bp_table_size * sizeof(BACK_POINTER_T) / 1024); compound_word_list = mk_compound_word_list(&compound_word_cnt); return 0;}/* * Since more that one word string will be evaluated against the input, set * the input first to allow the possibility of avoiding reprocessing the input * data. */voidtime_align_set_input(mfcc_t ***feat, int n_f){ feat_f = feat; frame_cnt = n_f;#if SHOW&SHOW_INVOKATION E_INFO("time_align_set_input() called\n");#endif#if SHOW&SHOW_SUMMARY_INFO E_INFO("time_align_set_input() received %d of input\n", frame_cnt);#endif}static intbegin_triphone(int32 phone_id, int32 lc_phone_id, int32 rc_phone_id){ int32 out_phone_id; char phone_str[64]; char const *phone_name; char const *lc_phone_name; char const *rc_phone_name; assert(phone_id != NO_PHONE); assert(lc_phone_id != NO_PHONE); assert(rc_phone_id != NO_PHONE); phone_name = phone_from_id(phone_id); lc_phone_name = phone_from_id(lc_phone_id); rc_phone_name = phone_from_id(rc_phone_id); sprintf(phone_str, "%s(%s,%s)b", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { return out_phone_id; } sprintf(phone_str, "%s(%s,%s)", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s) approx'ed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s(SIL,%s)b", phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s) approx'ed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s(SIL,%s)", phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s) approx'ed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s", phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s) approx'ed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } E_ERROR(" %s(%s,%s) returned id NO_PHONE\n", phone_name, lc_phone_name, rc_phone_name); assert(FALSE); /* should never get here. But if we do, there are some big problems */ return 0;}static int32single_phone_word_triphone(int32 phone_id, int32 lc_phone_id, int32 rc_phone_id){ int32 out_phone_id; char phone_str[64]; char const *phone_name; char const *lc_phone_name; char const *rc_phone_name; assert(phone_id != NO_PHONE); assert(lc_phone_id != NO_PHONE); assert(rc_phone_id != NO_PHONE); phone_name = phone_from_id(phone_id); lc_phone_name = phone_from_id(lc_phone_id); rc_phone_name = phone_from_id(rc_phone_id); sprintf(phone_str, "%s(%s,%s)s", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) return out_phone_id; sprintf(phone_str, "%s(%s,%s)e", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) return out_phone_id; sprintf(phone_str, "%s(%s,%s)", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)s approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s(%s,SIL)e", phone_name, lc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)s approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s(%s,SIL)", phone_name, lc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)s approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s", phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)s approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } E_ERROR("%s(%s,%s) returned id NO_PHONE\n", phone_name, lc_phone_name, rc_phone_name); assert(FALSE); /* should never get here. But if we do, there are some big problems */ return 0;}static int32end_triphone(int32 phone_id, int32 lc_phone_id, int32 rc_phone_id){ int32 out_phone_id; char phone_str[64]; char const *phone_name; char const *lc_phone_name; char const *rc_phone_name; assert(phone_id != NO_PHONE); assert(lc_phone_id != NO_PHONE); assert(rc_phone_id != NO_PHONE); phone_name = phone_from_id(phone_id); lc_phone_name = phone_from_id(lc_phone_id); rc_phone_name = phone_from_id(rc_phone_id); sprintf(phone_str, "%s(%s,%s)e", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) return out_phone_id; sprintf(phone_str, "%s(%s,%s)", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)e approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s(%s,SIL)e", phone_name, lc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)e approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s(%s,SIL)", phone_name, lc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)e approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } sprintf(phone_str, "%s", phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)e approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } E_ERROR("%s(%s,%s) returned id NO_PHONE\n", phone_name, lc_phone_name, rc_phone_name); assert(FALSE); /* should never get here. But if we do, there are some big problems */ return 0;}static int32triphone(int32 phone_id, int32 lc_phone_id, int32 rc_phone_id){ char phone_str[64]; char const *phone_name; char const *lc_phone_name; char const *rc_phone_name; int32 out_phone_id; assert(phone_id != NO_PHONE); assert(lc_phone_id != NO_PHONE); assert(rc_phone_id != NO_PHONE); phone_name = phone_from_id(phone_id); lc_phone_name = phone_from_id(lc_phone_id); rc_phone_name = phone_from_id(rc_phone_id); sprintf(phone_str, "%s(%s,%s)", phone_name, lc_phone_name, rc_phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { return out_phone_id; } sprintf(phone_str, "%s", phone_name); out_phone_id = phone_to_id(phone_str, FALSE); if (out_phone_id != NO_PHONE) { E_INFO("%s(%s,%s)e approxed as %s\n", phone_name, lc_phone_name, rc_phone_name, phone_str); return out_phone_id; } E_ERROR("%s(%s,%s) returned id NO_PHONE\n", phone_name, lc_phone_name, rc_phone_name); assert(FALSE); /* should never get here */ return 0;}static voidadd_triphone(short *amatrix, int32 * phone_id_map, int *word_id_map, char *boundary, int orig, int new, int32 triphone_id){ int i; short *orig_adjacency; short *new_adjacency; orig_adjacency = &amatrix[orig * MAX_NODES]; new_adjacency = &amatrix[new * MAX_NODES]; phone_id_map[new] = triphone_id; boundary[new] = boundary[orig]; word_id_map[new] = word_id_map[orig]; for (i = 0; i < MAX_NODES; i++) { if (orig_adjacency[i] == LEFT_ADJACENT) { amatrix[i * MAX_NODES + new] = RIGHT_ADJACENT; new_adjacency[i] = orig_adjacency[i]; } else if (orig_adjacency[i] == RIGHT_ADJACENT) { amatrix[i * MAX_NODES + new] = LEFT_ADJACENT; new_adjacency[i] = orig_adjacency[i]; } }}voidprune_invalid_adjacencies(short *amatrix, int node_cnt, int *ci_map, int *lc_map, int *rc_map)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -