static void utt_livepretend(void *data, utt_res_t * ur, int32 sf, int32 ef, char *uttid) { char fullrawfn[FILENAME_LENGTH]; char *hypstr; short samples[SAMPLE_BUFFER_LENGTH]; float32 **frames; kb_t *kb; FILE *rawfd; int len, n_frames; kb = (kb_t *) data; /* report_utt_res(ur); */ sprintf(fullrawfn, "%s/%s%s", rawdirfn, ur->uttfile, decoder.rawext); if ((rawfd = fopen(fullrawfn, "rb")) == NULL) { E_FATAL("Cannnot open raw file %s.\n", fullrawfn); } /* temporary hack */ /* fread(waveheader, 1, 44, rawfd); */ if (ur->lmname != NULL) srch_set_lm((srch_t *) kb->srch, ur->lmname); if (ur->regmatname != NULL) kb_setmllr(ur->regmatname, ur->cb2mllrname, kb); if (s3_decode_begin_utt(&decoder, ur->uttfile) != S3_DECODE_SUCCESS) E_FATAL("Cannot begin utterance decoding.\n"); len = fread(samples, sizeof(short), SAMPLE_BUFFER_LENGTH, rawfd); while (len > 0) { ptmr_start(&(st->tm)); fe_process_utt(fe, samples, len, &frames, &n_frames); if (frames != NULL) { s3_decode_process(&decoder, frames, n_frames); ckd_free_2d((void **)frames); } ptmr_stop(&(st->tm)); if (S3_DECODE_SUCCESS == s3_decode_hypothesis(&decoder, NULL, &hypstr, NULL)) if (decoder.phypdump) E_INFO("PARTIAL_HYP: %s\n", hypstr); len = fread(samples, sizeof(short), SAMPLE_BUFFER_LENGTH, rawfd); } fclose(rawfd); s3_decode_end_utt(&decoder); }
int ofxSphinxASR::engineSentAudio(short *audioBuf, int audioSize) { float32 **frames; int n_frames; if (!bEngineInitialed) return OFXASR_HAVE_NOT_INIT; if (!bEngineOpened) return OFXASR_HAVE_NOT_START; fe_process_utt(fe, audioBuf, audioSize, &frames, &n_frames); if (frames != NULL) { s3_decode_process(decoder, frames, n_frames); ckd_free_2d((void **)frames); } return OFXASR_SUCCESS; }
static void utt_livepretend(void *data, utt_res_t * ur, int32 sf, int32 ef, char *uttid) { char fullrawfn[FILENAME_LENGTH]; char *hypstr; cont_ad_t *cont_ad; ad_rec_t bogus_ad; short samples[SAMPLE_BUFFER_LENGTH]; float32 **frames; kb_t *kb; int nread, n_frames, seg_n_frames; int ts, listening; kb = (kb_t *) data; /* report_utt_res(ur); */ sprintf(fullrawfn, "%s/%s%s", rawdirfn, ur->uttfile, decoder.rawext); if ((rawfd = fopen(fullrawfn, "rb")) == NULL) { E_FATAL("Cannnot open raw file %s.\n", fullrawfn); } if (ur->lmname != NULL) srch_set_lm((srch_t *) kb->srch, ur->lmname); if (ur->regmatname != NULL) kb_setmllr(ur->regmatname, ur->cb2mllrname, kb); bogus_ad.sps = (int32) cmd_ln_float32_r(kb->kbcore->config, "-samprate"); if ((cont_ad = cont_ad_init(&bogus_ad, ad_file_read)) == NULL) { E_FATAL("Failed to initialize energy-based endpointer"); } listening = 0; ts = 0; seg_n_frames = 0; while ((nread = cont_ad_read(cont_ad, samples, SAMPLE_BUFFER_LENGTH)) >= 0) { if (nread) { ts = cont_ad->read_ts; if (!listening) { char uttid[FILENAME_LENGTH]; sprintf(uttid, "%s_%.3f", ur->uttfile, (double) ts / bogus_ad.sps); if (s3_decode_begin_utt(&decoder, uttid) != S3_DECODE_SUCCESS) E_FATAL("Cannot begin utterance decoding.\n"); listening = 1; } ptmr_start(&(st->tm)); fe_process_utt(fe, samples, nread, &frames, &n_frames); seg_n_frames += n_frames; if (frames != NULL) { s3_decode_process(&decoder, frames, n_frames); ckd_free_2d((void **)frames); } ptmr_stop(&(st->tm)); if (s3_decode_hypothesis(&decoder, NULL, &hypstr, NULL) == S3_DECODE_SUCCESS) { if (decoder.phypdump) { E_INFO("PARTIAL_HYP: %s\n", hypstr); } } /* If the segment is too long, break it. */ if (seg_n_frames > 15000) { s3_decode_end_utt(&decoder); listening = 0; } } else { if (listening && cont_ad->read_ts - ts > 8000) { /* HACK */ s3_decode_end_utt(&decoder); listening = 0; } } } fclose(rawfd); cont_ad_close(cont_ad); if (listening) s3_decode_end_utt(&decoder); }