main_decode_anytopo.c

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

C
1,466
字号
				if ( *((int32 *) cmd_ln_access("-backtrace")) )		    log_hyp_detailed (stdout, hyp, uttid, "BP", "bp");				/* Total scaled acoustic score and LM score */		ascr = lscr = 0;		for (h = hyp; h; h = h->next) {		    ascr += h->ascr;		    lscr += h->lscr;		}				printf ("BSTPTH: ");		log_hypstr (stdout, hyp, uttid, matchexact, ascr + lscr);				printf ("BSTXCT: ");		log_hypseg (uttid, stdout, hyp, nfr, scl, lwf);	    }	    	    dag_destroy ();	}		lm_cache_stats_dump (lm);	lm_cache_reset (lm);    } else {	E_ERROR ("%s: Viterbi search failed\n", uttid);	hyp = NULL;    }        /* Log recognition output to the standard match and matchseg files */    if (matchfp)	log_hypstr (matchfp, hyp, uttid, matchexact, 0);    if (matchsegfp)	log_hypseg (uttid, matchsegfp, hyp, nfr, scl, lwf);    ptmr_stop (&tmr_utt);        printf ("%s: ", uttid);    pctr_print(stderr,ctr_nfrm);    pctr_print(stderr,ctr_nsen);    printf ("%s: TMR: %5d Frm", uttid, nfr);    if (nfr > 0) {	printf (" %6.2f xEl", tmr_utt.t_elapsed * 100.0 / nfr);	printf (" %6.2f xCPU", tmr_utt.t_cpu * 100.0 / nfr);	if (tmr_utt.t_cpu > 0.0) {	    printf (" [fwd %6.2fx %3d%%]", tmr_fwdvit.t_cpu * 100.0 / nfr,		    (int32) ((tmr_fwdvit.t_cpu * 100.0) / tmr_utt.t_cpu));	    printf ("[gau+sen %6.2fx %2d%%]", tmr_gausen.t_cpu * 100.0 / nfr,		    (int32) ((tmr_gausen.t_cpu * 100.0) / tmr_utt.t_cpu));	    printf ("[srch %6.2fx %2d%%]", tmr_fwdsrch.t_cpu * 100.0 / nfr,		    (int32) ((tmr_fwdsrch.t_cpu * 100.0) / tmr_utt.t_cpu));	    	    fwd_timing_dump (tmr_utt.t_cpu);	    	    if (bp)		printf ("[bp %6.2fx %2d%%]", tmr_bstpth.t_cpu * 100.0 / nfr,			(int32) ((tmr_bstpth.t_cpu * 100.0) / tmr_utt.t_cpu));	}    }    printf ("\n");    fflush (stdout);        tot_nfr += nfr;}/* Process utterances in the control file (-ctl argument) */static int32 process_ctlfile ( void ){    FILE *ctlfp, *mllrctlfp;    char *ctlfile, *cepdir, *cepext, *mllrctlfile;    char *matchfile, *matchsegfile;    char line[1024], ctlspec[1024], cepfile[1024], uttid[1024];    char mllrfile[1024], prevmllr[1024];/* CHANGE BY BHIKSHA: ADDED veclen AS A VARIABLE, 6 JAN 98 */    int32 ctloffset, ctlcount, veclen, sf, ef, nfr;/* END OF CHANGES BY BHIKSHA */    int32 err_status;    int32 i, k;        err_status = 0;        if ((ctlfile = (char *) cmd_ln_access("-ctl")) == NULL)	E_FATAL("No -ctl argument\n");    E_INFO("Processing ctl file %s\n", ctlfile);        if ((mllrctlfile = (char *) cmd_ln_access("-mllrctl")) != NULL) {	if ((mllrctlfp = fopen (mllrctlfile, "r")) == NULL)	    E_FATAL("fopen(%s,r) failed\n", mllrctlfile);    } else	mllrctlfp = NULL;    prevmllr[0] = '\0';        if ((ctlfp = fopen (ctlfile, "r")) == NULL)	E_FATAL("fopen(%s,r) failed\n", ctlfile);        if ((matchfile = (char *) cmd_ln_access("-hyp")) == NULL) {	matchfp = NULL;    } else {	/* Look for ,EXACT suffix, for retaining fillers/pronunciation specs in output */	k = strlen (matchfile);	if ((k > 6) && (strcmp (matchfile+(k-6), ",EXACT") == 0)) {	    matchexact = 1;	    matchfile[k-6] = '\0';	} else	    matchexact = 0;	if ((matchfp = fopen (matchfile, "w")) == NULL)	    E_ERROR("fopen(%s,w) failed\n", matchfile);    }        if ((matchsegfile = (char *) cmd_ln_access("-hypseg")) == NULL) {	E_WARN("No -hypseg argument\n");	matchsegfp = NULL;    } else {	if ((matchsegfp = fopen (matchsegfile, "w")) == NULL)	    E_ERROR("fopen(%s,w) failed\n", matchsegfile);    }        cepdir = (char *) cmd_ln_access("-cepdir");    cepext = (char *) cmd_ln_access("-cepext");    assert ((cepdir != NULL) && (cepext != NULL));/* BHIKSHA: ADDING VECLEN TO ALLOW VECTORS OF DIFFERENT SIZES */    veclen = *((int32 *) cmd_ln_access("-ceplen"));/* END CHANGES, 6 JAN 1998, BHIKSHA */        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 err_status;    }        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) {	    if (mllrctlfp) {		if (fscanf (mllrctlfp, "%s", mllrfile) != 1)		    E_FATAL ("Unexpected EOF(%s)\n", mllrctlfile);	    }	    --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);	}	if (mllrctlfp) {	    if (fscanf (mllrctlfp, "%s", mllrfile) != 1)		E_FATAL ("Unexpected EOF(%s)\n", mllrctlfile);	    	    if (strcmp (prevmllr, mllrfile) != 0) {		float32 ***A, **B;		int32 gid, sid;		uint8 *mgau_xform;				gauden_mean_reload (g, (char *) cmd_ln_access("-mean"));				if (ms_mllr_read_regmat (mllrfile, &A, &B, fcb->stream_len,feat_n_stream(fcb)) < 0)		    E_FATAL("ms_mllr_read_regmat failed\n");				mgau_xform = (uint8 *) ckd_calloc (g->n_mgau, sizeof(uint8));		/* Transform each non-CI mixture Gaussian */		for (sid = 0; sid < sen->n_sen; sid++) {		    if (mdef->cd2cisen[sid] != sid) {	/* Otherwise it's a CI senone */			gid = sen->mgau[sid];			if (! mgau_xform[gid]) {			    ms_mllr_norm_mgau (g->mean[gid], g->n_density, A, B,					    fcb->stream_len,feat_n_stream(fcb));			    mgau_xform[gid] = 1;			}		    }		}		ckd_free (mgau_xform);				ms_mllr_free_regmat (A, B, fcb->stream_len,feat_n_stream(fcb));		strcpy (prevmllr, mllrfile);	    }	}	if (! feat)	  feat = feat_array_alloc (fcb, S3_MAX_FRAMES);		/* Read and process mfc/feature speech input file */	nfr = feat_s2mfc2feat(fcb, ctlspec, cepdir, cepext,sf, ef, feat, S3_MAX_FRAMES);	assert(feat);	if (nfr <= 0)	    E_ERROR("Utt %s: Input file read (%s) failed\n", uttid, cepfile);	else {	  E_INFO ("%s: %d mfc frames\n", uttid, nfr);	  assert(feat);	  decode_utt (nfr, uttid);	}#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;	}    }        if (matchfp)	fclose (matchfp);    if (matchsegfp)	fclose (matchsegfp);    fclose (ctlfp);    if (mllrctlfp)	fclose (mllrctlfp);        return (err_status);}int main (int32 argc, char *argv[]){    int32 err_status;    print_appl_info(argv[0]);    cmd_ln_appl_enter(argc,argv,"default.arg",defn);    unlimit ();        if ((cmd_ln_access("-mdef") == NULL) ||	(cmd_ln_access("-mean") == NULL) ||	(cmd_ln_access("-var") == NULL)  ||	(cmd_ln_access("-mixw") == NULL)  ||	(cmd_ln_access("-tmat") == NULL))	E_FATAL("Missing -mdef, -mean, -var, -mixw, or -tmat argument\n");    if ((cmd_ln_access("-dict") == NULL) ||	(cmd_ln_access("-lm") == NULL))	E_FATAL("Missing -dict or -lm argument\n");        inlatdir = (char *) cmd_ln_access ("-inlatdir");    outlatdir = (char *) cmd_ln_access ("-outlatdir");    if (outlatdir) {	int32 k;		k = strlen(outlatdir);	if ((k > 6) && (strcmp (outlatdir+(k-6), ",NODES") == 0)) {	    outlat_onlynodes = 1;	    outlatdir[k-6] = '\0';	} else	    outlat_onlynodes = 0;    }    if (inlatdir && outlatdir && (strcmp (inlatdir, outlatdir) == 0))	E_FATAL("Input and output lattice directories are the same\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.     */    {	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.01)	    E_WARN("Logbase %e perhaps too large??\n", logbase);	logs3_init ((float64) logbase);    }    /* Initialize feature stream type */    /*feat_init ((char *) cmd_ln_access ("-feat"));*/    fcb = feat_init ( (char *) cmd_ln_access ("-feat"),		      (char *) cmd_ln_access ("-cmn"),		      (char *) cmd_ln_access ("-varnorm"),		      (char *) cmd_ln_access ("-agc"));        /* Read in input databases */    models_init ();        /* Senone scaling factor in each frame */    senscale = (int32 *) ckd_calloc (S3_MAX_FRAMES, sizeof(int32));    /* Best statescore in each frame */    bestscr = (int32 *) ckd_calloc (S3_MAX_FRAMES, sizeof(int32));        /* Allocate profiling timers and counters */    ptmr_init(&tmr_utt);    ptmr_init(&tmr_fwdvit);    ptmr_init(&tmr_bstpth);    ptmr_init(&tmr_gausen);    ptmr_init(&tmr_fwdsrch);        pctr_new(ctr_nfrm,"frm");    pctr_new(ctr_nsen,"sen");    /* Initialize forward Viterbi search module */    fwd_init (mdef,tmat,dict,lm);    printf ("\n");        tot_nfr = 0;        err_status = process_ctlfile ();    if (tot_nfr > 0) {	printf ("\n");	printf("TOTAL FRAMES:       %8d\n", tot_nfr);	printf("TOTAL CPU TIME:     %11.2f sec, %7.2f xRT\n",	       tmr_utt.t_tot_cpu, tmr_utt.t_tot_cpu/(tot_nfr*0.01));	printf("TOTAL ELAPSED TIME: %11.2f sec, %7.2f xRT\n",	       tmr_utt.t_tot_elapsed, tmr_utt.t_tot_elapsed/(tot_nfr*0.01));	fflush (stdout);    }#if (! WIN32)#if defined(_SUN4)    system("ps -el | grep s3decode");#else    system ("ps aguxwww | grep s3decode");#endif#endif    cmd_ln_appl_exit();    exit(err_status);    return 0 ;}

⌨️ 快捷键说明

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