/* RAH 4.15.01 Lots of memory is allocated, but never freed, this function will clean up. * First pass will get the low hanging fruit.*/ void kb_free (kb_t *kb) { vithist_t *vithist = kb->vithist; if (kb->sen_active) ckd_free ((void *)kb->sen_active); if (kb->ssid_active) ckd_free ((void *)kb->ssid_active); if (kb->comssid_active) ckd_free ((void *)kb->comssid_active); if (kb->fillertree) ckd_free ((void *)kb->fillertree); if (kb->hmm_hist) ckd_free ((void *)kb->hmm_hist); /* vithist */ if (vithist) { ckd_free ((void *) vithist->entry); ckd_free ((void *) vithist->frame_start); ckd_free ((void *) vithist->bestscore); ckd_free ((void *) vithist->bestvh); ckd_free ((void *) vithist->lms2vh_root); ckd_free ((void *) kb->vithist); } kbcore_free (kb->kbcore); if (kb->feat) { ckd_free ((void *)kb->feat[0][0]); ckd_free_2d ((void **)kb->feat); } if (kb->cache_ci_senscr) { ckd_free_2d ((void **)kb->cache_ci_senscr); } if( kb->cache_best_list) { ckd_free((void*) kb->cache_best_list); } if(kb->phn_heur_list) { ckd_free((void*) kb->phn_heur_list); } if (kb->matchsegfp) fclose(kb->matchsegfp); if (kb->matchfp) fclose(kb->matchfp); kb_freehyps(kb); }
int ld_utt_begin(live_decoder_t *decoder, char *uttid) { kb_freehyps(&decoder->kb); fe_start_utt(decoder->fe); utt_begin(&decoder->kb); /* lgalescu@ihmc : decoder->uttid is never set! should do it here: */ strcpy(decoder->uttid, uttid); decoder->frame_num = 0; decoder->kb.nfr = 0; decoder->kb.utt_hmm_eval = 0; decoder->kb.utt_sen_eval = 0; decoder->kb.utt_gau_eval = 0; decoder->ld_state = LD_STATE_STARTED; return 0; }
int ld_utt_hyps(live_decoder_t *decoder, char **hyp_str, hyp_t ***hyp_segs) { int32 id; int32 i = 0; glist_t hyp_list; gnode_t *node; hyp_t *hyp; dict_t *dict; char *hyp_strptr; kb_t *kb = &decoder->kb; if (decoder->ld_state == LD_STATE_ENDED) { if (hyp_segs) { *hyp_segs = kb->hyp_segs; } if (hyp_str) { *hyp_str = kb->hyp_str; } return 0; } else { kb_freehyps(kb); } dict = kbcore_dict (decoder->kbcore); id = vithist_partialutt_end(kb->vithist, decoder->kbcore); if (id >= 0) { hyp_list = vithist_backtrace(kb->vithist, id); /* record the segment length and the overall string length */ for (node = hyp_list; node; node = gnode_next(node)) { hyp = (hyp_t *)gnode_ptr(node); if (hyp_segs) { kb->hyp_seglen++; } if (hyp_str) { if (!dict_filler_word(dict, hyp->id) && hyp->id != dict_finishwid(dict)) { kb->hyp_strlen += strlen(dict_wordstr(dict, dict_basewid(dict, hyp->id))) + 1; } } } /* allocate array to hold the segments and/or decoded string */ if (hyp_segs) { kb->hyp_segs = (hyp_t **)ckd_calloc(kb->hyp_seglen, sizeof(hyp_t *)); } if (hyp_str) { kb->hyp_str = (char *)ckd_calloc(kb->hyp_strlen+1, sizeof(char)); } /* iterate thru to fill in the array of segments and/or decoded string */ i = 0; if (hyp_str) { hyp_strptr = kb->hyp_str; } for (node = hyp_list; node; node = gnode_next(node), i++) { hyp = (hyp_t *)gnode_ptr(node); if (hyp_segs) { kb->hyp_segs[i] = hyp; } if (hyp_str) { strcat(hyp_strptr, dict_wordstr(dict, dict_basewid(dict, hyp->id))); hyp_strptr += strlen(hyp_strptr); strcat(hyp_strptr, " "); hyp_strptr += 1; } } glist_free(hyp_list); if (hyp_str) { kb->hyp_str[kb->hyp_strlen - 1] = '\0'; } } if (hyp_segs) { *hyp_segs = kb->hyp_segs; } if (hyp_str) { *hyp_str = kb->hyp_str; } return 0; }