📄 corpus.c
字号:
k = sscanf (line, "%s %d %d %s", uttfile, sf, ef, uttid); } while (k <= 0); if ((k == 2) || ( (k >= 3) && ((*sf >= *ef) || (*sf < 0))) ) E_FATAL("Error in ctlfile: %s\n", line); if (k < 4) { /* Create utt-id from mfc-filename (and sf/ef if specified) */ path2basename (uttfile, base); strip_fileext (base, uttid); if (k == 3) { k = strlen(uttid); sprintf (uttid+k, "_%d_%d", *sf, *ef); } else { *sf = 0; *ef = -1; /* Signifies "until EOF" */ } } return 0;}ptmr_t ctl_process (char *ctlfile, char* ctlmllrfile, int32 nskip, int32 count, void (*func) (void *kb, char *uttfile, int32 sf, int32 ef, char *uttid), void *kb){ FILE *fp, *mllrfp; char uttfile[16384], uttid[4096]; char regmatfile[4096]; int32 sf, ef; ptmr_t tm; mllrfp = NULL; E_INFO("Batch mode recognition without dynamic LM\n"); if (ctlfile) { if ((fp = fopen(ctlfile, "r")) == NULL) E_FATAL_SYSTEM("fopen(%s,r) failed\n", ctlfile); } else fp = stdin; if(ctlmllrfile){ if ((mllrfp = fopen(ctlmllrfile, "r")) == NULL) E_FATAL_SYSTEM("fopen(%s,r) failed\n", ctlmllrfile); } ptmr_init (&tm); if (nskip > 0) { E_INFO("Skipping %d entries at the beginning of %s\n", nskip, ctlfile); for (; nskip > 0; --nskip) { if (ctl_read_entry (fp, uttfile, &sf, &ef, uttid) < 0) { fclose (fp); return tm; } } if(ctlmllrfile){ for (; nskip > 0; --nskip) { if (ctl_read_entry (fp, regmatfile, &sf, &ef, uttid) < 0) { E_ERROR("MLLR cannot be read when skipping the %d-th sentence\n",nskip); fclose (fp); return tm; } } } } for (; count > 0; --count) { if (ctl_read_entry (fp, uttfile, &sf, &ef, uttid) < 0) break; if(ctlmllrfile){ if (ctl_read_entry (mllrfp, regmatfile, &sf, &ef, uttid) < 0){ E_ERROR("MLLR cannot be read when counting the %d-th sentence\n",count); break; } } /* Process this utterance */ ptmr_start (&tm); if (func){ if(ctlmllrfile) kb_setmllr(regmatfile,kb); (*func)(kb, uttfile, sf, ef, uttid); } ptmr_stop (&tm); E_INFO("%s: %6.1f sec CPU, %6.1f sec Clk; TOT: %8.1f sec CPU, %8.1f sec Clk\n\n", uttid, tm.t_cpu, tm.t_elapsed, tm.t_tot_cpu, tm.t_tot_elapsed); ptmr_reset (&tm); } fclose (fp); return tm;}ptmr_t ctl_process_dyn_lm (char *ctlfile, char *ctllmfile, char* ctlmllrfile, int32 nskip, int32 count, void (*func) (void *kb, char *uttfile, int32 sf, int32 ef, char *uttid), void *kb){ FILE *fp; FILE *ctllmfp; FILE *ctlmllrfp; char uttfile[16384], uttid[4096]; char lmname[4096]; char regmatname[4096]; char tmp[4096]; int32 sf, ef; ptmr_t tm; ctllmfp=NULL; ctlmllrfp=NULL; E_INFO("Batch mode recognition with dynamic LM\n"); if (ctlfile) { if ((fp = fopen(ctlfile, "r")) == NULL) E_FATAL_SYSTEM("fopen(%s,r) failed\n", ctlfile); } else fp = stdin; if(ctllmfile){ if ((ctllmfp = fopen(ctllmfile, "r")) == NULL) E_FATAL_SYSTEM("fopen(%s,r) failed\n", ctllmfile); } if(ctlmllrfile) { E_INFO("MLLR is used in this session\n"); if((ctlmllrfp = fopen(ctlmllrfile, "r")) == NULL) E_FATAL_SYSTEM("fopen(%s,r) failed\n", ctlmllrfile); } ptmr_init (&tm); if (nskip > 0) { E_INFO("Skipping %d entries at the beginning of %s\n", nskip, ctlfile); for (; nskip > 0; --nskip) { if (ctl_read_entry (fp, uttfile, &sf, &ef, uttid) < 0) { fclose (fp); return tm; } /*This checks the size of the control file of the lm in batch mode*/ if (ctl_read_entry (ctllmfp, lmname, &sf, &ef, tmp) < 0) { fclose (ctllmfp); E_ERROR("LM cannot be read when skipping the %d-th sentence\n",nskip); return tm; } /*This checks the size of the control file of the mllr in batch mode */ if(ctlmllrfile){ if (ctl_read_entry (ctlmllrfp, regmatname, &sf, &ef, tmp) < 0) { fclose (ctlmllrfp); E_ERROR("MLLR cannot be read when skipping the %d-th sentence\n",nskip); return tm; } } } } for (; count > 0; --count) { if (ctl_read_entry (fp, uttfile, &sf, &ef, uttid) < 0) break; /*This checks the size of the control file in batch mode*/ if (ctl_read_entry (ctllmfp, lmname, &sf, &ef, tmp) < 0) { fclose (ctllmfp); E_ERROR("LM cannot be read when counting the %d-th sentence\n",count); return tm; } if(ctlmllrfile){ if (ctl_read_entry (ctlmllrfp, regmatname, &sf, &ef, tmp) < 0) { fclose (ctlmllrfp); E_ERROR("MLLR cannot be read when counting the %d-th sentence\n",count); return tm; } } /* Process this utterance */ ptmr_start (&tm); E_INFO("filename %s, lmname %s\n",uttfile,lmname); if (func){ kb_setlm(lmname,kb); if(ctlmllrfile) kb_setmllr(regmatname,kb); (*func)(kb, uttfile, sf, ef, uttid); } ptmr_stop (&tm); E_INFO("%s: %6.1f sec CPU, %6.1f sec Clk; TOT: %8.1f sec CPU, %8.1f sec Clk\n\n", uttid, tm.t_cpu, tm.t_elapsed, tm.t_tot_cpu, tm.t_tot_elapsed); ptmr_reset (&tm); } fclose (fp); fclose (ctllmfp); fclose (ctlmllrfp); return tm;}ptmr_t ctl_process_utt (char *uttfile, int32 count, void (*func) (void *kb, char *uttfile, int32 sf, int32 ef, char *uttid), void *kb){ char uttid[4096]; char base[16384]; int32 i, c; int32 ts, newts; ptmr_t tm; ptmr_init (&tm); path2basename (uttfile, base); strip_fileext (base, uttid); strcpy (base, uttid); ts = -1; for (c = 0; c < count; c++) { /* Wait for uttfile to change from previous iteration */ for (i = 0;; i++) { newts = stat_mtime (uttfile); if ((newts >= 0) && (newts != ts)) break; if (i == 0) E_INFO("Waiting for %s, count %d, c %d\n", uttfile,count,c); SLEEP_SEC (1); } ts = newts; /* Form uttid */ sprintf (uttid, "%s_%08d", base, c); /* Process this utterance */ ptmr_start (&tm); if (func) (*func)(kb, uttfile, 0, -1, uttid); ptmr_stop (&tm); E_INFO("%s: %6.1f sec CPU, %6.1f sec Clk; TOT: %8.1f sec CPU, %8.1f sec Clk\n\n", uttid, tm.t_cpu, tm.t_elapsed, tm.t_tot_cpu, tm.t_tot_elapsed); ptmr_reset (&tm); } return tm;}void ctl_infile (char *file, char *dir, char *ext, char *utt){ int32 l1, l2; assert (utt); if (ext && (ext[0] != '\0')) { l1 = strlen(ext); l2 = strlen(utt); if ((l2 > l1) && (utt[l2-l1-1] == '.') && (strcmp (utt+(l2-l1), ext) == 0)) ext = NULL; /* utt already has the desired extension */ } if ((utt[0] != '/') && dir) { /* Dir specified for relative uttfile pathname */ if (ext && (ext[0] != '\0')) sprintf (file, "%s/%s.%s", dir, utt, ext); else sprintf (file, "%s/%s", dir, utt); } else { if (ext && (ext[0] != '\0')) sprintf (file, "%s.%s", utt, ext); else strcpy (file, utt); }}void ctl_outfile (char *file, char *dir, char *ext, char *utt, char *uttid){ int32 k; k = strlen(dir); if ((k > 4) && (strcmp (dir+k-4, ",CTL") == 0)) { /* HACK!! Hardwired ,CTL */ if (utt[0] != '/') { strcpy (file, dir); file[k-4] = '/'; strcpy (file+k-3, utt); } else strcpy (file, utt); } else { strcpy (file, dir); file[k] = '/'; strcpy (file+k+1, uttid); } if (ext && (ext[0] != '\0')) { strcat (file, "."); strcat (file, ext); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -