main_astar.c

来自「CMU大名鼎鼎的SPHINX-3大词汇量连续语音识别系统」· C语言 代码 · 共 497 行 · 第 1/2 页

C
497
字号
      "Input word-lattice directory with per-utt files for restricting words searched" },    { "-latext",      ARG_STRING,      "lat.gz",      "Word-lattice filename extension (.gz or .Z extension for compression)" },    { "-nbestdir",      ARG_STRING,      ".",      "Input word-lattice directory with per-utt files for restricting words searched" },    { "-nbestext",      ARG_STRING,      "nbest.gz",      "N-best filename extension (.gz or .Z extension for compression)" },    { "-nbest",      ARG_INT32,      "200",      "Max. n-best hypotheses to generate per utterance" },    { "-min_endfr",      ARG_INT32,      "3",      "Nodes ignored during search if they persist for fewer than so many end frames" },    { "-dagfudge",      ARG_INT32,      "2",      "Adjacency fudge (#frames) between nodes in DAG (0..2)" },    { "-ppathdebug",      ARG_INT32,      "0",      "Adjacency fudge (#frames) between nodes in DAG (0..2)" },    { "-logfn",      ARG_STRING,      NULL,      "Log file (default stdout/stderr)" },        { NULL, ARG_INT32, NULL, NULL }};/* * Load and cross-check all models (acoustic/lexical/linguistic). */static void models_init ( void ){    /* HMM model definition */    mdef = mdef_init ((char *) cmd_ln_access("-mdef"));    /* Dictionary */    dict = dict_init (mdef, (char *) cmd_ln_access("-dict"),		      (char *) cmd_ln_access("-fdict"), 0);    /* HACK!! Make sure SILENCE_WORD, START_WORD and FINISH_WORD are in dictionary */    silwid = dict_wordid (dict, S3_SILENCE_WORD);    startwid = dict_wordid (dict, S3_START_WORD);    finishwid = dict_wordid (dict, S3_FINISH_WORD);    if (NOT_S3WID(silwid) || NOT_S3WID(startwid) || NOT_S3WID(finishwid)) {	E_FATAL("%s, %s, or %s missing from dictionary\n",		S3_SILENCE_WORD, S3_START_WORD, S3_FINISH_WORD);    }    if ((dict->filler_start > dict->filler_end) || (! dict_filler_word (dict, silwid)))	E_FATAL("%s must occur (only) in filler dictionary\n", S3_SILENCE_WORD);    /* No check that alternative pronunciations for filler words are in filler range!! */    /* LM */    {	char *lmfile;		lmfile = (char *) cmd_ln_access("-lm");	if (! lmfile)	    E_FATAL("-lm argument missing\n");	lm = lm_read (lmfile, *(float32 *)cmd_ln_access("-lw"),	    		      *(float32 *)cmd_ln_access("-inspen"),			      *(float32 *)cmd_ln_access("-ugwt"));	fpen = fillpen_init (dict, (char *) cmd_ln_access("-fillpen"),		      *(float32 *)cmd_ln_access("-silpen"),		      *(float32 *)cmd_ln_access("-noisepen"),		      *(float32 *)cmd_ln_access("-lw"),		      *(float32 *)cmd_ln_access("-inspen"));    }    dict2lmwid = wid_dict_lm_map(dict, lm, *(float32 *)cmd_ln_access("-lw"));}/* Decode the given mfc file and write result to given directory */static void decode_utt (char *uttid, char *nbestdir){    char dagfile[1024], nbestfile[1024];    char *latdir, *latext, *nbestext;    int32 nfrm;        latdir = (char *) cmd_ln_access ("-inlatdir");    latext = (char *) cmd_ln_access ("-latext");    nbestext = (char *) cmd_ln_access ("-nbestext");    if (latdir)	sprintf (dagfile, "%s/%s.%s", latdir, uttid, latext);    else	sprintf (dagfile, "%s.%s", uttid, latext);        ptmr_reset (&tm_utt);    ptmr_start (&tm_utt);    if ((nfrm = s3astar_dag_load (dagfile)) > 0) {	sprintf (nbestfile, "%s/%s.%s", nbestdir, uttid, nbestext);	nbest_search (nbestfile, uttid);		lm_cache_stats_dump (lm);	lm_cache_reset (lm);    } else	E_ERROR("Dag load (%s) failed\n", uttid);    dag_destroy ();    ptmr_stop (&tm_utt);        printf ("%s: TMR: %5d Frm", uttid, nfrm);    if (nfrm > 0) {	printf (" %6.2f xEl", tm_utt.t_elapsed * 100.0 / nfrm);	printf (" %6.2f xCPU", tm_utt.t_cpu * 100.0 / nfrm);    }    printf ("\n");    fflush (stdout);}/* Process utterances in the control file (-ctl argument) */static void process_ctlfile ( void ){    FILE *ctlfp;    char *ctlfile, *nbestdir;    char line[1024], ctlspec[1024], uttid[1024];    int32 ctloffset, ctlcount;    int32 i, k, sf, ef;        if ((ctlfile = (char *) cmd_ln_access("-ctl")) == NULL)	E_FATAL("No -ctl argument\n");        E_INFO("Processing ctl file %s\n", ctlfile);        if ((ctlfp = fopen (ctlfile, "r")) == NULL)	E_FATAL("fopen(%s,r) failed\n", ctlfile);        ctloffset = *((int32 *) cmd_ln_access("-ctloffset"));    if (! cmd_ln_access("-ctlcount"))	ctlcount = 0x7fffffff;	/* All entries processed if no count specified */    else	ctlcount = *((int32 *) cmd_ln_access("-ctlcount"));    if (ctlcount == 0) {	E_INFO("-ctlcount argument = 0!!\n");	fclose (ctlfp);	return;    }        nbestdir = (char *) cmd_ln_access ("-nbestdir");    if (ctloffset > 0)	E_INFO("Skipping %d utterances in the beginning of control file\n",	       ctloffset);    while ((ctloffset > 0) && (fgets(line, sizeof(line), ctlfp) != NULL)) {	if (sscanf (line, "%s", ctlspec) > 0)	    --ctloffset;    }        while ((ctlcount > 0) && (fgets(line, sizeof(line), ctlfp) != NULL)) {	printf ("\n");	E_INFO("Utterance: %s", line);	sf = 0;	ef = (int32)0x7ffffff0;	if ((k = sscanf (line, "%s %d %d %s", ctlspec, &sf, &ef, uttid)) <= 0)	    continue;	    /* Empty line */	if ((k == 2) || ( (k >= 3) && ((sf >= ef) || (sf < 0))) ) {	    E_ERROR("Error in ctlfile spec; skipped\n");	    /* What happens to ctlcount??? */	    continue;	}	if (k < 4) {	    /* Create utt-id from mfc-filename (and sf/ef if specified) */	    for (i = strlen(ctlspec)-1; (i >= 0) && (ctlspec[i] != '/'); --i);	    if (k == 3)		sprintf (uttid, "%s_%d_%d", ctlspec+i+1, sf, ef);	    else		strcpy (uttid, ctlspec+i+1);	}	decode_utt (uttid, nbestdir);#if 0	linklist_stats ();#endif	--ctlcount;    }    printf ("\n");    while (fgets(line, sizeof(line), ctlfp) != NULL) {	if (sscanf (line, "%s", ctlspec) > 0) {	    E_INFO("Skipping rest of control file beginning with:\n\t%s", line);	    break;	}    }    fclose (ctlfp);}intmain (int32 argc, char *argv[]){  /*  kb_t kb;      ptmr_t tm;*/  print_appl_info(argv[0]);  cmd_ln_appl_enter(argc,argv,"default.arg",defn);  unlimit ();        /*     * 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.     */    {	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 ();    /* Initialize forward Viterbi search module */    nbest_init ();    printf ("\n");    ptmr_init (&tm_utt);        process_ctlfile ();#if (! WIN32)    system ("ps aguxwww | grep s3astar");#endif    cmd_ln_appl_exit();    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?