int32 main(int32 argc, char *argv[]) { kb_t kb; stat_t *st; cmd_ln_t *config; print_appl_info(argv[0]); cmd_ln_appl_enter(argc, argv, "default.arg", arg); unlimit(); config = cmd_ln_get(); kb_init(&kb, config); st = kb.stat; fprintf(stdout, "\n"); if (cmd_ln_str_r(config, "-ctl")) { /* When -ctlfile is speicified, corpus.c will look at -ctl_lm and -ctl_mllr to get the corresponding LM and MLLR for the utterance */ st->tm = ctl_process(cmd_ln_str_r(config, "-ctl"), cmd_ln_str_r(config, "-ctl_lm"), cmd_ln_str_r(config, "-ctl_mllr"), cmd_ln_int32_r(config, "-ctloffset"), cmd_ln_int32_r(config, "-ctlcount"), utt_decode, &kb); } else if (cmd_ln_str_r(config, "-utt")) { /* When -utt is specified, corpus.c will wait for the utterance to change */ st->tm = ctl_process_utt(cmd_ln_str_r(config, "-utt"), cmd_ln_int32_r(config, "-ctlcount"), utt_decode, &kb); } else { /* Is error checking good enough?" */ E_FATAL("Both -utt and -ctl are not specified.\n"); } if (kb.matchsegfp) fclose(kb.matchsegfp); if (kb.matchfp) fclose(kb.matchfp); stat_report_corpus(kb.stat); kb_free(&kb); #if (! WIN32) #if defined(_SUN4) system("ps -el | grep sphinx3_decode"); #else system("ps aguxwww | grep sphinx3_decode"); #endif #endif cmd_ln_free_r(config); exit(0); }
int ld_init(live_decoder_t *decoder, int argc, char **argv) { param_t fe_param; if (argc == 2) { /* * lgalescu: check if args need to be processed from file */ parse_args_file(argv[1]); } else cmd_ln_parse(arg_def, argc, argv); unlimit(); /* some decoder parameter capturing * !!! NOTE - HARDCODED FOR NOW. REPLACE WITH PARSE_ARG() ASAP !!!! */ memset(decoder, 0, sizeof(live_decoder_t)); kb_init(&decoder->kb); decoder->max_wpf = cmd_ln_int32 ("-maxwpf");; decoder->max_histpf = cmd_ln_int32 ("-maxhistpf"); decoder->max_hmmpf = cmd_ln_int32 ("-maxhmmpf"); decoder->phones_skip = cmd_ln_int32 ("-ptranskip"); decoder->hmm_log = cmd_ln_int32("-hmmdump") ? stderr : NULL; decoder->kbcore = decoder->kb.kbcore; decoder->kb.uttid = decoder->uttid; decoder->hypsegs = 0; decoder->num_hypsegs = 0; decoder->hypstr_len = 0; decoder->hypstr[0] = '\0'; decoder->features = feat_array_alloc(kbcore_fcb(decoder->kbcore), LIVEBUFBLOCKSIZE); decoder->ld_state = LD_STATE_IDLE; /* some front-end parameter capturing * !!! NOTE - HARDCODED FOR NOW. REPLACE WITH PARSE_ARG() ASAP !!!! */ memset(&fe_param, 0, sizeof(param_t)); fe_param.SAMPLING_RATE = (float32)cmd_ln_int32 ("-samprate"); fe_param.LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param.UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param.NUM_FILTERS = cmd_ln_int32("-nfilt"); fe_param.FRAME_RATE = cmd_ln_int32("-frate"); fe_param.PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha"); fe_param.FFT_SIZE = cmd_ln_int32("-nfft"); fe_param.WINDOW_LENGTH = cmd_ln_float32("-wlen"); decoder->fe = fe_init(&fe_param); if (!decoder->fe) { E_WARN("Front end initialization fe_init() failed\n"); return -1; } return 0; }
/* This routine initializes decoder variables for live mode decoding */ void live_initialize_decoder(char *live_args) { static kb_t live_kb; int32 maxcepvecs, maxhyplen, samprate, ceplen; param_t *fe_param; /*char const *uttIdNotDefined = "null";*/ parse_args_file(live_args); unlimit(); kb_init(&live_kb); kb = &live_kb; kbcore = kb->kbcore; kb->uttid = ckd_calloc(1000,sizeof(char)); hmmdumpfp = cmd_ln_int32("-hmmdump") ? stderr : NULL; maxwpf = cmd_ln_int32 ("-maxwpf"); maxhistpf = cmd_ln_int32 ("-maxhistpf"); maxhmmpf = cmd_ln_int32 ("-maxhmmpf"); ptranskip = cmd_ln_int32 ("-ptranskip"); maxhyplen = cmd_ln_int32 ("-maxhyplen"); if (!parthyp) parthyp = (partialhyp_t *) ckd_calloc(maxhyplen, sizeof(partialhyp_t)); parthyplen = 0; fe_param = (param_t *) ckd_calloc(1, sizeof(param_t)); samprate = cmd_ln_int32 ("-samprate"); if (samprate != 8000 && samprate != 16000) E_FATAL("Sampling rate %d not supported. Must be 8000 or 16000\n",samprate); fe_param->SAMPLING_RATE = (float32) samprate; fe_param->LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param->UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param->NUM_FILTERS = cmd_ln_int32("-nfilt"); /* 20040413, by ARCHAN. Clear the hardwiring. Hmm. Many people say no to do this, I just can't take it. */ fe_param->FRAME_RATE = cmd_ln_int32("-frate"); /* fe_param->FRAME_RATE = 100; */ fe_param->PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha"); fe_param->FFT_SIZE = cmd_ln_int32("-nfft"); fe_param->WINDOW_LENGTH = cmd_ln_float32("-wlen"); fe_param->doublebw=OFF; fe = fe_init(fe_param); if (!fe) E_FATAL("Front end initialization fe_init() failed\n"); maxcepvecs = cmd_ln_int32 ("-maxcepvecs"); ceplen = kbcore->fcb->cepsize; dummyframe = (float32*) ckd_calloc(1 * ceplen,sizeof(float32)); /* */ }
int main(int argc, char *argv[]) { print_appl_info(argv[0]); cmd_ln_appl_enter(argc, argv, "default.arg", defn); unlimit(); config = cmd_ln_get(); logmath = logs3_init(cmd_ln_float64_r(config, "-logbase"), 1, cmd_ln_int32_r(config, "-log3table")); E_INFO("Value of base %f \n", cmd_ln_float32_r(config, "-logbase")); models_init(); ptmr_init(&tm_utt); if ((inmatchsegfp = fopen(cmd_ln_str_r(config, "-inhypseg"), "r")) == NULL) E_ERROR("fopen(%s,r) failed\n", cmd_ln_str_r(config, "-inhypseg")); if ((outconfmatchsegfp = fopen(cmd_ln_str_r(config, "-output"), "w")) == NULL) E_ERROR("fopen(%s,w) failed\n", cmd_ln_str_r(config, "-output")); if (cmd_ln_str_r(config, "-ctl")) { ctl_process(cmd_ln_str_r(config, "-ctl"), cmd_ln_str_r(config, "-ctl_lm"), NULL, cmd_ln_int32_r(config, "-ctloffset"), cmd_ln_int32_r(config, "-ctlcount"), utt_confidence, NULL); } else { E_FATAL("-ctl is not specified\n"); } #if (! WIN32) system("ps auxwww | grep s3dag"); #endif fclose(outconfmatchsegfp); fclose(inmatchsegfp); models_free(); logmath_free(logmath); cmd_ln_free_r(config); return 0; }
/* This routine initializes decoder variables for live mode decoding */ void live_initialize_decoder(char *live_args) { static kb_t live_kb; int32 maxcepvecs, maxhyplen, samprate, ceplen; param_t *fe_param; char const *uttIdNotDefined = "null"; parse_args_file(live_args); unlimit(); kb_init(&live_kb); kb = &live_kb; kbcore = kb->kbcore; kb->uttid = ckd_salloc(uttIdNotDefined); hmmdumpfp = cmd_ln_int32("-hmmdump") ? stderr : NULL; maxwpf = cmd_ln_int32 ("-maxwpf"); maxhistpf = cmd_ln_int32 ("-maxhistpf"); maxhmmpf = cmd_ln_int32 ("-maxhmmpf"); ptranskip = cmd_ln_int32 ("-ptranskip"); maxhyplen = cmd_ln_int32 ("-maxhyplen"); if (!parthyp) parthyp = (partialhyp_t *) ckd_calloc(maxhyplen, sizeof(partialhyp_t)); fe_param = (param_t *) ckd_calloc(1, sizeof(param_t)); samprate = cmd_ln_int32 ("-samprate"); if (samprate != 8000 && samprate != 16000) E_FATAL("Sampling rate %s not supported. Must be 8000 or 16000\n",samprate); fe_param->SAMPLING_RATE = (float32) samprate; fe_param->LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param->UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param->NUM_FILTERS = cmd_ln_int32("-nfilt"); fe_param->FRAME_RATE = 100; /* HARD CODED TO 100 FRAMES PER SECOND */ fe_param->PRE_EMPHASIS_ALPHA = (float32) 0.97; fe = fe_init(fe_param); if (!fe) E_FATAL("Front end initialization fe_init() failed\n"); maxcepvecs = cmd_ln_int32 ("-maxcepvecs"); ceplen = kbcore->fcb->cepsize; dummyframe = (float32*) ckd_calloc(1 * ceplen,sizeof(float32)); /* */ #if defined(THRD) score_barrier = thread_barrier_init(NUM_THREADS); if (!score_barrier) E_FATAL("Cannot initialize score_barrier\n"); #endif }
main (int32 argc, char *argv[]) { char *reffile, *mdeffile, *dictfile, *fdictfile, *homfile; if (argc == 1) { cmd_ln_print_help (stderr, arglist); exit(0); } cmd_ln_parse (arglist, argc, argv); if ((mdeffile = (char *) cmd_ln_access ("-mdef")) == NULL) E_FATAL("-mdef argument missing\n"); if ((dictfile = (char *) cmd_ln_access ("-dict")) == NULL) E_FATAL("-dict argument missing\n"); if ((fdictfile = (char *) cmd_ln_access ("-fdict")) == NULL) E_FATAL("-fdict argument missing\n"); if ((reffile = (char *) cmd_ln_access ("-ref")) == NULL) E_FATAL("-ref argument missing\n"); unlimit(); mdef = mdef_init (mdeffile); if (mdef->n_ciphone <= 0) E_FATAL("0 CIphones in %s\n", mdeffile); dict = dict_init (mdef, dictfile, fdictfile); oovbegin = dict->n_word; startwid = dict_wordid (dict, "<s>"); finishwid = dict_wordid (dict, "</s>"); silwid = dict_wordid (dict, (char *) cmd_ln_access("-sil")); assert (dict_filler_word (dict, silwid)); homlist = NULL; if ((homfile = (char *) cmd_ln_access ("-hom")) != NULL) homfile_load (homfile); process_reffile (reffile); #if (0 && (! WIN32)) fflush (stdout); fflush (stderr); system ("ps aguxwww | grep dpalign"); #endif exit(0); }
main (int32 argc, char *argv[]) { char *reffile, *mdeffile, *dictfile, *fdictfile; if (argc == 1) { cmd_ln_print_help (stderr, arglist); exit(0); } cmd_ln_parse (arglist, argc, argv); if ((mdeffile = (char *) cmd_ln_access ("-mdef")) == NULL) E_FATAL("-mdef argument missing\n"); if ((dictfile = (char *) cmd_ln_access ("-dict")) == NULL) E_FATAL("-dict argument missing\n"); if ((fdictfile = (char *) cmd_ln_access ("-fdict")) == NULL) E_FATAL("-fdict argument missing\n"); if ((reffile = (char *) cmd_ln_access ("-ref")) == NULL) E_FATAL("-ref argument missing\n"); unlimit(); mdef = mdef_init (mdeffile); if (mdef->n_ciphone <= 0) E_FATAL("0 CIphones in %s\n", mdeffile); dict = dict_init (mdef, dictfile, fdictfile); process_reffile (reffile); #if (0 && (! WIN32)) fflush (stdout); fflush (stderr); system ("ps aguxwww | grep dpalign"); #endif exit(0); }
int32 main(int32 argc, char *argv[]) { FILE *fpout; mgau_model_t *mgau; int32 **subvec; int32 max_datarows, datarows, datacols, svqrows, svqcols; float32 **data, **vqmean; int32 *datamap, *vqmap; float64 sqerr; int32 stdev; int32 i, j, v, m, c; cmd_ln_t *config; logmath_t *logmath; print_appl_info(argv[0]); cmd_ln_appl_enter(argc, argv, "default.arg", arg); unlimit(); config = cmd_ln_get(); logmath = logs3_init(cmd_ln_float64_r(config, "-logbase"), 1, cmd_ln_int32_r(config, "-log3table")); /*Report Progress, use log table */ /* Load means/vars but DO NOT precompute variance inverses or determinants */ mgau = mgau_init(cmd_ln_str_r(config, "-mean"), cmd_ln_str_r(config, "-var"), 0.0 /* no varfloor */ , cmd_ln_str_r(config, "-mixw"), cmd_ln_float32_r(config, "-mixwfloor"), FALSE, /* No precomputation */ ".cont.", MIX_INT_FLOAT_COMP, logmath); /* Parse subvector spec argument; subvec is null terminated; subvec[x] is -1 terminated */ subvec = parse_subvecs(cmd_ln_str_r(config, "-svspec")); if (cmd_ln_str_r(config, "-subvq")) { if ((fpout = fopen(cmd_ln_str_r(config, "-subvq"), "w")) == NULL) { E_ERROR_SYSTEM("Failed to open output file '%s'", fpout); return 1; } } else fpout = stdout; /* Echo command line to output file */ for (i = 0; i < argc - 1; i++) fprintf(fpout, "# %s \\\n", argv[i]); fprintf(fpout, "# %s\n#\n", argv[argc - 1]); /* Print input and output configurations to output file */ for (v = 0; subvec[v]; v++); /* No. of subvectors */ svqrows = cmd_ln_int32_r(config, "-svqrows"); fprintf(fpout, "VQParam %d %d -> %d %d\n", mgau_n_mgau(mgau), mgau_max_comp(mgau), v, svqrows); for (v = 0; subvec[v]; v++) { for (i = 0; subvec[v][i] >= 0; i++); fprintf(fpout, "Subvector %d length %d ", v, i); for (i = 0; subvec[v][i] >= 0; i++) fprintf(fpout, " %2d", subvec[v][i]); fprintf(fpout, "\n"); } fflush(fpout); /* * datamap[] for identifying non-0 input vectors that take part in the clustering process: * datamap[m*max_mean + c] = row index of data[][] containing the copy. * vqmap[] for mapping vq input data to vq output. */ max_datarows = mgau_n_mgau(mgau) * mgau_max_comp(mgau); datamap = (int32 *) ckd_calloc(max_datarows, sizeof(int32)); vqmap = (int32 *) ckd_calloc(max_datarows, sizeof(int32)); stdev = cmd_ln_int32_r(config, "-stdev"); /* Copy and cluster each subvector */ for (v = 0; subvec[v]; v++) { E_INFO("Clustering subvector %d\n", v); for (datacols = 0; subvec[v][datacols] >= 0; datacols++); /* Input subvec length */ svqcols = datacols * 2; /* subvec length after concatenating mean + var */ /* Allocate input/output data areas */ data = (float32 **) ckd_calloc_2d(max_datarows, svqcols, sizeof(float32)); vqmean = (float32 **) ckd_calloc_2d(svqrows, svqcols, sizeof(float32)); /* Make a copy of the subvectors from the input data, and initialize maps */ for (i = 0; i < max_datarows; i++) datamap[i] = -1; datarows = 0; for (m = 0; m < mgau_n_mgau(mgau); m++) { /* For each mixture m */ for (c = 0; c < mgau_n_comp(mgau, m); c++) { /* For each component c in m */ if (vector_is_zero (mgau_var(mgau, m, c), mgau_veclen(mgau))) { E_INFO("Skipping mgau %d comp %d\n", m, c); continue; } for (i = 0; i < datacols; i++) { /* Copy specified dimensions, mean+var */ data[datarows][i * 2] = mgau->mgau[m].mean[c][subvec[v][i]]; data[datarows][i * 2 + 1] = (!stdev) ? mgau->mgau[m]. var[c][subvec[v][i]] : sqrt(mgau->mgau[m]. var[c][subvec[v][i]]); } datamap[m * mgau_max_comp(mgau) + c] = datarows++; } } E_INFO("Sanity check: input data[0]:\n"); vector_print(stderr, data[0], svqcols); for (i = 0; i < max_datarows; i++) vqmap[i] = -1; #if 0 { int32 **in; printf("Input data: %d x %d\n", datarows, svqcols); in = (int32 **) data; for (i = 0; i < datarows; i++) { printf("%8d:", i); for (j = 0; j < svqcols; j++) printf(" %08x", in[i][j]); printf("\n"); } for (i = 0; i < datarows; i++) { printf("%15d:", i); for (j = 0; j < svqcols; j++) printf(" %15.7e", data[i][j]); printf("\n"); } fflush(stdout); } #endif /* VQ the subvector copy built above */ sqerr = vector_vqgen(data, datarows, svqcols, svqrows, cmd_ln_float64_r(config, "-eps"), cmd_ln_int32_r(config, "-iter"), vqmean, vqmap, cmd_ln_int32_r(config, "-seed")); /* Output VQ */ fprintf(fpout, "Codebook %d Sqerr %e\n", v, sqerr); for (i = 0; i < svqrows; i++) { if (stdev) { /* Convert clustered stdev back to var */ for (j = 1; j < svqcols; j += 2) vqmean[i][j] *= vqmean[i][j]; } vector_print(fpout, vqmean[i], svqcols); } fprintf(fpout, "Map %d\n", v); for (i = 0; i < max_datarows; i += mgau_max_comp(mgau)) { for (j = 0; j < mgau_max_comp(mgau); j++) { if (datamap[i + j] < 0) fprintf(fpout, " -1"); else fprintf(fpout, " %d", vqmap[datamap[i + j]]); } fprintf(fpout, "\n"); } fflush(fpout); /* Cleanup */ ckd_free_2d((void **) data); ckd_free_2d((void **) vqmean); } subvecs_free(subvec); ckd_free(datamap); ckd_free(vqmap); mgau_free(mgau); fprintf(fpout, "End\n"); fclose(fpout); logmath_free(logmath); cmd_ln_free_r(config); exit(0); }
main (int32 argc, char *argv[]) { char *str; #if 0 ckd_debug(100000); #endif /* Digest command line argument definitions */ cmd_ln_define (defn); if ((argc == 2) && (strcmp (argv[1], "help") == 0)) { cmd_ln_print_definitions(); exit(1); } /* Look for default or specified arguments file */ str = NULL; if ((argc == 2) && (argv[1][0] != '-')) str = argv[1]; else if (argc == 1) { str = "s3decode.arg"; E_INFO("Looking for default argument file: %s\n", str); } if (str) { /* Build command line argument list from file */ if ((argc = load_argfile (str, argv[0], &argv)) < 0) { fprintf (stderr, "Usage:\n"); fprintf (stderr, "\t%s argument-list, or\n", argv[0]); fprintf (stderr, "\t%s [argument-file] (default file: s3decode.arg)\n\n", argv[0]); cmd_ln_print_definitions(); exit(1); } } cmdline_parse (argc, argv); /* Remove memory allocation restrictions */ unlimit (); #if (! WIN32) { char buf[1024]; gethostname (buf, 1024); buf[1023] = '\0'; E_INFO ("Executing on: %s\n", buf); } #endif E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__); if ((cmd_ln_access("-mdeffn") == NULL) || (cmd_ln_access("-dictfn") == NULL) || (cmd_ln_access("-lmfn") == NULL)) E_FATAL("Missing -mdeffn, -dictfn, or -lmfn argument\n"); /* * Initialize log(S3-base). All scores (probs...) computed in log domain to avoid * underflow. At the same time, log base = 1.0001 (1+epsilon) to allow log values * to be maintained in int32 variables without significant loss of precision. */ if (cmd_ln_access("-logbase") == NULL) logs3_init (1.0001); else { float32 logbase; logbase = *((float32 *) cmd_ln_access("-logbase")); if (logbase <= 1.0) E_FATAL("Illegal log-base: %e; must be > 1.0\n", logbase); if (logbase > 1.1) E_WARN("Logbase %e perhaps too large??\n", logbase); logs3_init ((float64) logbase); } /* Read in input databases */ models_init (); /* Allocate timing object */ tm_utt = timing_new (); tot_nfr = 0; /* Initialize forward Viterbi search module */ dag_init (); printf ("\n"); process_ctlfile (); printf ("\n"); printf("TOTAL FRAMES: %8d\n", tot_nfr); if (tot_nfr > 0) { printf("TOTAL CPU TIME: %11.2f sec, %7.2f xRT\n", tm_utt->t_tot_cpu, tm_utt->t_tot_cpu/(tot_nfr*0.01)); printf("TOTAL ELAPSED TIME: %11.2f sec, %7.2f xRT\n", tm_utt->t_tot_elapsed, tm_utt->t_tot_elapsed/(tot_nfr*0.01)); } fflush (stdout); #if (! WIN32) system ("ps auxwww | grep s3dag"); #endif /* Hack!! To avoid hanging problem under Linux */ if (logfp) { fclose (logfp); *stdout = orig_stdout; *stderr = orig_stderr; } exit(0); }
int main(int32 argc, char *argv[]) { char sent[16384]; cmd_ln_t *config; print_appl_info(argv[0]); cmd_ln_appl_enter(argc, argv, "default.arg", defn); unlimit(); config = cmd_ln_get(); ctloffset = cmd_ln_int32_r(config, "-ctloffset"); sentfile = cmd_ln_str_r(config, "-insent"); if ((sentfp = fopen(sentfile, "r")) == NULL) E_FATAL_SYSTEM("Failed to open file %s for reading", sentfile); /* Note various output directories */ if (cmd_ln_str_r(config, "-s2stsegdir") != NULL) s2stsegdir = (char *) ckd_salloc(cmd_ln_str_r(config, "-s2stsegdir")); if (cmd_ln_str_r(config, "-stsegdir") != NULL) stsegdir = (char *) ckd_salloc(cmd_ln_str_r(config, "-stsegdir")); if (cmd_ln_str_r(config, "-phsegdir") != NULL) phsegdir = (char *) ckd_salloc(cmd_ln_str_r(config, "-phsegdir")); if (cmd_ln_str_r(config, "-phlabdir") != NULL) phlabdir = (char *) ckd_salloc(cmd_ln_str_r(config, "-phlabdir")); if (cmd_ln_str_r(config, "-wdsegdir") != NULL) wdsegdir = (char *) ckd_salloc(cmd_ln_str_r(config, "-wdsegdir")); /* HACK! Pre-read insent without checking whether ctl could also be read. In general, this is caused by the fact that we used multiple files to specify resource in sphinx III. This is easy to solve but currently I just to remove process_ctl because it duplicates badly with ctl_process. The call back function will take care of matching the uttfile names. We don't need to worry too much about inconsistency. */ while (ctloffset > 0) { if (fgets(sent, sizeof(sent), sentfp) == NULL) { E_ERROR("EOF(%s)\n", sentfile); break; } --ctloffset; } if ((outsentfile = cmd_ln_str_r(config, "-outsent")) != NULL) { if ((outsentfp = fopen(outsentfile, "w")) == NULL) E_FATAL_SYSTEM("Failed to open file %s for writing", outsentfile); } if ((outctlfile = cmd_ln_str_r(config, "-outctl")) != NULL) { if ((outctlfp = fopen(outctlfile, "w")) == NULL) E_FATAL_SYSTEM("Failed top open file %s for writing", outctlfile); } if ((cmd_ln_str_r(config, "-s2stsegdir") == NULL) && (cmd_ln_str_r(config, "-stsegdir") == NULL) && (cmd_ln_str_r(config, "-phlabdir") == NULL) && (cmd_ln_str_r(config, "-phsegdir") == NULL) && (cmd_ln_str_r(config, "-wdsegdir") == NULL) && (cmd_ln_str_r(config, "-outsent") == NULL)) E_FATAL("Missing output file/directory argument(s)\n"); /* Read in input databases */ models_init(config); if (!feat) feat = feat_array_alloc(kbcore_fcb(kbc), S3_MAX_FRAMES); timers[tmr_utt].name = "U"; timers[tmr_gauden].name = "G"; timers[tmr_senone].name = "S"; timers[tmr_align].name = "A"; /* Initialize align module */ align_init(kbc->mdef, kbc->tmat, dict, config, kbc->logmath); printf("\n"); if (cmd_ln_str_r(config, "-mllr") != NULL) { if (kbc->mgau) adapt_set_mllr(adapt_am, kbc->mgau, cmd_ln_str_r(config, "-mllr"), NULL, kbc->mdef, config); else if (kbc->ms_mgau) model_set_mllr(kbc->ms_mgau, cmd_ln_str_r(config, "-mllr"), NULL, kbcore_fcb(kbc), kbc->mdef, config); else E_WARN("Can't use MLLR matrices with .s2semi. yet\n"); } tot_nfr = 0; /* process_ctlfile (); */ if (cmd_ln_str_r(config, "-ctl")) { /* When -ctlfile is speicified, corpus.c will look at -ctl_mllr to get the corresponding MLLR for the utterance */ ctl_process(cmd_ln_str_r(config, "-ctl"), NULL, cmd_ln_str_r(config, "-ctl_mllr"), cmd_ln_int32_r(config, "-ctloffset"), cmd_ln_int32_r(config, "-ctlcount"), utt_align, config); } else { E_FATAL(" -ctl are not specified.\n"); } if (tot_nfr > 0) { printf("\n"); printf("TOTAL FRAMES: %8d\n", tot_nfr); printf("TOTAL CPU TIME: %11.2f sec, %7.2f xRT\n", tm_utt.t_tot_cpu, tm_utt.t_tot_cpu / (tot_nfr * 0.01)); printf("TOTAL ELAPSED TIME: %11.2f sec, %7.2f xRT\n", tm_utt.t_tot_elapsed, tm_utt.t_tot_elapsed / (tot_nfr * 0.01)); } if (outsentfp) fclose(outsentfp); if (outctlfp) fclose(outctlfp); if (sentfp) fclose(sentfp); ckd_free(s2stsegdir); ckd_free(stsegdir); ckd_free(phsegdir); ckd_free(wdsegdir); feat_array_free(feat); align_free(); models_free(); #if (! WIN32) system("ps aguxwww | grep s3align"); #endif cmd_ln_free_r(config); return 0; }
void kb (int argc, char *argv[], float ip, /* word insertion penalty */ float lw, /* langauge weight */ float pip) /* phone insertion penalty */ { char *pname = argv[0]; char hmm_file_name[256]; int32 num_phones, num_ci_phones; int32 i, use_darpa_lm; /* FIXME: This is evil. But if we do it, let's prototype it somewhere, OK? */ unlimit (); /* Remove memory size limits */ language_weight = lw; insertion_penalty = ip; phone_insertion_penalty = pip; pconf (argc, argv, kb_param, 0, 0, 0); if ((phone_file_name == 0) || (dict_file_name == 0)) pusage (pname, (Config_t *)kb_param); log_info("%s(%d): Reading phone file [%s]\n", __FILE__, __LINE__, phone_file_name); if (phone_read (phone_file_name)) exit (-1); if (useWDPhonesOnly) phone_add_diphones(); num_ci_phones = phoneCiCount(); /* Read the distribution map file */ log_info("%s(%d): Reading map file [%s]\n", __FILE__, __LINE__, mapFileName); read_map (mapFileName, TRUE /* useCiTrans compress */); log_info("%s(%d): Reading dict file [%s]\n", __FILE__, __LINE__, dict_file_name); word_dict = dict_new (); if (dict_read (word_dict, dict_file_name, phrase_dict_file_name, noise_dict_file_name, !useWDPhonesOnly)) exit (-1); use_darpa_lm = TRUE; if (use_darpa_lm) { lmSetStartSym (lm_start_sym); lmSetEndSym (lm_end_sym); /* * Read control file describing multiple LMs, if specified. * File format (optional stuff is indicated by enclosing in []): * * [{ LMClassFileName LMClassFilename ... }] * TrigramLMFileName LMName [{ LMClassName LMClassName ... }] * TrigramLMFileName LMName [{ LMClassName LMClassName ... }] * ... * (There should be whitespace around the { and } delimiters.) * * This is an extension of the older format that had only TrigramLMFilenName * and LMName pairs. The new format allows a set of LMClass files to be read * in and referred to by the trigram LMs. (Incidentally, if one wants to use * LM classes in a trigram LM, one MUST use the -lmctlfn flag. It is not * possible to read in a class-based trigram LM using the -lmfn flag.) * * No "comments" allowed in this file. */ if (lm_ctl_filename) { FILE *ctlfp; char lmfile[4096], lmname[4096], str[4096]; lmclass_set_t lmclass_set; lmclass_t *lmclass, cl; int32 n_lmclass, n_lmclass_used; lmclass_set = lmclass_newset(); E_INFO("Reading LM control file '%s'\n", lm_ctl_filename); ctlfp = CM_fopen (lm_ctl_filename, "r"); if (fscanf (ctlfp, "%s", str) == 1) { if (strcmp (str, "{") == 0) { /* Load LMclass files */ while ((fscanf (ctlfp, "%s", str) == 1) && (strcmp (str, "}") != 0)) lmclass_set = lmclass_loadfile (lmclass_set, str); if (strcmp (str, "}") != 0) E_FATAL("Unexpected EOF(%s)\n", lm_ctl_filename); if (fscanf (ctlfp, "%s", str) != 1) str[0] = '\0'; } } else str[0] = '\0'; /* Fill in dictionary word id information for each LMclass word */ for (cl = lmclass_firstclass(lmclass_set); lmclass_isclass(cl); cl = lmclass_nextclass(lmclass_set, cl)) { kb_init_lmclass_dictwid (cl); } /* At this point if str[0] != '\0', we have an LM filename */ n_lmclass = lmclass_get_nclass(lmclass_set); lmclass = (lmclass_t *) CM_calloc (n_lmclass, sizeof(lmclass_t)); /* Read in one LM at a time */ while (str[0] != '\0') { strcpy (lmfile, str); if (fscanf (ctlfp, "%s", lmname) != 1) E_FATAL("LMname missing after LMFileName '%s'\n", lmfile); n_lmclass_used = 0; if (fscanf (ctlfp, "%s", str) == 1) { if (strcmp (str, "{") == 0) { /* LM uses classes; read their names */ while ((fscanf (ctlfp, "%s", str) == 1) && (strcmp (str, "}") != 0)) { if (n_lmclass_used >= n_lmclass) E_FATAL("Too many LM classes specified for '%s'\n", lmfile); lmclass[n_lmclass_used] = lmclass_get_lmclass (lmclass_set, str); if (! (lmclass_isclass(lmclass[n_lmclass_used]))) E_FATAL("LM class '%s' not found\n", str); n_lmclass_used++; } if (strcmp (str, "}") != 0) E_FATAL("Unexpected EOF(%s)\n", lm_ctl_filename); if (fscanf (ctlfp, "%s", str) != 1) str[0] = '\0'; } } else str[0] = '\0'; if (n_lmclass_used > 0) lm_read_clm (lmfile, lmname, language_weight, unigramWeight, insertion_penalty, lmclass, n_lmclass_used); else lm_read (lmfile, lmname, language_weight, unigramWeight, insertion_penalty); } fclose (ctlfp); NoLangModel = FALSE; } /* Read "base" LM file, if specified */ if (lm_file_name) { lmSetStartSym (lm_start_sym); lmSetEndSym (lm_end_sym); lm_read (lm_file_name, "", language_weight, unigramWeight, insertion_penalty); /* Make initial OOV list known to this base LM */ lm_init_oov (); NoLangModel = FALSE; } #ifdef USE_ILM /* Init ILM module (non-std-Darpa LM, eg ug/bg cache LM) */ ilm_init (); #endif } #if 0 /* Compute the phrase lm probabilities */ computePhraseLMProbs (); #endif num_phones = phone_count (); numSmds = hmm_num_sseq(); smds = (SMD *) CM_calloc (numSmds, sizeof (SMD)); /* * Read the hmm's into the SMD structures */ if (useBigHmmFiles) { for (i = 0; i < num_ci_phones; i++) { sprintf (hmm_file_name, "%s.%s", phone_from_id (i), hmm_ext); hmm_tied_read_big_bin (hmm_dir_list, hmm_file_name, smds, transSmooth, NUMOFCODEENTRIES, TRUE, transWeight); } } else { for (i = 0; i < num_phones; i++) { if ((!useCiTrans) || (phone_id_to_base_id(i) == i)) { sprintf (hmm_file_name, "%s.%s", phone_from_id (i), hmm_ext); hmm_tied_read_bin (hmm_dir_list, hmm_file_name, &smds[hmm_pid2sid(i)], transSmooth, NUMOFCODEENTRIES, TRUE, transWeight); } } } /* * Use Ci transitions ? */ if (useCiTrans) { for (i = 0; i < num_phones; i++) { if (hmm_pid2sid(phone_id_to_base_id(i)) != hmm_pid2sid(i)) { /* * Just make a copy of the CI phone transitions */ memcpy (&smds[hmm_pid2sid(i)], &smds[hmm_pid2sid(phone_id_to_base_id(i))], sizeof (SMD)); } } } /* * Read the distributions */ read_dists (hmm_dir, code1_ext, code2_ext, code3_ext, code4_ext, NUMOFCODEENTRIES, hmm_smooth_min, useCiPhonesOnly); if (Use8BitSenProb) SCVQSetSenoneCompression (8); /* * Map the distributions to the correct locations */ remap (smds); }
static int ld_init_impl(live_decoder_t * _decoder, int32 _internal_cmdln) { param_t fe_param; int rv = LD_SUCCESS; assert(_decoder != NULL); unlimit(); /* ARCHAN 20050708: This part should be factored with fe_parse_option */ /* allocate and initialize front-end */ fe_init_params(&fe_param); fe_param.SAMPLING_RATE = cmd_ln_float32("-samprate"); fe_param.FRAME_RATE = cmd_ln_int32("-frate"); fe_param.WINDOW_LENGTH = cmd_ln_float32("-wlen"); fe_param.FB_TYPE = strcmp("mel_scale", cmd_ln_str("-fbtype")) == 0 ? MEL_SCALE : LOG_LINEAR; fe_param.NUM_CEPSTRA = cmd_ln_int32("-ncep"); fe_param.NUM_FILTERS = cmd_ln_int32("-nfilt"); fe_param.FFT_SIZE = cmd_ln_int32("-nfft"); fe_param.LOWER_FILT_FREQ = cmd_ln_float32("-lowerf"); fe_param.UPPER_FILT_FREQ = cmd_ln_float32("-upperf"); fe_param.PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha"); fe_param.dither = strcmp("no", cmd_ln_str("-dither")); fe_param.warp_type = cmd_ln_str("-warp_type"); fe_param.warp_params = cmd_ln_str("-warp_params"); if ((_decoder->fe = fe_init(&fe_param)) == NULL) { E_WARN("Failed to initialize front-end.\n"); rv = LD_ERROR_OUT_OF_MEMORY; goto ld_init_impl_cleanup; } /* capture decoder parameters */ kb_init(&_decoder->kb); /* initialize decoder variables */ _decoder->kbcore = _decoder->kb.kbcore; _decoder->hyp_frame_num = -1; _decoder->uttid = NULL; _decoder->ld_state = LD_STATE_IDLE; _decoder->hyp_str = NULL; _decoder->hyp_segs = NULL; /* _decoder->swap= (cmd_ln_int32("-machine_endian") != cmd_ln_int32("-input_endian")); */ _decoder->swap = (strcmp(cmd_ln_str("-machine_endian"), cmd_ln_str("-input_endian")) != 0); _decoder->phypdump = (cmd_ln_int32("-phypdump")); _decoder->rawext = (cmd_ln_str("-rawext")); if (_decoder->phypdump) E_INFO("Partial hypothesis WILL be dumped\n"); else E_INFO("Partial hypothesis will NOT be dumped\n"); if (_decoder->swap) E_INFO("Input data WILL be byte swapped\n"); else E_INFO("Input data will NOT be byte swapped\n"); _decoder->internal_cmdln = _internal_cmdln; _decoder->features = feat_array_alloc(kbcore_fcb(_decoder->kbcore), LIVEBUFBLOCKSIZE); if (_decoder->features == NULL) { E_WARN("Failed to allocate internal feature buffer.\n"); rv = LD_ERROR_OUT_OF_MEMORY; goto ld_init_impl_cleanup; } return LD_SUCCESS; ld_init_impl_cleanup: if (_decoder->fe != NULL) { fe_close(_decoder->fe); } if (_decoder->features != NULL) { /* consult the implementation of feat_array_alloc() for how to free our * internal feature vector buffer */ ckd_free((void *) **_decoder->features); ckd_free_2d((void **) _decoder->features); } if (_internal_cmdln == TRUE) { cmd_ln_free(); } _decoder->ld_state = LD_STATE_FINISHED; return rv; }
main (int32 argc, char *argv[]) { kb_t kb; kbcore_t *kbcore; bitvec_t active; int32 w; cmd_ln_parse (arglist, argc, argv); unlimit(); kbcore = kbcore_init (cmd_ln_float32("-logbase"), cmd_ln_str("-feat"), cmd_ln_str("-mdef"), cmd_ln_str("-dict"), cmd_ln_str("-fdict"), cmd_ln_str("-compsep"), cmd_ln_str("-lm"), cmd_ln_str("-fillpen"), cmd_ln_float32("-silprob"), cmd_ln_float32("-fillprob"), cmd_ln_float32("-lw"), cmd_ln_float32("-wip"), cmd_ln_str("-mean"), cmd_ln_str("-var"), cmd_ln_float32("-varfloor"), cmd_ln_str("-senmgau"), cmd_ln_str("-mixw"), cmd_ln_float32("-mixwfloor"), cmd_ln_str("-tmat"), cmd_ln_float32("-tmatfloor")); /* Here's the perfect candidate for inheritance */ kb.mdef = kbcore->mdef; kb.dict = kbcore->dict; kb.lm = kbcore->lm; kb.fillpen = kbcore->fillpen; kb.tmat = kbcore->tmat; kb.dict2lmwid = kbcore->dict2lmwid; if ((kb.am = acoustic_init (kbcore->fcb, kbcore->gau, kbcore->sen, cmd_ln_float32("-mgaubeam"), S3_MAX_FRAMES)) == NULL) { E_FATAL("Acoustic models initialization failed\n"); } kb.beam = logs3 (cmd_ln_float64("-beam")); kb.wordbeam = logs3 (cmd_ln_float64("-wordbeam")); kb.wordmax = cmd_ln_int32("-wordmax"); /* Mark the active words and build lextree */ active = bitvec_alloc (dict_size (kb.dict)); bitvec_clear_all (active, dict_size(kb.dict)); for (w = 0; w < dict_size(kb.dict); w++) { if (IS_LMWID(kb.dict2lmwid[w]) || dict_filler_word (kb.dict, w)) bitvec_set (active, w); } kb.lextree_root = lextree_build (kb.dict, kb.mdef, active, cmd_ln_int32("-flatdepth")); kb.vithist = (glist_t *) ckd_calloc (S3_MAX_FRAMES+2, sizeof(glist_t)); kb.vithist++; /* Allow for dummy frame -1 for start word */ kb.lextree_active = NULL; kb.wd_last_sf = (int32 *) ckd_calloc (dict_size(kb.dict), sizeof(int32)); kb.tm = (ptmr_t *) ckd_calloc (1, sizeof(ptmr_t)); kb.tm_search = (ptmr_t *) ckd_calloc (1, sizeof(ptmr_t)); ctl_process (cmd_ln_str("-ctl"), cmd_ln_int32("-ctloffset"), cmd_ln_int32("-ctlcount"), decode_utt, &kb); exit(0); }
int main(int argc, char **argv) { setvbuf(stdout, NULL, _IOLBF, 0); #ifdef XP_UNIX unlimit(); #endif fprintf(stdout, "\n"); unsigned long limit = 0; // no thread limit by default char *addr = NULL; PRBool log = PR_FALSE; LogLevel logLevel = LOGINFO; PLOptState *options; PRBool secure = PR_FALSE; PRBool NSTests = PR_FALSE; // don't execute Netscape tests by default PtrList<char> protlist; // list of security protocols PtrList<char> configlist; // list of configurations RegexList regexlist; // list of Sun tests/regex to load RegexList regexcludelist; // list of Sun tests/regex to exclude char* suitename = "suite1"; PRInt32 concurrent = 0; // number of concurrent threads for each test. 0 means sequential, single-threaded PRInt32 delay = 0; PRInt32 split = 0; PRInt32 timeout = 0; // leave timeout unchanged by default char* cert=NULL; char* certpwd=NULL; char* cipherString = NULL; char* version = "ENTERPRISE"; PRInt32 release = 41; PRInt32 hsp = 0; // SSL handshake period PRBool performance = PR_FALSE; PRInt32 maxtm = 0; PRUint16 af = PR_AF_INET; PRInt32 displayperiod=0; PRBool loop = PR_FALSE; Logger::logInitialize(logLevel); options = PL_CreateOptState(argc, argv, "X:C:h:H:l:c:d:n:w46r:sx:p:o:t:a:e:k:Ng:v:R:QPE:T:L:"); long repeat = 1; while ( PL_GetNextOpt(options) == PL_OPT_OK) { switch(options->option) { case 'L': loop = PR_TRUE; if (options->value) displayperiod = (PRInt32) atoi(options->value); break; case 'E': if (options->value) protlist.insert(strdup(options->value)); break; case 'T': if (options->value) maxtm = (PRInt32) atoi(options->value); break; case 'H': if (options->value) hsp = (PRInt32) atoi(options->value); break; case 'v': if (options->value) version = uppercase(strdup(options->value)); break; case 'g': if (options->value) configlist.insert(strdup(options->value)); break; case 'x': if (options->value) regexlist.add(options->value); break; case 'X': if (options->value) regexcludelist.add(options->value); break; case 'w': log = PR_TRUE; break; case 'r': if (options->value) repeat = atol(options->value); break; case 'e': if (options->value) timeout = atol(options->value); break; case 'o': if (options->value) split = atol(options->value); break; case 't': if (options->value) delay = atol(options->value); break; case 'd': if (options->value) suitename = strdup(options->value); break; case 'a': if (options->value) arch = strdup(options->value); break; case 'N': NSTests = PR_TRUE; break; case 'h': if (options->value) addr = strdup(options->value); break; case 'p': if (options->value) concurrent = atol(options->value); else concurrent = 1; // 1 thread per test break; case 'P': performance = PR_TRUE; // meaure performance only break; case 'l': if (options->value) logLevel = (LogLevel)atoi(options->value); break; case 'R': if (options->value) release = (PRInt32) atoi(options->value); break; case 's': secure = PR_TRUE; break; case 'n': if (options->value) cert = strdup(options->value); break; case 'k': if (options->value) certpwd = strdup(options->value); break; case 'c': if (options->value) { cipherString = strdup(options->value); if (PR_TRUE != EnableCipher(cipherString)) { Logger::logError(LOGINFO, "Invalid cipher specified.\n"); }; } break; case 'C': if (options->value) limit = atol(options->value); else limit = 0; // no thread limit break; case 'Q': printCipherOptions(); break; case '6': af = PR_AF_INET6; break; case '4': af = PR_AF_INET; break; }; }; SecurityProtocols secprots; if (PR_TRUE == secure) { NSString str; str.append(suitename); str.append("/certs/client"); secure = InitSecurity((char*)str.data(), cert, certpwd); if (PR_TRUE != secure) Logger::logError(LOGINFO, "Unable to initialize security.\n"); if (protlist.entries()) { secprots = protlist; }; }; PL_DestroyOptState(options); Logger::logInitialize(logLevel); nstime_init(); if (!addr) { usage(argv[0]); return -1; }; HttpServer server(addr, af); server.setSSL(secure); if (PR_FALSE == NSTests) { if (alltests) alltests->clear(); // cancel all the Netscape tests if (!regexlist.length()) regexlist.add(".*"); }; if (!configlist.entries()) configlist.insert("COMMON"); // if no config is specified, select default COMMON configuration Engine::globaltimeout = PR_TicksPerSecond()*timeout; SunTestSuite suite(configlist, suitename, regexlist, regexcludelist, arch, version, release, log, PR_TicksPerSecond()*timeout, split, delay, hsp, secprots, maxtm); PRInt32 percent = suite.runTests(server, concurrent, repeat, limit, performance, loop, displayperiod); return percent; };