Julius 4.2
|
00001 00025 /* 00026 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00027 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00028 * Copyright (c) 2005-2011 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 00331 static void 00332 j_config_remove_initial(Jconf *jconf) 00333 { 00334 JCONF_AM *am; 00335 JCONF_LM *lm; 00336 JCONF_SEARCH *s; 00337 00338 if(jconf->am_root->next != NULL && jconf->am_root->id == 0) { 00339 am = jconf->am_root->next; 00340 free(jconf->am_root); 00341 jconf->am_root = am; 00342 } 00343 if(jconf->lm_root->next != NULL && jconf->lm_root->id == 0) { 00344 lm = jconf->lm_root->next; 00345 free(jconf->lm_root); 00346 jconf->lm_root = lm; 00347 } 00348 if(jconf->search_root->next != NULL && jconf->search_root->id == 0) { 00349 s = jconf->search_root->next; 00350 free(jconf->search_root); 00351 jconf->search_root = s; 00352 } 00353 } 00354 00375 int 00376 j_config_load_args(Jconf *jconf, int argc, char *argv[]) 00377 { 00378 /* parse options and set variables */ 00379 if (opt_parse(argc, argv, NULL, jconf) == FALSE) { 00380 return -1; 00381 } 00382 /* if multiple instances defined from init, remove initial one (id=0) */ 00383 j_config_remove_initial(jconf); 00384 00385 return 0; 00386 } 00387 00407 int 00408 j_config_load_string(Jconf *jconf, char *string) 00409 { 00410 int argc; 00411 char **argv; 00412 char *buf; 00413 00414 /* parse options and set variables */ 00415 if (config_string_parse(string, jconf) == FALSE) { 00416 return -1; 00417 } 00418 /* if multiple instances defined from init, remove initial one (id=0) */ 00419 j_config_remove_initial(jconf); 00420 00421 return 0; 00422 } 00423 00443 int 00444 j_config_load_file(Jconf *jconf, char *filename) 00445 { 00446 /* parse options and set variables */ 00447 if (config_file_parse(filename, jconf) == FALSE) { 00448 return -1; 00449 } 00450 /* if multiple instances defined from init, remove initial one (id=0) */ 00451 j_config_remove_initial(jconf); 00452 00453 return 0; 00454 } 00455 00475 Jconf * 00476 j_config_load_args_new(int argc, char *argv[]) 00477 { 00478 Jconf *jconf; 00479 jconf = j_jconf_new(); 00480 if (j_config_load_args(jconf, argc, argv) == -1) { 00481 j_jconf_free(jconf); 00482 return NULL; 00483 } 00484 return jconf; 00485 } 00486 00505 Jconf * 00506 j_config_load_file_new(char *filename) 00507 { 00508 Jconf *jconf; 00509 jconf = j_jconf_new(); 00510 if (j_config_load_file(jconf, filename) == -1) { 00511 j_jconf_free(jconf); 00512 return NULL; 00513 } 00514 return jconf; 00515 } 00516 00535 Jconf * 00536 j_config_load_string_new(char *string) 00537 { 00538 Jconf *jconf; 00539 jconf = j_jconf_new(); 00540 if (j_config_load_string(jconf, string) == -1) { 00541 j_jconf_free(jconf); 00542 return NULL; 00543 } 00544 return jconf; 00545 } 00546 00568 void 00569 j_add_dict(JCONF_LM *lm, char *dictfile) 00570 { 00571 JCONF_LM_NAMELIST *nl; 00572 nl = (JCONF_LM_NAMELIST *)mymalloc(sizeof(JCONF_LM_NAMELIST)); 00573 nl->name = (char *)mymalloc(strlen(dictfile) + 1); 00574 strcpy(nl->name, dictfile); 00575 nl->next = lm->additional_dict_files; 00576 lm->additional_dict_files = nl; 00577 } 00578 00598 void 00599 j_add_word(JCONF_LM *lm, char *wordentry) 00600 { 00601 JCONF_LM_NAMELIST *nl; 00602 nl = (JCONF_LM_NAMELIST *)mymalloc(sizeof(JCONF_LM_NAMELIST)); 00603 nl->name = (char *)mymalloc(strlen(wordentry) + 1); 00604 strcpy(nl->name, wordentry); 00605 nl->next = lm->additional_dict_entries; 00606 lm->additional_dict_entries = nl; 00607 } 00608 00629 boolean 00630 j_adin_init(Recog *recog) 00631 { 00632 boolean ret; 00633 00634 if (recog->jconf->input.type == INPUT_VECTOR) { 00635 /* feature vector input */ 00636 if (recog->jconf->input.speech_input == SP_MFCMODULE) { 00637 if (mfc_module_init(recog->mfcclist, recog) == FALSE) { 00638 return FALSE; 00639 } 00640 ret = mfc_module_standby(recog->mfcclist); 00641 } else { 00642 ret = TRUE; 00643 } 00644 return ret; 00645 } 00646 00647 /* initialize A/D-in device */ 00648 ret = adin_initialize(recog); 00649 00650 return(ret); 00651 } 00652 00672 char * 00673 j_get_current_filename(Recog *recog) 00674 { 00675 char *p; 00676 p = NULL; 00677 if (recog->jconf->input.type == INPUT_WAVEFORM) { 00678 /* adin function input */ 00679 if (recog->adin->ad_input_name != NULL) { 00680 p = recog->adin->ad_input_name(); 00681 } 00682 } else { 00683 switch(recog->jconf->input.speech_input) { 00684 case SP_MFCMODULE: 00685 p = mfc_module_input_name(recog->mfcclist); 00686 break; 00687 case SP_MFCFILE: 00688 /* already assigned */ 00689 p = recog->adin->current_input_name; 00690 break; 00691 } 00692 } 00693 return p; 00694 } 00695 00696 00711 void 00712 j_recog_info(Recog *recog) 00713 { 00714 /* print out system information */ 00715 print_engine_info(recog); 00716 } 00717 00746 Recog * 00747 j_create_instance_from_jconf(Jconf *jconf) 00748 { 00749 Recog *recog; 00750 00751 /* check option values and set parameters needed for model loading */ 00752 if (j_jconf_finalize(jconf) == FALSE) { 00753 return NULL; 00754 } 00755 00756 /* create a recognition instance */ 00757 recog = j_recog_new(); 00758 00759 /* assign configuration to the instance */ 00760 recog->jconf = jconf; 00761 00762 /* load all files according to the configurations */ 00763 if (j_load_all(recog, jconf) == FALSE) { 00764 jlog("ERROR: j_create_instance_from_jconf: error in loading model\n"); 00765 /* j_model_free(model); */ 00766 return NULL; 00767 } 00768 00769 /* checkout for recognition: build lexicon tree, allocate cache */ 00770 if (j_final_fusion(recog) == FALSE) { 00771 jlog("ERROR: j_create_instance_from_jconf: error while setup for recognition\n"); 00772 j_recog_free(recog); 00773 return NULL; 00774 } 00775 00776 return recog; 00777 } 00778 00804 boolean 00805 j_regist_user_lm_func(PROCESS_LM *lm, 00806 LOGPROB (*unifunc)(WORD_INFO *winfo, WORD_ID w, LOGPROB ngram_prob), 00807 LOGPROB (*bifunc)(WORD_INFO *winfo, WORD_ID context, WORD_ID w, LOGPROB ngram_prob), 00808 LOGPROB (*probfunc)(WORD_INFO *winfo, WORD_ID *contexts, int context_len, WORD_ID w, LOGPROB ngram_prob)) 00809 { 00810 lm->lmfunc.uniprob = unifunc; 00811 lm->lmfunc.biprob = bifunc; 00812 lm->lmfunc.lmprob = probfunc; 00813 return TRUE; 00814 } 00815 00833 boolean 00834 j_regist_user_param_func(Recog *recog, boolean (*user_calc_vector)(MFCCCalc *, SP16 *, int)) 00835 { 00836 recog->calc_vector = user_calc_vector; 00837 return TRUE; 00838 } 00839 00840 00858 JCONF_AM * 00859 j_get_amconf_by_name(Jconf *jconf, char *name) 00860 { 00861 JCONF_AM *amconf; 00862 00863 for(amconf=jconf->am_root;amconf;amconf=amconf->next) { 00864 if (strmatch(amconf->name, name)) { 00865 break; 00866 } 00867 } 00868 if (!amconf) { /* error */ 00869 jlog("ERROR: j_get_amconf_by_name: [AM \"%s\"] not found\n", name); 00870 return NULL; 00871 } 00872 return amconf; 00873 } 00874 00892 JCONF_AM * 00893 j_get_amconf_by_id(Jconf *jconf, int id) 00894 { 00895 JCONF_AM *amconf; 00896 00897 for(amconf=jconf->am_root;amconf;amconf=amconf->next) { 00898 if (amconf->id == id) { 00899 break; 00900 } 00901 } 00902 if (!amconf) { /* error */ 00903 jlog("ERROR: j_get_amconf_by_id: [AM%02d] not found\n", id); 00904 return NULL; 00905 } 00906 return amconf; 00907 } 00908 00929 JCONF_AM * 00930 j_get_amconf_default(Jconf *jconf) 00931 { 00932 JCONF_AM *amconf; 00933 00934 if (jconf->am_root == NULL) return NULL; 00935 for(amconf=jconf->am_root;amconf->next;amconf=amconf->next); 00936 return(amconf); 00937 } 00938 00956 JCONF_LM * 00957 j_get_lmconf_by_name(Jconf *jconf, char *name) 00958 { 00959 JCONF_LM *lmconf; 00960 00961 for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) { 00962 if (strmatch(lmconf->name, name)) { 00963 break; 00964 } 00965 } 00966 if (!lmconf) { /* error */ 00967 jlog("ERROR: j_get_lmconf_by_name: [LM \"%s\"] not found\n", name); 00968 return NULL; 00969 } 00970 return lmconf; 00971 } 00972 00990 JCONF_LM * 00991 j_get_lmconf_by_id(Jconf *jconf, int id) 00992 { 00993 JCONF_LM *lmconf; 00994 00995 for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) { 00996 if (lmconf->id == id) { 00997 break; 00998 } 00999 } 01000 if (!lmconf) { /* error */ 01001 jlog("ERROR: j_get_lmconf_by_id: [LM%02d] not found\n", id); 01002 return NULL; 01003 } 01004 return lmconf; 01005 } 01006 01024 JCONF_SEARCH * 01025 j_get_searchconf_by_name(Jconf *jconf, char *name) 01026 { 01027 JCONF_SEARCH *sconf; 01028 01029 for(sconf=jconf->search_root;sconf;sconf=sconf->next) { 01030 if (strmatch(sconf->name, name)) { 01031 break; 01032 } 01033 } 01034 if (!sconf) { /* error */ 01035 jlog("ERROR: j_get_searchconf_by_name: [SR \"%s\"] not found\n", name); 01036 return NULL; 01037 } 01038 return sconf; 01039 } 01040 01058 JCONF_SEARCH * 01059 j_get_searchconf_by_id(Jconf *jconf, int id) 01060 { 01061 JCONF_SEARCH *sconf; 01062 01063 for(sconf=jconf->search_root;sconf;sconf=sconf->next) { 01064 if (sconf->id == id) { 01065 break; 01066 } 01067 } 01068 if (!sconf) { /* error */ 01069 jlog("ERROR: j_get_searchconf_by_id: [SR%02d] not found\n", id); 01070 return NULL; 01071 } 01072 return sconf; 01073 } 01074 01095 boolean 01096 j_process_deactivate(Recog *recog, char *name) 01097 { 01098 RecogProcess *r; 01099 01100 for(r=recog->process_list;r;r=r->next) { 01101 if (strmatch(r->config->name, name)) { 01102 /* book to be inactive at next interval */ 01103 r->active = -1; 01104 break; 01105 } 01106 } 01107 if (!r) { /* not found */ 01108 jlog("ERROR: j_process_deactivate: no SR instance named \"%s\", cannot deactivate\n", name); 01109 return FALSE; 01110 } 01111 01112 /* tell engine to update */ 01113 recog->process_want_reload = TRUE; 01114 01115 return TRUE; 01116 } 01117 01139 boolean 01140 j_process_deactivate_by_id(Recog *recog, int id) 01141 { 01142 RecogProcess *r; 01143 01144 for(r=recog->process_list;r;r=r->next) { 01145 if (r->config->id == id) { 01146 /* book to be inactive at next interval */ 01147 r->active = -1; 01148 break; 01149 } 01150 } 01151 if (!r) { /* not found */ 01152 jlog("ERROR: j_process_deactivate_by_id: no SR instance whose id is \"%02d\", cannot deactivate\n", id); 01153 return FALSE; 01154 } 01155 01156 /* tell engine to update */ 01157 recog->process_want_reload = TRUE; 01158 01159 return TRUE; 01160 } 01161 01183 boolean 01184 j_process_activate(Recog *recog, char *name) 01185 { 01186 RecogProcess *r; 01187 01188 for(r=recog->process_list;r;r=r->next) { 01189 if (strmatch(r->config->name, name)) { 01190 /* book to be active at next interval */ 01191 r->active = 1; 01192 break; 01193 } 01194 } 01195 if (!r) { /* not found */ 01196 jlog("ERROR: j_process_activate: no SR instance named \"%s\", cannot activate\n", name); 01197 return FALSE; 01198 } 01199 01200 /* tell engine to update */ 01201 recog->process_want_reload = TRUE; 01202 01203 return TRUE; 01204 } 01205 01227 boolean 01228 j_process_activate_by_id(Recog *recog, int id) 01229 { 01230 RecogProcess *r; 01231 01232 for(r=recog->process_list;r;r=r->next) { 01233 if (r->config->id == id) { 01234 /* book to be active at next interval */ 01235 r->active = 1; 01236 break; 01237 } 01238 } 01239 if (!r) { /* not found */ 01240 jlog("ERROR: j_process_activate_by_id: no SR instance whose id is \"%02d\", cannot activate\n", id); 01241 return FALSE; 01242 } 01243 01244 /* tell engine to update */ 01245 recog->process_want_reload = TRUE; 01246 01247 return TRUE; 01248 } 01249 01280 boolean 01281 j_process_add_lm(Recog *recog, JCONF_LM *lmconf, JCONF_SEARCH *sconf, char *name) 01282 { 01283 /* add lmconf to global config */ 01284 if (j_jconf_lm_regist(recog->jconf, lmconf, name) == FALSE) { 01285 jlog("ERROR: j_process_add_lm: failed to regist new LM conf as \"%s\"\n", name); 01286 return FALSE; 01287 } 01288 /* assign lmconf and default amconf to the sconf */ 01289 sconf->amconf = j_get_amconf_default(recog->jconf); 01290 sconf->lmconf = lmconf; 01291 /* add the sconf to global config */ 01292 if (j_jconf_search_regist(recog->jconf, sconf, name) == FALSE) { 01293 jlog("ERROR: j_process_add_lm: failed to regist new SR conf as \"%s\"\n", name); 01294 j_jconf_search_free(sconf); 01295 return FALSE; 01296 } 01297 /* finalize the whole parameters */ 01298 if (j_jconf_finalize(recog->jconf) == FALSE) { 01299 jlog("ERROR: j_process_add_lm: failed to finalize the updated whole jconf\n"); 01300 return FALSE; 01301 } 01302 /* create LM process intance for the lmconf, and load LM */ 01303 if (j_load_lm(recog, lmconf) == FALSE) { 01304 jlog("ERROR: j_process_add_lm: failed to load LM \"%s\"\n", lmconf->name); 01305 return FALSE; 01306 } 01307 /* create recognition process instance for the sconf, and setup for recognition */ 01308 if (j_launch_recognition_instance(recog, sconf) == FALSE) { 01309 jlog("ERROR: j_process_add_lm: failed to start a new recognizer instance \"%s\"\n", sconf->name); 01310 return FALSE; 01311 } 01312 /* the created process will be live=FALSE, active = 1, so 01313 the new recognition instance is dead now but 01314 will be made live at next session */ 01315 01316 /* tell engine to update */ 01317 recog->process_want_reload = TRUE; 01318 01319 return TRUE; 01320 } 01321 01343 boolean 01344 j_process_remove(Recog *recog, JCONF_SEARCH *sconf) 01345 { 01346 RecogProcess *r, *r_prev; 01347 JCONF_SEARCH *sc, *sc_prev; 01348 01349 if (sconf == NULL) { 01350 jlog("ERROR: j_process_remove: sconf == NULL\n"); 01351 return FALSE; 01352 } 01353 01354 /* find corresponding process in engine and remove it from list */ 01355 r_prev = NULL; 01356 for(r=recog->process_list;r;r=r->next) { 01357 if (r->config == sconf) { 01358 if (r_prev == NULL) { 01359 recog->process_list = r->next; 01360 } else { 01361 r_prev->next = r->next; 01362 } 01363 break; 01364 } 01365 r_prev = r; 01366 } 01367 if (!r) { 01368 jlog("ERROR: j_process_remove: specified sconf %02d %s not found in recogprocess, removal failed\n", sconf->id, sconf->name); 01369 return FALSE; 01370 } 01371 01372 /* remove config from list in engine */ 01373 sc_prev = NULL; 01374 for(sc=recog->jconf->search_root;sc;sc=sc->next) { 01375 if (sc == sconf) { 01376 if (sc_prev == NULL) { 01377 recog->jconf->search_root = sc->next; 01378 } else { 01379 sc_prev->next = sc->next; 01380 } 01381 break; 01382 } 01383 sc_prev = sc; 01384 } 01385 if (!sc) { 01386 jlog("ERROR: j_process_remove: sconf %02d %s not found\n", sconf->id, sconf->name); 01387 } 01388 01389 /* free them */ 01390 j_recogprocess_free(r); 01391 if (verbose_flag) jlog("STAT: recogprocess %02d %s removed\n", sconf->id, sconf->name); 01392 j_jconf_search_free(sconf); 01393 01394 /* tell engine to update */ 01395 recog->process_want_reload = TRUE; 01396 01397 return TRUE; 01398 } 01399 01421 boolean 01422 j_process_lm_remove(Recog *recog, JCONF_LM *lmconf) 01423 { 01424 RecogProcess *r; 01425 PROCESS_LM *lm, *lm_prev; 01426 JCONF_LM *l, *l_prev; 01427 01428 if (lmconf == NULL) { 01429 jlog("ERROR: j_process_lm_remove: lmconf == NULL\n"); 01430 return FALSE; 01431 } 01432 01433 /* check if still used by a process */ 01434 for(r=recog->process_list;r;r=r->next) { 01435 if (r->config->lmconf == lmconf) { 01436 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); 01437 return FALSE; 01438 } 01439 } 01440 01441 /* find corresponding LM process in engine and remove it from list */ 01442 lm_prev = NULL; 01443 for(lm=recog->lmlist;lm;lm=lm->next) { 01444 if (lm->config == lmconf) { 01445 if (lm_prev == NULL) { 01446 recog->lmlist = lm->next; 01447 } else { 01448 lm_prev->next = lm->next; 01449 } 01450 break; 01451 } 01452 lm_prev = lm; 01453 } 01454 if (!lm) { 01455 jlog("ERROR: j_process_lm_remove: specified lmconf %02d %s not found in LM process, removal failed\n", lmconf->id, lmconf->name); 01456 return FALSE; 01457 } 01458 01459 /* remove config from list in engine */ 01460 l_prev = NULL; 01461 for(l=recog->jconf->lm_root;l;l=l->next) { 01462 if (l == lmconf) { 01463 if (l_prev == NULL) { 01464 recog->jconf->lm_root = l->next; 01465 } else { 01466 l_prev->next = l->next; 01467 } 01468 break; 01469 } 01470 l_prev = l; 01471 } 01472 if (!l) { 01473 jlog("ERROR: j_process_lm_remove: lmconf %02d %s not found\n", lmconf->id, lmconf->name); 01474 return FALSE; 01475 } 01476 01477 /* free them */ 01478 j_process_lm_free(lm); 01479 if (verbose_flag) jlog("STAT: LM process %02d %s removed\n", lmconf->id, lmconf->name); 01480 j_jconf_lm_free(lmconf); 01481 01482 /* tell engine to update */ 01483 recog->process_want_reload = TRUE; 01484 01485 return TRUE; 01486 } 01487 01509 boolean 01510 j_process_am_remove(Recog *recog, JCONF_AM *amconf) 01511 { 01512 RecogProcess *r; 01513 PROCESS_LM *lm; 01514 PROCESS_AM *am, *am_prev; 01515 JCONF_AM *a, *a_prev; 01516 01517 if (amconf == NULL) { 01518 jlog("ERROR: j_process_am_remove: amconf == NULL\n"); 01519 return FALSE; 01520 } 01521 01522 /* check if still used by a process */ 01523 for(r=recog->process_list;r;r=r->next) { 01524 if (r->config->amconf == amconf) { 01525 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); 01526 return FALSE; 01527 } 01528 } 01529 01530 /* check if still used by a LM process */ 01531 for(lm=recog->lmlist;lm;lm=lm->next) { 01532 if (lm->am->config == amconf) { 01533 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); 01534 return FALSE; 01535 } 01536 } 01537 01538 /* find corresponding AM process in engine and remove it from list */ 01539 am_prev = NULL; 01540 for(am=recog->amlist;am;am=am->next) { 01541 if (am->config == amconf) { 01542 if (am_prev == NULL) { 01543 recog->amlist = am->next; 01544 } else { 01545 am_prev->next = am->next; 01546 } 01547 break; 01548 } 01549 am_prev = am; 01550 } 01551 if (!am) { 01552 jlog("ERROR: j_process_am_remove: specified amconf %02d %s not found in AM process, removal failed\n", amconf->id, amconf->name); 01553 return FALSE; 01554 } 01555 01556 /* remove config from list in engine */ 01557 a_prev = NULL; 01558 for(a=recog->jconf->am_root;a;a=a->next) { 01559 if (a == amconf) { 01560 if (a_prev == NULL) { 01561 recog->jconf->am_root = a->next; 01562 } else { 01563 a_prev->next = a->next; 01564 } 01565 break; 01566 } 01567 a_prev = a; 01568 } 01569 if (!a) { 01570 jlog("ERROR: j_process_am_remove: amconf %02d %s not found\n", amconf->id, amconf->name); 01571 return FALSE; 01572 } 01573 01574 /* free them */ 01575 j_process_am_free(am); 01576 if (verbose_flag) jlog("STAT: AM process %02d %s removed\n", amconf->id, amconf->name); 01577 j_jconf_am_free(amconf); 01578 01579 /* tell engine to update */ 01580 recog->process_want_reload = TRUE; 01581 01582 return TRUE; 01583 } 01584 01585 #ifdef DEBUG_VTLN_ALPHA_TEST 01586 void 01587 vtln_alpha(Recog *recog, RecogProcess *r) 01588 { 01589 Sentence *s; 01590 float alpha, alpha_bgn, alpha_end; 01591 float max_alpha; 01592 LOGPROB max_score; 01593 PROCESS_AM *am; 01594 MFCCCalc *mfcc; 01595 SentenceAlign *align; 01596 01597 s = &(r->result.sent[0]); 01598 align = result_align_new(); 01599 01600 max_score = LOG_ZERO; 01601 01602 printf("------------ begin VTLN -------------\n"); 01603 01604 mfcc = r->am->mfcc; 01605 01606 alpha_bgn = mfcc->para->vtln_alpha - VTLN_RANGE; 01607 alpha_end = mfcc->para->vtln_alpha + VTLN_RANGE; 01608 01609 for(alpha = alpha_bgn; alpha <= alpha_end; alpha += VTLN_STEP) { 01610 mfcc->para->vtln_alpha = alpha; 01611 if (InitFBank(mfcc->wrk, mfcc->para) == FALSE) { 01612 jlog("ERROR: VTLN: InitFBank() failed\n"); 01613 return; 01614 } 01615 if (wav2mfcc(recog->speech, recog->speechlen, recog) == FALSE) { 01616 jlog("ERROR: VTLN: wav2mfcc() failed\n"); 01617 return; 01618 } 01619 outprob_prepare(&(r->am->hmmwrk), mfcc->param->samplenum); 01620 word_align(s->word, s->word_num, mfcc->param, align, r); 01621 printf("%f: %f\n", alpha, align->allscore); 01622 if (max_score < align->allscore) { 01623 max_score = align->allscore; 01624 max_alpha = alpha; 01625 } 01626 } 01627 printf("MAX: %f: %f\n", max_alpha, max_score); 01628 mfcc->para->vtln_alpha = max_alpha; 01629 if (InitFBank(mfcc->wrk, mfcc->para) == FALSE) { 01630 jlog("ERROR: VTLN: InitFBank() failed\n"); 01631 return; 01632 } 01633 01634 printf("------------ end VTLN -------------\n"); 01635 01636 result_align_free(align); 01637 01638 } 01639 #endif 01640 01641 01642 /* end of file */