📄 fbs_main.c
字号:
utt_id++; else utt_id = utt; strcpy(utt_name, utt_id); return utt_name;}voidrun_ctl_file(char const *ctl_file_name)/*-------------------------------------------------------------------------* * Sequence through a control file containing a list of utterance * NB. This is a one shot routine. */{ FILE *ctl_fs; char line[4096], mfcfile[4096], idspec[4096]; int32 line_no = 0; int32 sf, ef; search_hyp_t *hyp; int32 ctl_offset, ctl_count, ctl_incr; if (strcmp(ctl_file_name, "-") != 0) ctl_fs = myfopen(ctl_file_name, "r"); else ctl_fs = stdin; ctl_offset = cmd_ln_int32("-ctloffset"); ctl_count = cmd_ln_int32("-ctlcount"); ctl_incr = cmd_ln_int32("-ctlincr"); for (;;) { if (ctl_fs == stdin) E_INFO("\nInput file(no ext): "); if (fgets(line, sizeof(line), ctl_fs) == NULL) break; if (uttproc_parse_ctlfile_entry(line, mfcfile, &sf, &ef, idspec) < 0) continue; if (strcmp(mfcfile, "--END-OF-DOCUMENT--") == 0) { search_finish_document(); continue; } if ((ctl_offset-- > 0) || (ctl_count <= 0) || ((line_no++ % ctl_incr) != 0)) continue; E_INFO("\nUtterance: %s\n", idspec); if (!cmd_ln_boolean("-allphone")) { hyp = run_sc_utterance(mfcfile, sf, ef, idspec); if (hyp && cmd_ln_boolean("-shortbacktrace")) { /* print backtrace summary */ fprintf(stdout, "SEG:"); for (; hyp; hyp = hyp->next) fprintf(stdout, "[%d %d %s]", hyp->sf, hyp->ef, hyp->word); fprintf(stdout, " (%s %d A=%d L=%d)\n\n", uttproc_get_uttid(), search_get_score(), search_get_score() - search_get_lscr(), search_get_lscr()); fflush(stdout); } } else uttproc_allphone_file(mfcfile); ctl_count--; } if (ctl_fs != stdin) fclose(ctl_fs);}voidrun_time_align_ctl_file(char const *utt_ctl_file_name, char const *pe_ctl_file_name, char const *out_sent_file_name)/*-------------------------------------------------------------------------* * Sequence through a control file containing a list of utterance * NB. This is a one shot routine. */{ FILE *utt_ctl_fs; FILE *pe_ctl_fs; FILE *out_sent_fs; char Utt[1024]; char time_align_spec[1024]; int32 line_no = 0; char left_word[256]; char right_word[256]; char pe_words[1024]; int32 begin_frame; int32 end_frame; int32 n_featfr; int32 align_all = 0; int32 ctl_offset, ctl_count, ctl_incr; time_align_init(); time_align_set_beam_width(1e-9f); /* FIXME: !!!??? */ E_INFO("****** USING WIDE BEAM ****** (1e-9)\n"); utt_ctl_fs = myfopen(utt_ctl_file_name, "r"); pe_ctl_fs = myfopen(pe_ctl_file_name, "r"); if (out_sent_file_name) { out_sent_fs = myfopen(out_sent_file_name, "w"); } else out_sent_fs = NULL; ctl_offset = cmd_ln_int32("-ctloffset"); ctl_count = cmd_ln_int32("-ctlcount"); ctl_incr = cmd_ln_int32("-ctlincr"); while (fscanf(utt_ctl_fs, "%s\n", Utt) != EOF) { fgets(time_align_spec, 1023, pe_ctl_fs); if (ctl_offset) { ctl_offset--; continue; } if (ctl_count == 0) continue; if ((line_no++ % ctl_incr) != 0) continue; if (!strncmp (time_align_spec, "*align_all*", strlen("*align_all*"))) { E_INFO("Aligning whole utterances\n"); align_all = 1; fgets(time_align_spec, 1023, pe_ctl_fs); } if (align_all) { strcpy(left_word, "<s>"); strcpy(right_word, "</s>"); begin_frame = end_frame = NO_FRAME; time_align_spec[strlen(time_align_spec) - 1] = '\0'; strcpy(pe_words, time_align_spec); E_INFO("Utt %s\n", Utt); fflush(stdout); } else { sscanf(time_align_spec, "%s %d %d %s %[^\n]", left_word, &begin_frame, &end_frame, right_word, pe_words); E_INFO("\nDoing '%s %d) %s (%d %s' in utterance %s\n", left_word, begin_frame, pe_words, end_frame, right_word, Utt); } build_uttid(Utt); if ((n_featfr = uttproc_file2feat(Utt, 0, -1, 1)) < 0) E_ERROR("Failed to load %s\n", Utt); else { time_align_utterance(Utt, out_sent_fs, left_word, begin_frame, pe_words, end_frame, right_word); } --ctl_count; } fclose(utt_ctl_fs); fclose(pe_ctl_fs);}/* * Decode utterance. */static search_hyp_t *run_sc_utterance(char *mfcfile, int32 sf, int32 ef, char *idspec){ char startword_filename[1000]; FILE *sw_fp; int32 frmcount, ret; char *finalhyp; char utt[1024]; search_hyp_t *hypseg; int32 nbest; char *startWord_directory, *startWord_ext; strcpy(utt, idspec); build_uttid(utt); startWord_directory = cmd_ln_str("-startworddir"); startWord_ext = cmd_ln_str("-startwordext"); nbest = cmd_ln_int32("-nbest"); /* Select the LM for utt */ if (get_n_lm() > 1) { FILE *lmname_fp; char utt_lmname_file[1000], lmname[1000]; char *utt_lmname_dir = cmd_ln_str("-lmnamedir"); char *lmname_ext = cmd_ln_str("-lmnameext"); sprintf(utt_lmname_file, "%s/%s.%s", utt_lmname_dir, utt_name, lmname_ext); E_INFO("Looking for LM-name file %s\n", utt_lmname_file); if ((lmname_fp = fopen(utt_lmname_file, "r")) != NULL) { /* File containing LM name for this utt exists */ if (fscanf(lmname_fp, "%s", lmname) != 1) E_FATAL("Cannot read lmname from file %s\n", utt_lmname_file); fclose(lmname_fp); } else { /* No LM name specified for this utt; use default (with no name) */ E_INFO("File %s not found, using default LM\n", utt_lmname_file); lmname[0] = '\0'; } uttproc_set_lm(lmname); } /* Select startword for utt (LISTEN project) */#ifdef WIN32 if (startWord_directory && (utt[0] != '\\') && (utt[0] != '/')) sprintf(startword_filename, "%s/%s.%s", startWord_directory, utt, startWord_ext); else sprintf(startword_filename, "%s.%s", utt, startWord_ext);#else if (startWord_directory && (utt[0] != '/')) sprintf(startword_filename, "%s/%s.%s", startWord_directory, utt, startWord_ext); else sprintf(startword_filename, "%s.%s", utt, startWord_ext);#endif if ((sw_fp = fopen(startword_filename, "r")) != NULL) { char startWord[512]; /* FIXME */ fscanf(sw_fp, "%s", startWord); fclose(sw_fp); E_INFO("startWord: %s\n", startWord); uttproc_set_startword(startWord); } ret = uttproc_file2feat(mfcfile, sf, ef, 0); if (ret < 0) return NULL; /* Get hyp words segmentation (linked list of search_hyp_t) */ if (uttproc_result_seg(&frmcount, &hypseg, 1) < 0) { E_ERROR("uttproc_result_seg(%s) failed\n", uttproc_get_uttid()); return NULL; } search_result(&frmcount, &finalhyp); if (!uttproc_fsg_search_mode()) { /* Should the Nbest generation be in uttproc.c (uttproc_result)?? */ if (nbest > 0) { FILE *nbestfp; char nbestfile[4096]; search_hyp_t *h, **alt; int32 i, n_alt, startwid; char *nbest_dir = cmd_ln_str("-nbestdir"); char *nbest_ext = cmd_ln_str("-nbestext"); startwid = kb_get_word_id("<s>"); search_save_lattice(); n_alt = search_get_alt(nbest, 0, searchFrame(), -1, startwid, &alt); sprintf(nbestfile, "%s/%s.%s", nbest_dir, utt_name, nbest_ext); if ((nbestfp = fopen(nbestfile, "w")) == NULL) { E_WARN("fopen(%s,w) failed; using stdout\n", nbestfile); nbestfp = stdout; } for (i = 0; i < n_alt; i++) { for (h = alt[i]; h; h = h->next) fprintf(nbestfp, "%s ", h->word); fprintf(nbestfp, "\n"); } if (nbestfp != stdout) fclose(nbestfp); } } return hypseg; /* Linked list of hypothesis words */}/* * Run time align on a semi-continuous utterance. */voidtime_align_utterance(char const *utt, FILE * out_sent_fp, char const *left_word, int32 begin_frame, /* FIXME: Gets modified in time_align.c - watch out! */ char *pe_words, int32 end_frame, char const *right_word){ int32 n_frames; mfcc_t ***feat;#if !(defined(_WIN32) || defined(GNUWINCE)) struct rusage start, stop; struct timeval e_start, e_stop;#endif if ((begin_frame != NO_FRAME) || (end_frame != NO_FRAME)) { E_ERROR("Partial alignment not implemented\n"); return; } if ((n_frames = uttproc_get_featbuf(&feat)) < 0) { E_ERROR("#input speech frames = %d\n", n_frames); return; } time_align_set_input(feat, n_frames);#if !(defined(_WIN32) || defined(GNUWINCE))#ifndef _HPUX_SOURCE getrusage(RUSAGE_SELF, &start);#endif /* _HPUX_SOURCE */ gettimeofday(&e_start, 0);#endif /* _WIN32 */ if (time_align_word_sequence(utt, left_word, pe_words, right_word) == 0) { char *data_directory = cmd_ln_str("-cepdir"); char *seg_data_directory = cmd_ln_str("-segdir"); char *seg_file_ext = cmd_ln_str("-segext"); if (seg_file_ext) { unsigned short *seg; int seg_cnt; char seg_file_basename[MAXPATHLEN + 1]; switch (time_align_seg_output(&seg, &seg_cnt)) { case NO_SEGMENTATION: E_ERROR("NO SEGMENTATION for %s\n", utt); break; case NO_MEMORY: E_ERROR("NO MEMORY for %s\n", utt); break; default: { /* write the data in the same location as the cep file */ if (data_directory && (utt[0] != '/')) { if (seg_data_directory) { sprintf(seg_file_basename, "%s/%s.%s", seg_data_directory, utt, seg_file_ext); } else { sprintf(seg_file_basename, "%s/%s.%s", data_directory, utt, seg_file_ext); } } else { if (seg_data_directory) { char *spkr_dir; char basename[MAXPATHLEN]; char *sl; strcpy(basename, utt); sl = strrchr(basename, '/'); *sl = '\0'; sl = strrchr(basename, '/'); spkr_dir = sl + 1; sprintf(seg_file_basename, "%s/%s/%s.%s", seg_data_directory, spkr_dir, utt_name, seg_file_ext); } else { sprintf(seg_file_basename, "%s.%s", utt, seg_file_ext); } } E_INFO("Seg output %s\n", seg_file_basename); awriteshort(seg_file_basename, seg, seg_cnt); } } } if (out_sent_fp) { char const *best_word_str = time_align_best_word_string(); if (best_word_str) { fprintf(out_sent_fp, "%s (%s)\n", best_word_str, utt_name); } else { fprintf(out_sent_fp, "NO BEST WORD SEQUENCE for %s\n", utt); } } } else { E_ERROR("No alignment for %s\n", utt_name); }#if !(defined(_WIN32) || defined(GNUWINCE))#ifndef _HPUX_SOURCE getrusage(RUSAGE_SELF, &stop);#endif /* _HPUX_SOURCE */ gettimeofday(&e_stop, 0); E_INFO(" %5.2f SoS", n_frames * 0.01); E_INFO(", %6.2f sec elapsed", MakeSeconds(&e_start, &e_stop)); if (n_frames > 0) E_INFO(", %5.2f xRT", MakeSeconds(&e_start, &e_stop) / (n_frames * 0.01));#ifndef _HPUX_SOURCE E_INFO(", %6.2f sec CPU", MakeSeconds(&start.ru_utime, &stop.ru_utime)); if (n_frames > 0) E_INFO(", %5.2f xRT", MakeSeconds(&start.ru_utime, &stop.ru_utime) / (n_frames * 0.01));#endif /* _HPUX_SOURCE */ E_INFO("\n"); TotalCPUTime += MakeSeconds(&start.ru_utime, &stop.ru_utime); TotalElapsedTime += MakeSeconds(&e_start, &e_stop); TotalSpeechTime += n_frames * 0.01;#endif /* _WIN32 */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -