Ejemplo n.º 1
0
void
mdef_dump(FILE * fp, mdef_t * m)
{
    int32 i, j;
    int32 ssid;
    char buf[1024];

    fprintf(fp, "%d ciphone\n", m->n_ciphone);
    fprintf(fp, "%d phone\n", m->n_phone);
    fprintf(fp, "%d emitstate\n", m->n_emit_state);
    fprintf(fp, "%d cisen\n", m->n_ci_sen);
    fprintf(fp, "%d sen\n", m->n_sen);
    fprintf(fp, "%d tmat\n", m->n_tmat);

    for (i = 0; i < m->n_phone; i++) {
        mdef_phone_str(m, i, buf);
        ssid = m->phone[i].ssid;

        fprintf(fp, "%3d %5d", m->phone[i].tmat, ssid);
        for (j = 0; j < m->n_emit_state; j++)
            fprintf(fp, " %5d", m->sseq[ssid][j]);
        fprintf(fp, "\t");
        for (j = 0; j < m->n_emit_state; j++)
            fprintf(fp, " %3d", m->cd2cisen[m->sseq[ssid][j]]);
        fprintf(fp, "\t%s\n", buf);
    }

    fflush(fp);
}
Ejemplo n.º 2
0
/* Write phone segmentation output file */
static void
write_phseg(char *dir, align_phseg_t * phseg, char *uttid, char *ctlspec)
{
    char str[1024];
    FILE *fp;
    int32 uttscr;

    /* Attempt to write segmentation for this utt to a separate file */
    build_output_uttfile(str, dir, uttid, ctlspec);
    strcat(str, ".phseg");
    E_INFO("Writing phone segmentation to: %s\n", str);
    if ((fp = fopen(str, "w")) == NULL) {
        E_ERROR_SYSTEM("Failed to open file %s for writing", str);
        fp = stdout;            /* Segmentations can be directed to stdout this way */
        E_INFO("Phone segmentation (%s):\n", uttid);
        dir = NULL;             /* Flag to indicate fp shouldn't be closed at the end */
    }

    if (!dir) {
        fprintf(fp, "PH:%s>", uttid);
        fflush(fp);
    }
    fprintf(fp, "\t%5s %5s %9s %s\n", "SFrm", "EFrm", "SegAScr", "Phone");
    fflush(fp);
    uttscr = 0;
    for (; phseg; phseg = phseg->next) {
        mdef_phone_str(kbc->mdef, phseg->pid, str);

        if (!dir) {
            fprintf(fp, "ph:%s>", uttid);
            fflush(fp);
        }
        fprintf(fp, "\t%5d %5d %9d %s\n",
                phseg->sf, phseg->ef, phseg->score, str);
        fflush(fp);
        uttscr += (phseg->score);
    }

    if (!dir) {
        fprintf(fp, "PH:%s>", uttid);
        fflush(fp);
    }
    fprintf(fp, " Total score: %11d\n", uttscr);
    fflush(fp);

    if (dir)
        fclose(fp);
    else {
        fprintf(fp, "\n");
        fflush(fp);
    }
}
/* Write phone segmentation output file */
static void write_phseg (char *dir, align_phseg_t *phseg, char *uttid, char *ctlspec)
{
    char str[1024];
    FILE *fp;
    int32 uttscr, f, scale;
    
    /* Attempt to write segmentation for this utt to a separate file */
    build_output_uttfile (str, dir, uttid, ctlspec);
    strcat (str, ".phseg");
    E_INFO("Writing phone segmentation to: %s\n", str);
    if ((fp = fopen (str, "w")) == NULL) {
	E_ERROR("fopen(%s,w) failed\n", str);
	fp = stdout;	/* Segmentations can be directed to stdout this way */
	E_INFO ("Phone segmentation (%s):\n", uttid);
	dir = NULL;	/* Flag to indicate fp shouldn't be closed at the end */
    }
    
    if (! dir)
	fprintf (fp, "PH:%s>", uttid);
    fprintf (fp, "\t%5s %5s %9s %s\n",
	     "SFrm", "EFrm", "SegAScr", "Phone");
    
    uttscr = 0;
    for (; phseg; phseg = phseg->next) {
	mdef_phone_str (mdef, phseg->pid, str);
	
	/* Account for senone score scaling in each frame */
	scale = 0;
	for (f = phseg->sf; f <= phseg->ef; f++)
	    scale += senscale[f];
	
	if (! dir)
	    fprintf (fp, "ph:%s>", uttid);
	fprintf (fp, "\t%5d %5d %9d %s\n",
		 phseg->sf, phseg->ef, phseg->score + scale, str);
	
	uttscr += (phseg->score + scale);
    }

    if (! dir)
	fprintf (fp, "PH:%s>", uttid);
    fprintf (fp, " Total score: %11d\n", uttscr);

    if (dir)
	fclose (fp);
    else
	fprintf (fp, "\n");
}
Ejemplo n.º 4
0
static void
triphone_add(mdef_t * m,
             int ci, int lc, int rc, word_posn_t wpos,
             int p)
{
    ph_lc_t *lcptr;
    ph_rc_t *rcptr;

    assert(p < m->n_phone);

    /* Fill in phone[p] information (state and tmat mappings added later) */
    m->phone[p].ci = ci;
    m->phone[p].lc = lc;
    m->phone[p].rc = rc;
    m->phone[p].wpos = wpos;

    /* Create <ci,lc,rc,wpos> -> p mapping if not a CI phone */
    if (p >= m->n_ciphone) {
        if ((lcptr = find_ph_lc(m->wpos_ci_lclist[wpos][(int) ci], lc))
            == NULL) {
            lcptr = (ph_lc_t *) ckd_calloc(1, sizeof(ph_lc_t)); /* freed at mdef_free, I believe */
            lcptr->lc = lc;
            lcptr->next = m->wpos_ci_lclist[wpos][(int) ci];
            m->wpos_ci_lclist[wpos][(int) ci] = lcptr;  /* This is what needs to be freed */
        }
        if ((rcptr = find_ph_rc(lcptr->rclist, rc)) != NULL) {
            __BIGSTACKVARIABLE__ char buf[4096];

            mdef_phone_str(m, rcptr->pid, buf);
            E_FATAL("Duplicate triphone: %s\n", buf);
        }

        rcptr = (ph_rc_t *) ckd_calloc(1, sizeof(ph_rc_t));     /* freed in mdef_free, I believe */
        rcptr->rc = rc;
        rcptr->pid = p;
        rcptr->next = lcptr->rclist;
        lcptr->rclist = rcptr;
    }
}