libjulius/src/jfunc.c

説明を見る。
00001 
00025 /*
00026  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00027  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00028  * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
00029  * All rights reserved
00030  */
00031 
00032 #include <julius/juliuslib.h>
00033 
00051 void
00052 j_request_pause(Recog *recog)
00053 {
00054   /* pause recognition: will stop when the current input ends */
00055   if (recog->process_active) {
00056     recog->process_want_terminate = FALSE;
00057     recog->process_want_reload = TRUE;
00058     recog->process_active = FALSE;
00059   }
00060   /* control the A/D-in module to stop recording */
00061   if (recog->jconf->input.type == INPUT_WAVEFORM) {
00062     if (recog->adin->ad_pause != NULL) {
00063       (*(recog->adin->ad_pause))();
00064     }
00065   } else {
00066     /* feature vector input */
00067     if (recog->jconf->input.speech_input == SP_MFCMODULE) {
00068       if (recog->mfcclist->func.fv_pause) recog->mfcclist->func.fv_pause();
00069     }
00070   }
00071 }
00072 
00090 void
00091 j_request_terminate(Recog *recog)
00092 {
00093   /* terminate recognition: input will terminate immidiately */
00094   /* set flags to stop adin to terminate immediately, and
00095      stop process */
00096   if (recog->process_active) {
00097     recog->process_want_terminate = TRUE;
00098     recog->process_want_reload = TRUE;
00099     recog->process_active = FALSE;
00100   }
00101   if (recog->jconf->input.type == INPUT_WAVEFORM) {
00102     if (recog->adin->ad_terminate != NULL) {
00103       /* control the A/D-in module to terminate recording imemdiately */
00104       (*(recog->adin->ad_terminate))();
00105     }
00106   } else {
00107     /* feature vector input */
00108     if (recog->jconf->input.speech_input == SP_MFCMODULE) {
00109       if (recog->mfcclist->func.fv_terminate) recog->mfcclist->func.fv_terminate();
00110     }
00111   }
00112 }
00113 
00128 void 
00129 j_request_resume(Recog *recog)
00130 {
00131   if (recog->process_active == FALSE) {
00132     recog->process_want_terminate = FALSE;
00133     recog->process_active = TRUE;
00134   }
00135   /* control the A/D-in module to restart recording now */
00136   if (recog->jconf->input.type == INPUT_WAVEFORM) {
00137     if (recog->adin->ad_resume != NULL) {
00138       (*(recog->adin->ad_resume))();
00139     }
00140   } else {
00141     /* feature vector input */
00142     if (recog->jconf->input.speech_input == SP_MFCMODULE) {
00143       if (recog->mfcclist->func.fv_resume) recog->mfcclist->func.fv_resume();
00144     }
00145   }
00146 }
00147 
00169 void
00170 schedule_grammar_update(Recog *recog)
00171 {
00172   if (recog->process_active) {
00173     /* if recognition is currently running, tell engine how/when to
00174        re-construct global lexicon. */
00175     switch(recog->gram_switch_input_method) {
00176     case SM_TERMINATE:  /* discard input now and change (immediate) */
00177       recog->process_want_terminate = TRUE;
00178       recog->process_want_reload = TRUE;
00179       break;
00180     case SM_PAUSE:              /* segment input now, recognize it, and then change */
00181       recog->process_want_terminate = FALSE;
00182       recog->process_want_reload = TRUE;
00183       break;
00184     case SM_WAIT:               /* wait until the current input end and recognition completed */
00185       recog->process_want_terminate = FALSE;
00186       recog->process_want_reload = FALSE;
00187       break;
00188     }
00189     /* After the update, recognition will restart without sleeping. */
00190   } else {
00191     /* If recognition is currently not running, the received
00192        grammars are merely stored in memory here.  The re-construction of
00193        global lexicon will be delayed: it will be re-built just before
00194        the recognition process starts next time. */
00195   }
00196 }
00197 
00214 void
00215 j_reset_reload(Recog *recog)
00216 {
00217   recog->process_want_reload = FALSE;
00218 }
00219 
00231 void
00232 j_enable_debug_message()
00233 {
00234   debug2_flag = TRUE;
00235 }
00236 
00249 void
00250 j_disable_debug_message()
00251 {
00252   debug2_flag = FALSE;
00253 }
00254 
00267 void
00268 j_enable_verbose_message()
00269 {
00270   verbose_flag = TRUE;
00271 }
00272 
00285 void
00286 j_disable_verbose_message()
00287 {
00288   verbose_flag = FALSE;
00289 }
00290               
00291 
00300 void
00301 j_internal_error(char *fmt, ...)
00302 {
00303   va_list ap;
00304   int ret;
00305 
00306   va_start(ap,fmt);
00307   ret = vfprintf(stderr, fmt, ap);
00308   va_end(ap);
00309 
00310   /* clean up socket if already opened */
00311   cleanup_socket();
00312 
00313   exit(1);
00314 }
00315 
00336 int
00337 j_config_load_args(Jconf *jconf, int argc, char *argv[])
00338 {
00339   JCONF_AM *am;
00340   JCONF_LM *lm;
00341   JCONF_SEARCH *s;
00342 
00343   /* parse options and set variables */
00344   if (opt_parse(argc, argv, NULL, jconf) == FALSE) {
00345     return -1;
00346   }
00347   /* if multiple instances defined from init, remove initial one (id=0) */
00348   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00349     am = jconf->am_root->next;
00350     free(jconf->am_root);
00351     jconf->am_root = am;
00352   }
00353   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00354     lm = jconf->lm_root->next;
00355     free(jconf->lm_root);
00356     jconf->lm_root = lm;
00357   }
00358   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00359     s = jconf->search_root->next;
00360     free(jconf->search_root);
00361     jconf->search_root = s;
00362   }
00363   return 0;
00364 }
00365 
00385 int
00386 j_config_load_file(Jconf *jconf, char *filename)
00387 {
00388   JCONF_AM *am;
00389   JCONF_LM *lm;
00390   JCONF_SEARCH *s;
00391 
00392   /* parse options and set variables */
00393   if (config_file_parse(filename, jconf) == FALSE) {
00394     return -1;
00395   }
00396   /* if multiple instances defined from init, remove initial one (id=0) */
00397   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00398     am = jconf->am_root->next;
00399     free(jconf->am_root);
00400     jconf->am_root = am;
00401   }
00402   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00403     lm = jconf->lm_root->next;
00404     free(jconf->lm_root);
00405     jconf->lm_root = lm;
00406   }
00407   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00408     s = jconf->search_root->next;
00409     free(jconf->search_root);
00410     jconf->search_root = s;
00411   }
00412   return 0;
00413 }
00414 
00434 Jconf *
00435 j_config_load_args_new(int argc, char *argv[])
00436 {
00437   Jconf *jconf;
00438   JCONF_AM *am;
00439   JCONF_LM *lm;
00440   JCONF_SEARCH *s;
00441 
00442   jconf = j_jconf_new();
00443   /* parse options and set variables */
00444   if (opt_parse(argc, argv, NULL, jconf) == FALSE) {
00445     j_jconf_free(jconf);
00446     return NULL;
00447   }
00448   /* if multiple instances defined from init, remove initial one (id=0) */
00449   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00450     am = jconf->am_root->next;
00451     free(jconf->am_root);
00452     jconf->am_root = am;
00453   }
00454   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00455     lm = jconf->lm_root->next;
00456     free(jconf->lm_root);
00457     jconf->lm_root = lm;
00458   }
00459   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00460     s = jconf->search_root->next;
00461     free(jconf->search_root);
00462     jconf->search_root = s;
00463   }
00464   return jconf;
00465 }
00466 
00485 Jconf *
00486 j_config_load_file_new(char *filename)
00487 {
00488   Jconf *jconf;
00489   JCONF_AM *am;
00490   JCONF_LM *lm;
00491   JCONF_SEARCH *s;
00492 
00493   jconf = j_jconf_new();
00494   /* parse options and set variables */
00495   if (config_file_parse(filename, jconf) == FALSE) {
00496     j_jconf_free(jconf);
00497     return NULL;
00498   }
00499   /* if multiple instances defined from init, remove initial one (id=0) */
00500   if(jconf->am_root->next != NULL && jconf->am_root->id == 0) {
00501     am = jconf->am_root->next;
00502     free(jconf->am_root);
00503     jconf->am_root = am;
00504   }
00505   if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) {
00506     lm = jconf->lm_root->next;
00507     free(jconf->lm_root);
00508     jconf->lm_root = lm;
00509   }
00510   if(jconf->search_root->next != NULL && jconf->search_root->id == 0) {
00511     s = jconf->search_root->next;
00512     free(jconf->search_root);
00513     jconf->search_root = s;
00514   }
00515   return jconf;
00516 }
00517 
00538 boolean
00539 j_adin_init(Recog *recog)
00540 {
00541   boolean ret;
00542 
00543   if (recog->jconf->input.type == INPUT_VECTOR) {
00544     /* feature vector input */
00545     if (recog->jconf->input.speech_input == SP_MFCMODULE) {
00546       if (mfc_module_init(recog->mfcclist, recog) == FALSE) {
00547         return FALSE;
00548       }
00549       ret = mfc_module_standby(recog->mfcclist);
00550     } else {
00551       ret = TRUE;
00552     }
00553     return ret;
00554   }
00555   
00556   /* initialize A/D-in device */
00557   ret = adin_initialize(recog);
00558 
00559   return(ret);
00560 }
00561 
00578 char *
00579 j_get_current_filename()
00580 {
00581 #ifdef HAVE_LIBSNDFILE
00582   return(adin_sndfile_get_current_filename());
00583 #else
00584   return(adin_file_get_current_filename());
00585 #endif
00586 }
00587 
00588 
00603 void
00604 j_recog_info(Recog *recog)
00605 {
00606   /* print out system information */
00607   print_engine_info(recog);
00608 }
00609 
00638 Recog *
00639 j_create_instance_from_jconf(Jconf *jconf)
00640 {
00641   Recog *recog;
00642 
00643   /* check option values and set parameters needed for model loading */
00644   if (j_jconf_finalize(jconf) == FALSE) {
00645     return NULL;
00646   }
00647 
00648   /* create a recognition instance */
00649   recog = j_recog_new();
00650 
00651   /* assign configuration to the instance */
00652   recog->jconf = jconf;
00653 
00654   /* load all files according to the configurations */
00655   if (j_load_all(recog, jconf) == FALSE) {
00656     jlog("ERROR: j_create_instance_from_jconf: error in loading model\n");
00657     /* j_model_free(model); */
00658     return NULL;
00659   }
00660 
00661   /* checkout for recognition: build lexicon tree, allocate cache */
00662   if (j_final_fusion(recog) == FALSE) {
00663     jlog("ERROR: j_create_instance_from_jconf: error while setup for recognition\n");
00664     j_recog_free(recog);
00665     return NULL;
00666   }
00667 
00668   return recog;
00669 }
00670 
00696 boolean
00697 j_regist_user_lm_func(PROCESS_LM *lm, 
00698           LOGPROB (*unifunc)(WORD_INFO *winfo, WORD_ID w, LOGPROB ngram_prob), 
00699           LOGPROB (*bifunc)(WORD_INFO *winfo, WORD_ID context, WORD_ID w, LOGPROB ngram_prob),
00700           LOGPROB (*probfunc)(WORD_INFO *winfo, WORD_ID *contexts, int context_len, WORD_ID w, LOGPROB ngram_prob))
00701 {
00702   lm->lmfunc.uniprob = unifunc;
00703   lm->lmfunc.biprob = bifunc;
00704   lm->lmfunc.lmprob = probfunc;
00705   return TRUE;
00706 }
00707 
00725 boolean
00726 j_regist_user_param_func(Recog *recog, boolean (*user_calc_vector)(MFCCCalc *, SP16 *, int))
00727 {
00728   recog->calc_vector = user_calc_vector;
00729   return TRUE;
00730 }
00731 
00732 
00750 JCONF_AM *
00751 j_get_amconf_by_name(Jconf *jconf, char *name)
00752 {
00753   JCONF_AM *amconf;
00754 
00755   for(amconf=jconf->am_root;amconf;amconf=amconf->next) {
00756     if (strmatch(amconf->name, name)) {
00757       break;
00758     }
00759   }
00760   if (!amconf) {                /* error */
00761     jlog("ERROR: j_get_amconf_by_name: [AM \"%s\"] not found\n", name);
00762     return NULL;
00763   }
00764   return amconf;
00765 }
00766 
00784 JCONF_AM *
00785 j_get_amconf_by_id(Jconf *jconf, int id)
00786 {
00787   JCONF_AM *amconf;
00788 
00789   for(amconf=jconf->am_root;amconf;amconf=amconf->next) {
00790     if (amconf->id == id) {
00791       break;
00792     }
00793   }
00794   if (!amconf) {                /* error */
00795     jlog("ERROR: j_get_amconf_by_id: [AM%02d] not found\n", id);
00796     return NULL;
00797   }
00798   return amconf;
00799 }
00800 
00821 JCONF_AM *
00822 j_get_amconf_default(Jconf *jconf)
00823 {
00824   JCONF_AM *amconf;
00825 
00826   if (jconf->am_root == NULL) return NULL;
00827   for(amconf=jconf->am_root;amconf->next;amconf=amconf->next);
00828   return(amconf);
00829 }
00830 
00848 JCONF_LM *
00849 j_get_lmconf_by_name(Jconf *jconf, char *name)
00850 {
00851   JCONF_LM *lmconf;
00852 
00853   for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) {
00854     if (strmatch(lmconf->name, name)) {
00855       break;
00856     }
00857   }
00858   if (!lmconf) {                /* error */
00859     jlog("ERROR: j_get_lmconf_by_name: [LM \"%s\"] not found\n", name);
00860     return NULL;
00861   }
00862   return lmconf;
00863 }
00864 
00882 JCONF_LM *
00883 j_get_lmconf_by_id(Jconf *jconf, int id)
00884 {
00885   JCONF_LM *lmconf;
00886 
00887   for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) {
00888     if (lmconf->id == id) {
00889       break;
00890     }
00891   }
00892   if (!lmconf) {                /* error */
00893     jlog("ERROR: j_get_lmconf_by_id: [LM%02d] not found\n", id);
00894     return NULL;
00895   }
00896   return lmconf;
00897 }
00898 
00916 JCONF_SEARCH *
00917 j_get_searchconf_by_name(Jconf *jconf, char *name)
00918 {
00919   JCONF_SEARCH *sconf;
00920 
00921   for(sconf=jconf->search_root;sconf;sconf=sconf->next) {
00922     if (strmatch(sconf->name, name)) {
00923       break;
00924     }
00925   }
00926   if (!sconf) {         /* error */
00927     jlog("ERROR: j_get_searchconf_by_name: [SR \"%s\"] not found\n", name);
00928     return NULL;
00929   }
00930   return sconf;
00931 }
00932 
00950 JCONF_SEARCH *
00951 j_get_searchconf_by_id(Jconf *jconf, int id)
00952 {
00953   JCONF_SEARCH *sconf;
00954 
00955   for(sconf=jconf->search_root;sconf;sconf=sconf->next) {
00956     if (sconf->id == id) {
00957       break;
00958     }
00959   }
00960   if (!sconf) {         /* error */
00961     jlog("ERROR: j_get_searchconf_by_id: [SR%02d] not found\n", id);
00962     return NULL;
00963   }
00964   return sconf;
00965 }
00966 
00987 boolean
00988 j_process_deactivate(Recog *recog, char *name)
00989 {
00990   RecogProcess *r;
00991 
00992   for(r=recog->process_list;r;r=r->next) {
00993     if (strmatch(r->config->name, name)) {
00994       /* book to be inactive at next interval */
00995       r->active = -1;
00996       break;
00997     }
00998   }
00999   if (!r) {                     /* not found */
01000     jlog("ERROR: j_process_deactivate: no SR instance named \"%s\", cannot deactivate\n", name);
01001     return FALSE;
01002   }
01003 
01004   /* tell engine to update */
01005   recog->process_want_reload = TRUE;
01006 
01007   return TRUE;
01008 }
01009 
01031 boolean
01032 j_process_deactivate_by_id(Recog *recog, int id)
01033 {
01034   RecogProcess *r;
01035 
01036   for(r=recog->process_list;r;r=r->next) {
01037     if (r->config->id == id) {
01038       /* book to be inactive at next interval */
01039       r->active = -1;
01040       break;
01041     }
01042   }
01043   if (!r) {                     /* not found */
01044     jlog("ERROR: j_process_deactivate_by_id: no SR instance whose id is \"%02d\", cannot deactivate\n", id);
01045     return FALSE;
01046   }
01047 
01048   /* tell engine to update */
01049   recog->process_want_reload = TRUE;
01050 
01051   return TRUE;
01052 }
01053 
01075 boolean
01076 j_process_activate(Recog *recog, char *name)
01077 {
01078   RecogProcess *r;
01079 
01080   for(r=recog->process_list;r;r=r->next) {
01081     if (strmatch(r->config->name, name)) {
01082       /* book to be active at next interval */
01083       r->active = 1;
01084       break;
01085     }
01086   }
01087   if (!r) {                     /* not found */
01088     jlog("ERROR: j_process_activate: no SR instance named \"%s\", cannot activate\n", name);
01089     return FALSE;
01090   }
01091 
01092   /* tell engine to update */
01093   recog->process_want_reload = TRUE;
01094 
01095   return TRUE;
01096 }
01097 
01119 boolean
01120 j_process_activate_by_id(Recog *recog, int id)
01121 {
01122   RecogProcess *r;
01123 
01124   for(r=recog->process_list;r;r=r->next) {
01125     if (r->config->id == id) {
01126       /* book to be active at next interval */
01127       r->active = 1;
01128       break;
01129     }
01130   }
01131   if (!r) {                     /* not found */
01132     jlog("ERROR: j_process_activate_by_id: no SR instance whose id is \"%02d\", cannot activate\n", id);
01133     return FALSE;
01134   }
01135 
01136   /* tell engine to update */
01137   recog->process_want_reload = TRUE;
01138 
01139   return TRUE;
01140 }
01141 
01172 boolean
01173 j_process_add_lm(Recog *recog, JCONF_LM *lmconf, JCONF_SEARCH *sconf, char *name)
01174 {
01175   /* add lmconf to global config */
01176   if (j_jconf_lm_regist(recog->jconf, lmconf, name) == FALSE) {
01177     jlog("ERROR: j_process_add_lm: failed to regist new LM conf as \"%s\"\n", name);
01178     return FALSE;
01179   }
01180   /* assign lmconf and default amconf to the sconf */
01181   sconf->amconf = j_get_amconf_default(recog->jconf);
01182   sconf->lmconf = lmconf;
01183   /* add the sconf to global config */
01184   if (j_jconf_search_regist(recog->jconf, sconf, name) == FALSE) {
01185     jlog("ERROR: j_process_add_lm: failed to regist new SR conf as \"%s\"\n", name);
01186     j_jconf_search_free(sconf);
01187     return FALSE;
01188   }
01189   /* finalize the whole parameters */
01190   if (j_jconf_finalize(recog->jconf) == FALSE) {
01191     jlog("ERROR: j_process_add_lm: failed to finalize the updated whole jconf\n");
01192     return FALSE;
01193   }
01194   /* create LM process intance for the lmconf, and load LM */
01195   if (j_load_lm(recog, lmconf) == FALSE) {
01196     jlog("ERROR: j_process_add_lm: failed to load LM \"%s\"\n", lmconf->name);
01197     return FALSE;
01198   }
01199   /* create recognition process instance for the sconf, and setup for recognition */
01200   if (j_launch_recognition_instance(recog, sconf) == FALSE) {
01201     jlog("ERROR: j_process_add_lm: failed to start a new recognizer instance \"%s\"\n", sconf->name);
01202     return FALSE;
01203   }
01204   /* the created process will be live=FALSE, active = 1, so
01205      the new recognition instance is dead now but
01206      will be made live at next session */
01207 
01208   /* tell engine to update */
01209   recog->process_want_reload = TRUE;
01210 
01211   return TRUE;
01212 }
01213 
01235 boolean
01236 j_process_remove(Recog *recog, JCONF_SEARCH *sconf)
01237 {
01238   RecogProcess *r, *r_prev;
01239   JCONF_SEARCH *sc, *sc_prev;
01240 
01241   if (sconf == NULL) {
01242     jlog("ERROR: j_process_remove: sconf == NULL\n");
01243     return FALSE;
01244   }
01245 
01246   /* find corresponding process in engine and remove it from list */
01247   r_prev = NULL;
01248   for(r=recog->process_list;r;r=r->next) {
01249     if (r->config == sconf) {
01250       if (r_prev == NULL) {
01251         recog->process_list = r->next;
01252       } else {
01253         r_prev->next = r->next;
01254       }
01255       break;
01256     }
01257     r_prev = r;
01258   }
01259   if (!r) {
01260     jlog("ERROR: j_process_remove: specified sconf %02d %s not found in recogprocess, removal failed\n", sconf->id, sconf->name);
01261     return FALSE;
01262   }
01263 
01264   /* remove config from list in engine */
01265   sc_prev = NULL;
01266   for(sc=recog->jconf->search_root;sc;sc=sc->next) {
01267     if (sc == sconf) {
01268       if (sc_prev == NULL) {
01269         recog->jconf->search_root = sc->next;
01270       } else {
01271         sc_prev->next = sc->next;
01272       }
01273       break;
01274     }
01275     sc_prev = sc;
01276   }
01277   if (!sc) {
01278     jlog("ERROR: j_process_remove: sconf %02d %s not found\n", sconf->id, sconf->name);
01279   }
01280 
01281   /* free them */
01282   j_recogprocess_free(r);
01283   if (verbose_flag) jlog("STAT: recogprocess %02d %s removed\n", sconf->id, sconf->name);
01284   j_jconf_search_free(sconf);
01285 
01286   /* tell engine to update */
01287   recog->process_want_reload = TRUE;
01288 
01289   return TRUE;
01290 }
01291 
01313 boolean
01314 j_process_lm_remove(Recog *recog, JCONF_LM *lmconf)
01315 {
01316   RecogProcess *r;
01317   PROCESS_LM *lm, *lm_prev;
01318   JCONF_LM *l, *l_prev;
01319 
01320   if (lmconf == NULL) {
01321     jlog("ERROR: j_process_lm_remove: lmconf == NULL\n");
01322     return FALSE;
01323   }
01324 
01325   /* check if still used by a process */
01326   for(r=recog->process_list;r;r=r->next) {
01327     if (r->config->lmconf == lmconf) {
01328       jlog("ERROR: j_process_lm_remove: specified lmconf %02d %s still used in a recogprocess %02d %s\n", lmconf->id, lmconf->name, r->config->id, r->config->name);
01329       return FALSE;
01330     }
01331   }
01332 
01333   /* find corresponding LM process in engine and remove it from list */
01334   lm_prev = NULL;
01335   for(lm=recog->lmlist;lm;lm=lm->next) {
01336     if (lm->config == lmconf) {
01337       if (lm_prev == NULL) {
01338         recog->lmlist = lm->next;
01339       } else {
01340         lm_prev->next = lm->next;
01341       }
01342       break;
01343     }
01344     lm_prev = lm;
01345   }
01346   if (!lm) {
01347     jlog("ERROR: j_process_lm_remove: specified lmconf %02d %s not found in LM process, removal failed\n", lmconf->id, lmconf->name);
01348     return FALSE;
01349   }
01350 
01351   /* remove config from list in engine */
01352   l_prev = NULL;
01353   for(l=recog->jconf->lm_root;l;l=l->next) {
01354     if (l == lmconf) {
01355       if (l_prev == NULL) {
01356         recog->jconf->lm_root = l->next;
01357       } else {
01358         l_prev->next = l->next;
01359       }
01360       break;
01361     }
01362     l_prev = l;
01363   }
01364   if (!l) {
01365     jlog("ERROR: j_process_lm_remove: lmconf %02d %s not found\n", lmconf->id, lmconf->name);
01366     return FALSE;
01367   }
01368 
01369   /* free them */
01370   j_process_lm_free(lm);
01371   if (verbose_flag) jlog("STAT: LM process %02d %s removed\n", lmconf->id, lmconf->name);
01372   j_jconf_lm_free(lmconf);
01373 
01374   /* tell engine to update */
01375   recog->process_want_reload = TRUE;
01376 
01377   return TRUE;
01378 }
01379 
01401 boolean
01402 j_process_am_remove(Recog *recog, JCONF_AM *amconf)
01403 {
01404   RecogProcess *r;
01405   PROCESS_LM *lm;
01406   PROCESS_AM *am, *am_prev;
01407   JCONF_AM *a, *a_prev;
01408 
01409   if (amconf == NULL) {
01410     jlog("ERROR: j_process_am_remove: amconf == NULL\n");
01411     return FALSE;
01412   }
01413 
01414   /* check if still used by a process */
01415   for(r=recog->process_list;r;r=r->next) {
01416     if (r->config->amconf == amconf) {
01417       jlog("ERROR: j_process_am_remove: specified amconf %02d %s still used in a recogprocess %02d %s\n", amconf->id, amconf->name, r->config->id, r->config->name);
01418       return FALSE;
01419     }
01420   }
01421 
01422   /* check if still used by a LM process */
01423   for(lm=recog->lmlist;lm;lm=lm->next) {
01424     if (lm->am->config == amconf) {
01425       jlog("ERROR: j_process_am_remove: specified amconf %02d %s still used in a LM %02d %s\n", amconf->id, amconf->name, lm->config->id, lm->config->name);
01426       return FALSE;
01427     }
01428   }
01429 
01430   /* find corresponding AM process in engine and remove it from list */
01431   am_prev = NULL;
01432   for(am=recog->amlist;am;am=am->next) {
01433     if (am->config == amconf) {
01434       if (am_prev == NULL) {
01435         recog->amlist = am->next;
01436       } else {
01437         am_prev->next = am->next;
01438       }
01439       break;
01440     }
01441     am_prev = am;
01442   }
01443   if (!am) {
01444     jlog("ERROR: j_process_am_remove: specified amconf %02d %s not found in AM process, removal failed\n", amconf->id, amconf->name);
01445     return FALSE;
01446   }
01447 
01448   /* remove config from list in engine */
01449   a_prev = NULL;
01450   for(a=recog->jconf->am_root;a;a=a->next) {
01451     if (a == amconf) {
01452       if (a_prev == NULL) {
01453         recog->jconf->am_root = a->next;
01454       } else {
01455         a_prev->next = a->next;
01456       }
01457       break;
01458     }
01459     a_prev = a;
01460   }
01461   if (!a) {
01462     jlog("ERROR: j_process_am_remove: amconf %02d %s not found\n", amconf->id, amconf->name);
01463     return FALSE;
01464   }
01465 
01466   /* free them */
01467   j_process_am_free(am);
01468   if (verbose_flag) jlog("STAT: AM process %02d %s removed\n", amconf->id, amconf->name);
01469   j_jconf_am_free(amconf);
01470 
01471   /* tell engine to update */
01472   recog->process_want_reload = TRUE;
01473 
01474   return TRUE;
01475 }
01476 
01477 #ifdef DEBUG_VTLN_ALPHA_TEST
01478 void
01479 vtln_alpha(Recog *recog, RecogProcess *r)
01480 {
01481   Sentence *s;
01482   float alpha, alpha_bgn, alpha_end;
01483   float max_alpha;
01484   LOGPROB max_score;
01485   PROCESS_AM *am;
01486   MFCCCalc *mfcc;
01487   SentenceAlign *align;
01488 
01489   s = &(r->result.sent[0]);
01490   align = result_align_new();
01491 
01492   max_score = LOG_ZERO;
01493 
01494   printf("------------ begin VTLN -------------\n");
01495 
01496   mfcc = r->am->mfcc;
01497 
01498   alpha_bgn = mfcc->para->vtln_alpha - VTLN_RANGE;
01499   alpha_end = mfcc->para->vtln_alpha + VTLN_RANGE;
01500 
01501   for(alpha = alpha_bgn; alpha <= alpha_end; alpha += VTLN_STEP) {
01502     mfcc->para->vtln_alpha = alpha;
01503     if (InitFBank(mfcc->wrk, mfcc->para) == FALSE) {
01504       jlog("ERROR: VTLN: InitFBank() failed\n");
01505       return;
01506     }
01507     if (wav2mfcc(recog->speech, recog->speechlen, recog) == FALSE) {
01508       jlog("ERROR: VTLN: wav2mfcc() failed\n");
01509       return;
01510     }
01511     outprob_prepare(&(r->am->hmmwrk), mfcc->param->samplenum);
01512     word_align(s->word, s->word_num, mfcc->param, align, r);
01513     printf("%f: %f\n", alpha, align->allscore);
01514     if (max_score < align->allscore) {
01515       max_score = align->allscore;
01516       max_alpha = alpha;
01517     }
01518   }
01519   printf("MAX: %f: %f\n", max_alpha, max_score);
01520   mfcc->para->vtln_alpha = max_alpha;
01521   if (InitFBank(mfcc->wrk, mfcc->para) == FALSE) {
01522     jlog("ERROR: VTLN: InitFBank() failed\n");
01523     return;
01524   }
01525 
01526   printf("------------ end VTLN -------------\n");
01527 
01528   result_align_free(align);
01529 
01530 }
01531 #endif
01532 
01533 
01534 /* end of file */

Juliusに対してThu Jul 23 12:16:22 2009に生成されました。  doxygen 1.5.1