void s3_decode_end_utt(s3_decode_t * _decode) { int32 num_features; if (_decode == NULL) return; if (_decode->state != S3_DECODE_STATE_DECODING) { E_WARN("Cannot end utterance in current decoder state.\n"); return; } /* Call this with no frames, to update CMN and AGC statistics. */ num_features = feat_s2mfc2feat_live(kbcore_fcb(_decode->kbcore), NULL, NULL, FALSE, TRUE, _decode->kb.feat); if (num_features > 0) utt_decode_block(_decode->kb.feat, num_features, &_decode->num_frames_decoded, &_decode->kb); _decode->kb.stat->tot_fr += _decode->kb.stat->nfr; s3_decode_record_hyps(_decode, TRUE); utt_end(&_decode->kb); _decode->state = S3_DECODE_STATE_IDLE; }
int ld_utt_end(live_decoder_t *decoder) { ld_utt_proc_raw_impl(decoder, 0, 0, decoder->frame_num == 0, 1); decoder->kb.tot_fr += decoder->kb.nfr; utt_end(&decoder->kb); decoder->ld_state = LD_STATE_ENDED; return 0; }
void ld_end_utt(live_decoder_t * _decoder) { assert(_decoder != NULL); if (_decoder->ld_state != LD_STATE_DECODING) { E_WARN("ld_end_utt() called with decoder idle/finished.\n"); return; } ld_process_raw_impl(_decoder, NULL, 0, TRUE); _decoder->kb.stat->tot_fr += _decoder->kb.stat->nfr; ld_record_hyps(_decoder, TRUE); utt_end(&_decoder->kb); _decoder->ld_state = LD_STATE_IDLE; }
int32 live_utt_decode_block (int16 *samples, int32 nsamples, int32 live_endutt, partialhyp_t **ohyp) { static int32 live_begin_new_utt = 1; static int32 frmno; float32 **live_feat; int32 live_nfr, live_nfeatvec; int32 nwds; /* int32 id; */ /* unreferenced variable */ /* glist_t hyp; */ /* unreferenced variable */ /* gnode_t *gn; */ /* unreferenced variable */ /* hyp_t *h; */ /* unreferenced variable */ /* dict_t *dict; */ /* unreferenced variable */ float32 **mfcbuf; if (live_begin_new_utt){ fe_start_utt(fe); utt_begin (kb); frmno = 0; kb->nfr = 0; kb->utt_hmm_eval = 0; kb->utt_sen_eval = 0; kb->utt_gau_eval = 0; live_begin_new_utt = 0; } sample_blk++; /* 10.jan.01 RAH, fe_process_utt now requires ***mfcbuf and it allocates the memory internally) */ mfcbuf = NULL; live_nfr = fe_process_utt(fe, samples, nsamples, &mfcbuf); /* */ if (live_endutt) /* RAH, It seems that we shouldn't throw out this data */ fe_end_utt(fe,dummyframe); /* Flush out the fe */ /* Compute feature vectors */ live_nfeatvec = feat_s2mfc2feat_block(kbcore_fcb(kbcore), mfcbuf, live_nfr, live_begin_new_utt, live_endutt, &live_feat); E_INFO ("live_nfeatvec: %ld\n",live_nfeatvec); /* decode the block */ if (sample_blk<=START_BLOCK) single_utt_decode_block (live_feat, live_nfeatvec, &frmno, kb, maxwpf, maxhistpf, maxhmmpf, ptranskip, hmmdumpfp); else utt_decode_block (live_feat, live_nfeatvec, &frmno, kb, maxwpf, maxhistpf, maxhmmpf, ptranskip, hmmdumpfp); /* Pull out partial hypothesis */ nwds = live_get_partialhyp(live_endutt); *ohyp = parthyp; /* Clean up */ if (live_endutt) { live_begin_new_utt = 1; kb->tot_fr += kb->nfr; utt_end(kb); } else { live_begin_new_utt = 0; } /* I'm starting to think that fe_process_utt should not be allocating its memory, that or it should allocate some max and just keep on going, this idea of constantly allocating freeing memory seems dangerous to me.*/ ckd_free_2d((void **) mfcbuf); /* RAH, this must be freed since fe_process_utt allocates it */ return(nwds); }
void utt_decode(void *data, utt_res_t * ur, int32 sf, int32 ef, char *uttid) { kb_t *kb; kbcore_t *kbcore; cmd_ln_t *config; int32 num_decode_frame; int32 total_frame; stat_t *st; srch_t *s; num_decode_frame = 0; E_INFO("Processing: %s\n", uttid); kb = (kb_t *) data; kbcore = kb->kbcore; config = kbcore_config(kbcore); kb_set_uttid(uttid, ur->uttfile, kb); st = kb->stat; /* Convert input file to cepstra if waveform input is selected */ if (cmd_ln_boolean_r(config, "-adcin")) { int16 *adcdata; int32 nsamps = 0; if ((adcdata = bio_read_wavfile(cmd_ln_str_r(config, "-cepdir"), ur->uttfile, cmd_ln_str_r(config, "-cepext"), cmd_ln_int32_r(config, "-adchdr"), strcmp(cmd_ln_str_r(config, "-input_endian"), "big"), &nsamps)) == NULL) { E_FATAL("Cannot read file %s\n", ur->uttfile); } if (kb->mfcc) { ckd_free_2d((void **)kb->mfcc); } fe_start_utt(kb->fe); if (fe_process_utt(kb->fe, adcdata, nsamps, &kb->mfcc, &total_frame) < 0) { E_FATAL("MFCC calculation failed\n", ur->uttfile); } ckd_free(adcdata); if (total_frame > S3_MAX_FRAMES) { E_FATAL("Maximum number of frames (%d) exceeded\n", S3_MAX_FRAMES); } if ((total_frame = feat_s2mfc2feat_live(kbcore_fcb(kbcore), kb->mfcc, &total_frame, TRUE, TRUE, kb->feat)) < 0) { E_FATAL("Feature computation failed\n"); } } else { /* Read mfc file and build feature vectors for entire utterance */ if ((total_frame = feat_s2mfc2feat(kbcore_fcb(kbcore), ur->uttfile, cmd_ln_str_r(config, "-cepdir"), cmd_ln_str_r(config, "-cepext"), sf, ef, kb->feat, S3_MAX_FRAMES)) < 0) { E_FATAL("Cannot read file %s. Forced exit\n", ur->uttfile); } } /* Also need to make sure we don't set resource if it is the same. Well, this mechanism could be provided inside the following function. */ s = kb->srch; if (ur->lmname != NULL) srch_set_lm(s, ur->lmname); if (ur->regmatname != NULL) kb_setmllr(ur->regmatname, ur->cb2mllrname, kb); /* These are necessary! */ s->uttid = kb->uttid; s->uttfile = kb->uttfile; utt_begin(kb); utt_decode_block(kb->feat, total_frame, &num_decode_frame, kb); utt_end(kb); st->tot_fr += st->nfr; }
int32 live_utt_decode_block (int16 *samples, int32 nsamples, int32 live_endutt, partialhyp_t **ohyp) { static int32 live_begin_new_utt = 1; static int32 frmno; static float32 ***live_feat = NULL; int32 live_nfr, live_nfeatvec; int32 nwds =0; float32 **mfcbuf; /* int i,j;*/ /* 2004/08/27 L Galescu <*****@*****.**> -- added raw audio file saving */ static char uttfn[1024]; static FILE *rawfp = NULL; int16 block_peak_amplitude; if(live_feat==NULL) live_feat = feat_array_alloc (kbcore_fcb(kbcore), LIVEBUFBLOCKSIZE); if (live_begin_new_utt){ fe_start_utt(fe); utt_begin (kb); frmno = 0; kb->nfr = 0; kb->utt_hmm_eval = 0; kb->utt_sen_eval = 0; kb->utt_gau_eval = 0; live_begin_new_utt = 0; sprintf(uttfn, "%s/%s.raw", cmd_ln_str("-outrawdir"), kb->uttid); rawfp = fopen(uttfn, "wb"); } /* 10.jan.01 RAH, fe_process_utt now requires ***mfcbuf and it allocates the memory internally) */ mfcbuf = NULL; /* LG 20080613 */ block_peak_amplitude = get_peak_amplitude(samples, nsamples); if (block_peak_amplitude > peak_amplitude) peak_amplitude = block_peak_amplitude; E_INFO("segment peak %d\n",peak_amplitude); live_nfr = fe_process_utt(fe, samples, nsamples, &mfcbuf); /**/ if (rawfp != NULL) { fwrite(samples, sizeof(int16), nsamples, rawfp); if (live_endutt) fclose(rawfp); } if (live_endutt) { /* RAH, It seems that we shouldn't throw out this data */ fe_end_utt(fe,dummyframe); /* Flush out the fe */ } #if 0 E_INFO("Number frame after fe_process_utt %d\n",live_nfr); for(i=0;i<live_nfr;i++){ printf("%d ",i); for(j=0;j<13;j++){ printf("%f ",mfcbuf[i][j]); fflush(stdout); } printf("\n"); fflush(stdout); } #endif /* lgalescu 2004/08/22 -- i am under the impression that * feat_s2mfc2feat_block() needs to be called at the end of utt * even if no frames need processing */ /* lgalescu 2004/10/13 -- rescinded the above */ if(live_nfr>0){ /* Compute feature vectors */ live_nfeatvec = feat_s2mfc2feat_block(kbcore_fcb(kbcore), mfcbuf, live_nfr, live_begin_new_utt, live_endutt, live_feat); #if 0 E_INFO ("live_nfeatvec: %ld\n",live_nfeatvec); #endif #if 0 E_INFO("Current frame number %d, Number of frames %d, Number frame after feat_s2mfcfeat_block %d\n",frmno,live_nfr,live_nfeatvec); for(i=0;i<live_nfeatvec;i++){ printf("%d\n",i); printf("Cep: "); fflush(stdout); for(j=0;j<13;j++){ printf("%f ",live_feat[i][0][j]); fflush(stdout); } printf("\n"); fflush(stdout); printf("Del: "); fflush(stdout); for(j=13;j<26;j++){ printf("%f ",live_feat[i][0][j]); fflush(stdout); } printf("\n"); fflush(stdout); printf("Acc: "); fflush(stdout); for(j=26;j<39;j++){ printf("%f ",live_feat[i][0][j]); fflush(stdout); } printf("\n"); fflush(stdout); } #endif /* decode the block */ utt_decode_block (live_feat, live_nfeatvec, &frmno, kb, maxwpf, maxhistpf, maxhmmpf, ptranskip, hmmdumpfp); /* lgalescu 2004/08/21 * moved the following block out of the previous if(){} because we need * the output even when no feature computation has to be done. */ /* lgalescu 2004/10/13 -- rescinded */ /* Pull out partial hypothesis */ nwds = live_get_partialhyp(live_endutt); *ohyp = parthyp; parthyplen = nwds; } /* Clean up */ if (live_endutt) { live_begin_new_utt = 1; kb->tot_fr += kb->nfr; utt_end(kb); } else { live_begin_new_utt = 0; } /* I'm starting to think that fe_process_utt should not be allocating its * memory, that or it should allocate some max and just keep on going, * this idea of constantly allocating freeing memory seems dangerous to me. */ /* 20040318 ARCHAN : It sounds extremely dangerous to me and I will * eliminate it sometime. */ /* lgalescu: i second that! the memory issue needs to be investigated: after a run on linux, i noticed some 1.6M of memory having "disappeared"! */ if(live_nfr>0){ ckd_free_2d((void **) mfcbuf); /* RAH, this must be freed since fe_process_utt allocates it */ } return(parthyplen); }