boolean mfc_module_set_header(MFCCCalc *mfcc, Recog *recog) { FUNC_INT func; unsigned int ret; func = (FUNC_INT) plugin_get_func(mfcc->plugin_source, "fvin_get_configuration"); if (func == NULL) { jlog("ERROR: feature vector input plugin: fvin_get_configuration() not found\n"); return FALSE; } /* vector length in unit */ mfcc->param->veclen = (*func)(0); mfcc->param->header.sampsize = mfcc->param->veclen * sizeof(VECT); /* frame shift in msec */ mfcc->param->header.wshift = (*func)(1) * 10000.0; /* parameter type for checking (return 0xffff to disable the check) */ ret = (*func)(2); if (ret == 0xffff) { /* disable type checking */ recog->jconf->input.paramtype_check_flag = FALSE; } else { mfcc->param->header.samptype = ret; } return TRUE; }
boolean mfc_module_set_header(MFCCCalc *mfcc, Recog *recog) { FUNC_INT func; unsigned int ret; #ifdef ENABLE_PLUGIN if (mfcc->plugin_source < 0) { /* no plugin, use the default functions */ func = vecin_get_configuration; } else { func = (FUNC_INT) plugin_get_func(mfcc->plugin_source, "fvin_get_configuration"); if (func == NULL) { jlog("ERROR: feature vector input: fvin_get_configuration() not found\n"); return FALSE; } } #else func = vecin_get_configuration; #endif /* vector length in unit */ mfcc->param->veclen = (*func)(0); mfcc->param->header.sampsize = mfcc->param->veclen * sizeof(VECT); /* frame shift in msec */ mfcc->param->header.wshift = (*func)(1) * 10000.0; /* parameter type for checking (return 0xffff to disable the check) */ ret = (*func)(2); if (ret == 0xffff) { /* disable type checking */ recog->jconf->input.paramtype_check_flag = FALSE; } else { mfcc->param->header.samptype = ret; } /* switch if the input vector is feature vector or outprob vector */ mfcc->param->is_outprob = ( (*func)(3) > 0 ) ? TRUE : FALSE; return TRUE; }
boolean mfc_module_init(MFCCCalc *mfcc, Recog *recog) { mfcc->plugin_source = recog->jconf->input.plugin_source; if (mfcc->plugin_source < 0) { jlog("ERROR: SP_MDCMODULE selected but plugin is missing?\n"); return FALSE; } mfcc->func.fv_standby = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_standby"); mfcc->func.fv_begin = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_open"); mfcc->func.fv_read = (int (*)(VECT *, int)) plugin_get_func(mfcc->plugin_source, "fvin_read"); mfcc->func.fv_end = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_close"); mfcc->func.fv_resume = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_resume"); mfcc->func.fv_pause = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_pause"); mfcc->func.fv_terminate= (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_terminate"); mfcc->func.fv_input_name= (char * (*)()) plugin_get_func(mfcc->plugin_source, "fvin_input_name"); if (mfcc->func.fv_read == NULL) { jlog("ERROR: FEATURE_INPUT plugin: fvin_read() not found!\n"); return FALSE; } return TRUE; }
boolean mfc_module_init(MFCCCalc *mfcc, Recog *recog) { /* assign default functions */ mfcc->func.fv_standby = (boolean (*)()) vecin_standby; mfcc->func.fv_begin = (boolean (*)()) vecin_open; mfcc->func.fv_read = (int (*)(VECT *, int)) vecin_read; mfcc->func.fv_end = (boolean (*)()) vecin_close; mfcc->func.fv_resume = (boolean (*)()) vecin_resume; mfcc->func.fv_pause = (boolean (*)()) vecin_pause; mfcc->func.fv_terminate = (boolean (*)()) vecin_terminate; mfcc->func.fv_input_name = (char * (*)()) vecin_input_name; #ifdef ENABLE_PLUGIN mfcc->plugin_source = recog->jconf->input.plugin_source; if (mfcc->plugin_source < 0) { /* no plugin, use the default functions */ return TRUE; } mfcc->func.fv_standby = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_standby"); mfcc->func.fv_begin = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_open"); mfcc->func.fv_read = (int (*)(VECT *, int)) plugin_get_func(mfcc->plugin_source, "fvin_read"); mfcc->func.fv_end = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_close"); mfcc->func.fv_resume = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_resume"); mfcc->func.fv_pause = (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_pause"); mfcc->func.fv_terminate= (boolean (*)()) plugin_get_func(mfcc->plugin_source, "fvin_terminate"); mfcc->func.fv_input_name= (char * (*)()) plugin_get_func(mfcc->plugin_source, "fvin_input_name"); if (mfcc->func.fv_read == NULL) { jlog("ERROR: FEATURE_INPUT: fvin_read() not found!\n"); return FALSE; } #endif return TRUE; }
/** * <JA> * 設定パラメータに従い音声入力デバイスをセットアップする. * * @param recog [i/o] エンジンインスタンス * * </JA> * <EN> * Set up audio input device according to the jconf configurations. * * @param recog [i/o] engine instance * </EN> * * @callgraph * @callergraph */ boolean adin_initialize(Recog *recog) { char *arg = NULL; ADIn *adin; Jconf *jconf; #ifdef ENABLE_PLUGIN FUNC_INT func; int sid; #endif adin = recog->adin; jconf = recog->jconf; jlog("STAT: ###### initialize input device\n"); /* select input device: file, mic, netaudio, etc... */ #ifdef ENABLE_PLUGIN sid = jconf->input.plugin_source; if (sid >= 0) { /* set plugin properties and functions to adin */ func = (FUNC_INT) plugin_get_func(sid, "adin_get_configuration"); if (func == NULL) { jlog("ERROR: invalid plugin: adin_get_configuration() not exist\n"); return FALSE; } adin->silence_cut_default = (*func)(1); adin->enable_thread = (*func)(2); adin->ad_standby = (boolean (*)(int, void *)) plugin_get_func(sid, "adin_standby"); adin->ad_begin = (boolean (*)(char *)) plugin_get_func(sid, "adin_open"); adin->ad_end = (boolean (*)()) plugin_get_func(sid, "adin_close"); adin->ad_resume = (boolean (*)()) plugin_get_func(sid, "adin_resume"); adin->ad_pause = (boolean (*)()) plugin_get_func(sid, "adin_pause"); adin->ad_terminate = (boolean (*)()) plugin_get_func(sid, "adin_terminate"); adin->ad_read = (int (*)(SP16 *, int)) plugin_get_func(sid, "adin_read"); adin->ad_input_name = (char * (*)()) plugin_get_func(sid, "adin_input_name"); if (adin->ad_read == NULL) { jlog("ERROR: m_adin: selected plugin has no function adin_read()\n"); return FALSE; } } else { #endif /* built-in */ if (adin_select(adin, jconf->input.speech_input, jconf->input.device) == FALSE) { jlog("ERROR: m_adin: failed to select input device\n"); return FALSE; } /* set sampling frequency and device-dependent configuration (argument is device-dependent) */ switch(jconf->input.speech_input) { case SP_ADINNET: /* arg: port number */ arg = mymalloc(100); sprintf(arg, "%d", jconf->input.adinnet_port); break; case SP_RAWFILE: /* arg: filename of file list (if any) */ if (jconf->input.inputlist_filename != NULL) { arg = mymalloc(strlen(jconf->input.inputlist_filename)+1); strcpy(arg, jconf->input.inputlist_filename); } else { arg = NULL; } break; case SP_STDIN: arg = NULL; break; #ifdef USE_NETAUDIO case SP_NETAUDIO: /* netaudio server/port name */ arg = mymalloc(strlen(jconf->input.netaudio_devname)+1); strcpy(arg, jconf->input.netaudio_devname); break; #endif } #ifdef ENABLE_PLUGIN } #endif if (adin_setup_all(adin, jconf, arg) == FALSE) { return FALSE; } if (arg != NULL) free(arg); return TRUE; }
/** * <EN> * @brief Combine all loaded models and settings into one engine instance. * * This function will finalize preparation of recognition: * * - create required MFCC calculation instances, * - create recognition process instance for specified LM/AM combination, * - set model-specific recognition parameters, * - build tree lexicon for each process instance for the 1st pass, * - prepare work area and cache area for recognition, * - initialize some values / work area for frontend processing. * * After this function, all recognition setup was done and we are ready for * start recognition. * * This should be called after j_jconf_finalize() and j_load_all() has been * completed. You should put the jconf at recog->jconf before calling this * function. * </EN> * <JA> * @brief 全てのロードされたモデルと設定からエンジンインスタンスを * 最終構成する. * * この関数は,認識準備のための最終処理を行う. 内部では, * * - 必要な MFCC 計算インスタンスの生成 * - 指定された LM/AM の組からの認識処理インスタンス生成 * - モデルに依存する認識用パラメータの設定 * - 第1パス用の木構造化辞書を認識処理インスタンスごとに構築 * - 認識処理用ワークエリアとキャッシュエリアを確保 * - フロントエンド処理のためのいくつかの値とワークエリアの確保 * * を行う. この関数が終了後,エンジンインスタンス内の全てのセットアップ * は終了し,認識が開始できる状態となる. * * この関数は,j_jconf_finalize() と j_load_all() が終わった状態で * 呼び出す必要がある. 呼出し前には,recog->jconf に (j_load_all でともに * 使用した) jconf を格納しておくこと. * * </JA> * * @param recog [in] engine instance * * @return TRUE when all initialization successfully done, or FALSE if any * error has been occured. * * @callgraph * @callergraph * @ingroup instance * */ boolean j_final_fusion(Recog *recog) { MFCCCalc *mfcc; JCONF_SEARCH *sconf; PROCESS_AM *am; jlog("STAT: ------\n"); jlog("STAT: All models are ready, go for final fusion\n"); jlog("STAT: [1] create MFCC extraction instance(s)\n"); if (recog->jconf->input.type == INPUT_WAVEFORM) { /***************************************************/ /* create MFCC calculation instance from AM config */ /* according to the fixated parameter information */ /***************************************************/ create_mfcc_calc_instances(recog); } /****************************************/ /* create recognition process instances */ /****************************************/ jlog("STAT: [2] create recognition processing instance(s) with AM and LM\n"); for(sconf=recog->jconf->search_root;sconf;sconf=sconf->next) { if (j_launch_recognition_instance(recog, sconf) == FALSE) return FALSE; } /****************************/ /****** initialize GMM ******/ /****************************/ if (recog->gmm != NULL) { jlog("STAT: [2.5] create GMM instance\n"); if (gmm_init(recog) == FALSE) { jlog("ERROR: m_fusion: error in initializing GMM\n"); return FALSE; } } /* stage 4: setup output probability function for each AM */ jlog("STAT: [3] initialize for acoustic HMM calculation\n"); for(am=recog->amlist;am;am=am->next) { #ifdef ENABLE_PLUGIN /* set plugin function if specified */ if (am->config->gprune_method == GPRUNE_SEL_USER) { am->hmmwrk.compute_gaussset = (void (*)(HMMWork *, HTK_HMM_Dens **, int, int *, int)) plugin_get_func(am->config->gprune_plugin_source, "calcmix"); if (am->hmmwrk.compute_gaussset == NULL) { jlog("ERROR: calcmix plugin has no function \"calcmix\"\n"); return FALSE; } am->hmmwrk.compute_gaussset_init = (boolean (*)(HMMWork *)) plugin_get_func(am->config->gprune_plugin_source, "calcmix_init"); if (am->hmmwrk.compute_gaussset_init == NULL) { jlog("ERROR: calcmix plugin has no function \"calcmix_init\"\n"); return FALSE; } am->hmmwrk.compute_gaussset_free = (void (*)(HMMWork *)) plugin_get_func(am->config->gprune_plugin_source, "calcmix_free"); if (am->hmmwrk.compute_gaussset_free == NULL) { jlog("ERROR: calcmix plugin has no function \"calcmix_free\"\n"); return FALSE; } } #endif if (am->config->hmm_gs_filename != NULL) {/* with GMS */ if (outprob_init(&(am->hmmwrk), am->hmminfo, am->hmm_gs, am->config->gs_statenum, am->config->gprune_method, am->config->mixnum_thres) == FALSE) { return FALSE; } } else { if (outprob_init(&(am->hmmwrk), am->hmminfo, NULL, 0, am->config->gprune_method, am->config->mixnum_thres) == FALSE) { return FALSE; } } } /* stage 5: initialize work area for input and realtime decoding */ jlog("STAT: [4] prepare MFCC storage(s)\n"); if (recog->jconf->input.type == INPUT_VECTOR) { /* create an MFCC instance for MFCC input */ /* create new mfcc instance */ recog->mfcclist = j_mfcccalc_new(NULL); recog->mfcclist->id = 1; /* assign to the am */ for(am=recog->amlist;am;am=am->next) { am->mfcc = recog->mfcclist; } if (recog->gmm) recog->gmmmfcc = recog->mfcclist; } /* allocate parameter holders */ for(mfcc=recog->mfcclist;mfcc;mfcc=mfcc->next) { mfcc->param = new_param(); } /* initialize SS calculation work area */ if (recog->jconf->input.type == INPUT_WAVEFORM) { for(mfcc=recog->mfcclist;mfcc;mfcc=mfcc->next) { if (mfcc->frontend.sscalc) { mfcc->frontend.mfccwrk_ss = WMP_work_new(mfcc->para); if (mfcc->frontend.mfccwrk_ss == NULL) { jlog("ERROR: m_fusion: failed to initialize MFCC computation for SS\n"); return FALSE; } if (mfcc->frontend.sscalc_len * recog->jconf->input.sfreq / 1000 < mfcc->para->framesize) { jlog("ERROR: m_fusion: head sil length for SS (%d msec) is shorter than a frame (%d msec)\n", mfcc->frontend.sscalc_len, mfcc->para->framesize * 1000 / recog->jconf->input.sfreq); return FALSE; } } } } if (recog->jconf->decodeopt.realtime_flag) { jlog("STAT: [5] prepare for real-time decoding\n"); /* prepare for 1st pass pipeline processing */ if (recog->jconf->input.type == INPUT_WAVEFORM) { if (RealTimeInit(recog) == FALSE) { jlog("ERROR: m_fusion: failed to initialize recognition process\n"); return FALSE; } } } /* finished! */ jlog("STAT: All init successfully done\n\n"); /* set-up callback plugin if any */ #ifdef ENABLE_PLUGIN if (plugin_exec_engine_startup(recog) == FALSE) { jlog("ERROR: m_fusion: failed to execute callback setup in plugin\n"); return FALSE; } #endif return TRUE; }