Julius 4.1.5
|
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 00581 char * 00582 j_get_current_filename(Recog *recog) 00583 { 00584 char *p; 00585 p = NULL; 00586 if (recog->jconf->input.type == INPUT_WAVEFORM) { 00587 /* adin function input */ 00588 if (recog->adin->ad_input_name != NULL) { 00589 p = recog->adin->ad_input_name(); 00590 } 00591 } else { 00592 switch(recog->jconf->input.speech_input) { 00593 case SP_MFCMODULE: 00594 p = mfc_module_input_name(recog->mfcclist); 00595 break; 00596 case SP_MFCFILE: 00597 /* already assigned */ 00598 p = recog->adin->current_input_name; 00599 break; 00600 } 00601 } 00602 return p; 00603 } 00604 00605 00620 void 00621 j_recog_info(Recog *recog) 00622 { 00623 /* print out system information */ 00624 print_engine_info(recog); 00625 } 00626 00655 Recog * 00656 j_create_instance_from_jconf(Jconf *jconf) 00657 { 00658 Recog *recog; 00659 00660 /* check option values and set parameters needed for model loading */ 00661 if (j_jconf_finalize(jconf) == FALSE) { 00662 return NULL; 00663 } 00664 00665 /* create a recognition instance */ 00666 recog = j_recog_new(); 00667 00668 /* assign configuration to the instance */ 00669 recog->jconf = jconf; 00670 00671 /* load all files according to the configurations */ 00672 if (j_load_all(recog, jconf) == FALSE) { 00673 jlog("ERROR: j_create_instance_from_jconf: error in loading model\n"); 00674 /* j_model_free(model); */ 00675 return NULL; 00676 } 00677 00678 /* checkout for recognition: build lexicon tree, allocate cache */ 00679 if (j_final_fusion(recog) == FALSE) { 00680 jlog("ERROR: j_create_instance_from_jconf: error while setup for recognition\n"); 00681 j_recog_free(recog); 00682 return NULL; 00683 } 00684 00685 return recog; 00686 } 00687 00713 boolean 00714 j_regist_user_lm_func(PROCESS_LM *lm, 00715 LOGPROB (*unifunc)(WORD_INFO *winfo, WORD_ID w, LOGPROB ngram_prob), 00716 LOGPROB (*bifunc)(WORD_INFO *winfo, WORD_ID context, WORD_ID w, LOGPROB ngram_prob), 00717 LOGPROB (*probfunc)(WORD_INFO *winfo, WORD_ID *contexts, int context_len, WORD_ID w, LOGPROB ngram_prob)) 00718 { 00719 lm->lmfunc.uniprob = unifunc; 00720 lm->lmfunc.biprob = bifunc; 00721 lm->lmfunc.lmprob = probfunc; 00722 return TRUE; 00723 } 00724 00742 boolean 00743 j_regist_user_param_func(Recog *recog, boolean (*user_calc_vector)(MFCCCalc *, SP16 *, int)) 00744 { 00745 recog->calc_vector = user_calc_vector; 00746 return TRUE; 00747 } 00748 00749 00767 JCONF_AM * 00768 j_get_amconf_by_name(Jconf *jconf, char *name) 00769 { 00770 JCONF_AM *amconf; 00771 00772 for(amconf=jconf->am_root;amconf;amconf=amconf->next) { 00773 if (strmatch(amconf->name, name)) { 00774 break; 00775 } 00776 } 00777 if (!amconf) { /* error */ 00778 jlog("ERROR: j_get_amconf_by_name: [AM \"%s\"] not found\n", name); 00779 return NULL; 00780 } 00781 return amconf; 00782 } 00783 00801 JCONF_AM * 00802 j_get_amconf_by_id(Jconf *jconf, int id) 00803 { 00804 JCONF_AM *amconf; 00805 00806 for(amconf=jconf->am_root;amconf;amconf=amconf->next) { 00807 if (amconf->id == id) { 00808 break; 00809 } 00810 } 00811 if (!amconf) { /* error */ 00812 jlog("ERROR: j_get_amconf_by_id: [AM%02d] not found\n", id); 00813 return NULL; 00814 } 00815 return amconf; 00816 } 00817 00838 JCONF_AM * 00839 j_get_amconf_default(Jconf *jconf) 00840 { 00841 JCONF_AM *amconf; 00842 00843 if (jconf->am_root == NULL) return NULL; 00844 for(amconf=jconf->am_root;amconf->next;amconf=amconf->next); 00845 return(amconf); 00846 } 00847 00865 JCONF_LM * 00866 j_get_lmconf_by_name(Jconf *jconf, char *name) 00867 { 00868 JCONF_LM *lmconf; 00869 00870 for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) { 00871 if (strmatch(lmconf->name, name)) { 00872 break; 00873 } 00874 } 00875 if (!lmconf) { /* error */ 00876 jlog("ERROR: j_get_lmconf_by_name: [LM \"%s\"] not found\n", name); 00877 return NULL; 00878 } 00879 return lmconf; 00880 } 00881 00899 JCONF_LM * 00900 j_get_lmconf_by_id(Jconf *jconf, int id) 00901 { 00902 JCONF_LM *lmconf; 00903 00904 for(lmconf=jconf->lm_root;lmconf;lmconf=lmconf->next) { 00905 if (lmconf->id == id) { 00906 break; 00907 } 00908 } 00909 if (!lmconf) { /* error */ 00910 jlog("ERROR: j_get_lmconf_by_id: [LM%02d] not found\n", id); 00911 return NULL; 00912 } 00913 return lmconf; 00914 } 00915 00933 JCONF_SEARCH * 00934 j_get_searchconf_by_name(Jconf *jconf, char *name) 00935 { 00936 JCONF_SEARCH *sconf; 00937 00938 for(sconf=jconf->search_root;sconf;sconf=sconf->next) { 00939 if (strmatch(sconf->name, name)) { 00940 break; 00941 } 00942 } 00943 if (!sconf) { /* error */ 00944 jlog("ERROR: j_get_searchconf_by_name: [SR \"%s\"] not found\n", name); 00945 return NULL; 00946 } 00947 return sconf; 00948 } 00949 00967 JCONF_SEARCH * 00968 j_get_searchconf_by_id(Jconf *jconf, int id) 00969 { 00970 JCONF_SEARCH *sconf; 00971 00972 for(sconf=jconf->search_root;sconf;sconf=sconf->next) { 00973 if (sconf->id == id) { 00974 break; 00975 } 00976 } 00977 if (!sconf) { /* error */ 00978 jlog("ERROR: j_get_searchconf_by_id: [SR%02d] not found\n", id); 00979 return NULL; 00980 } 00981 return sconf; 00982 } 00983 01004 boolean 01005 j_process_deactivate(Recog *recog, char *name) 01006 { 01007 RecogProcess *r; 01008 01009 for(r=recog->process_list;r;r=r->next) { 01010 if (strmatch(r->config->name, name)) { 01011 /* book to be inactive at next interval */ 01012 r->active = -1; 01013 break; 01014 } 01015 } 01016 if (!r) { /* not found */ 01017 jlog("ERROR: j_process_deactivate: no SR instance named \"%s\", cannot deactivate\n", name); 01018 return FALSE; 01019 } 01020 01021 /* tell engine to update */ 01022 recog->process_want_reload = TRUE; 01023 01024 return TRUE; 01025 } 01026 01048 boolean 01049 j_process_deactivate_by_id(Recog *recog, int id) 01050 { 01051 RecogProcess *r; 01052 01053 for(r=recog->process_list;r;r=r->next) { 01054 if (r->config->id == id) { 01055 /* book to be inactive at next interval */ 01056 r->active = -1; 01057 break; 01058 } 01059 } 01060 if (!r) { /* not found */ 01061 jlog("ERROR: j_process_deactivate_by_id: no SR instance whose id is \"%02d\", cannot deactivate\n", id); 01062 return FALSE; 01063 } 01064 01065 /* tell engine to update */ 01066 recog->process_want_reload = TRUE; 01067 01068 return TRUE; 01069 } 01070 01092 boolean 01093 j_process_activate(Recog *recog, char *name) 01094 { 01095 RecogProcess *r; 01096 01097 for(r=recog->process_list;r;r=r->next) { 01098 if (strmatch(r->config->name, name)) { 01099 /* book to be active at next interval */ 01100 r->active = 1; 01101 break; 01102 } 01103 } 01104 if (!r) { /* not found */ 01105 jlog("ERROR: j_process_activate: no SR instance named \"%s\", cannot activate\n", name); 01106 return FALSE; 01107 } 01108 01109 /* tell engine to update */ 01110 recog->process_want_reload = TRUE; 01111 01112 return TRUE; 01113 } 01114 01136 boolean 01137 j_process_activate_by_id(Recog *recog, int id) 01138 { 01139 RecogProcess *r; 01140 01141 for(r=recog->process_list;r;r=r->next) { 01142 if (r->config->id == id) { 01143 /* book to be active at next interval */ 01144 r->active = 1; 01145 break; 01146 } 01147 } 01148 if (!r) { /* not found */ 01149 jlog("ERROR: j_process_activate_by_id: no SR instance whose id is \"%02d\", cannot activate\n", id); 01150 return FALSE; 01151 } 01152 01153 /* tell engine to update */ 01154 recog->process_want_reload = TRUE; 01155 01156 return TRUE; 01157 } 01158 01189 boolean 01190 j_process_add_lm(Recog *recog, JCONF_LM *lmconf, JCONF_SEARCH *sconf, char *name) 01191 { 01192 /* add lmconf to global config */ 01193 if (j_jconf_lm_regist(recog->jconf, lmconf, name) == FALSE) { 01194 jlog("ERROR: j_process_add_lm: failed to regist new LM conf as \"%s\"\n", name); 01195 return FALSE; 01196 } 01197 /* assign lmconf and default amconf to the sconf */ 01198 sconf->amconf = j_get_amconf_default(recog->jconf); 01199 sconf->lmconf = lmconf; 01200 /* add the sconf to global config */ 01201 if (j_jconf_search_regist(recog->jconf, sconf, name) == FALSE) { 01202 jlog("ERROR: j_process_add_lm: failed to regist new SR conf as \"%s\"\n", name); 01203 j_jconf_search_free(sconf); 01204 return FALSE; 01205 } 01206 /* finalize the whole parameters */ 01207 if (j_jconf_finalize(recog->jconf) == FALSE) { 01208 jlog("ERROR: j_process_add_lm: failed to finalize the updated whole jconf\n"); 01209 return FALSE; 01210 } 01211 /* create LM process intance for the lmconf, and load LM */ 01212 if (j_load_lm(recog, lmconf) == FALSE) { 01213 jlog("ERROR: j_process_add_lm: failed to load LM \"%s\"\n", lmconf->name); 01214 return FALSE; 01215 } 01216 /* create recognition process instance for the sconf, and setup for recognition */ 01217 if (j_launch_recognition_instance(recog, sconf) == FALSE) { 01218 jlog("ERROR: j_process_add_lm: failed to start a new recognizer instance \"%s\"\n", sconf->name); 01219 return FALSE; 01220 } 01221 /* the created process will be live=FALSE, active = 1, so 01222 the new recognition instance is dead now but 01223 will be made live at next session */ 01224 01225 /* tell engine to update */ 01226 recog->process_want_reload = TRUE; 01227 01228 return TRUE; 01229 } 01230 01252 boolean 01253 j_process_remove(Recog *recog, JCONF_SEARCH *sconf) 01254 { 01255 RecogProcess *r, *r_prev; 01256 JCONF_SEARCH *sc, *sc_prev; 01257 01258 if (sconf == NULL) { 01259 jlog("ERROR: j_process_remove: sconf == NULL\n"); 01260 return FALSE; 01261 } 01262 01263 /* find corresponding process in engine and remove it from list */ 01264 r_prev = NULL; 01265 for(r=recog->process_list;r;r=r->next) { 01266 if (r->config == sconf) { 01267 if (r_prev == NULL) { 01268 recog->process_list = r->next; 01269 } else { 01270 r_prev->next = r->next; 01271 } 01272 break; 01273 } 01274 r_prev = r; 01275 } 01276 if (!r) { 01277 jlog("ERROR: j_process_remove: specified sconf %02d %s not found in recogprocess, removal failed\n", sconf->id, sconf->name); 01278 return FALSE; 01279 } 01280 01281 /* remove config from list in engine */ 01282 sc_prev = NULL; 01283 for(sc=recog->jconf->search_root;sc;sc=sc->next) { 01284 if (sc == sconf) { 01285 if (sc_prev == NULL) { 01286 recog->jconf->search_root = sc->next; 01287 } else { 01288 sc_prev->next = sc->next; 01289 } 01290 break; 01291 } 01292 sc_prev = sc; 01293 } 01294 if (!sc) { 01295 jlog("ERROR: j_process_remove: sconf %02d %s not found\n", sconf->id, sconf->name); 01296 } 01297 01298 /* free them */ 01299 j_recogprocess_free(r); 01300 if (verbose_flag) jlog("STAT: recogprocess %02d %s removed\n", sconf->id, sconf->name); 01301 j_jconf_search_free(sconf); 01302 01303 /* tell engine to update */ 01304 recog->process_want_reload = TRUE; 01305 01306 return TRUE; 01307 } 01308 01330 boolean 01331 j_process_lm_remove(Recog *recog, JCONF_LM *lmconf) 01332 { 01333 RecogProcess *r; 01334 PROCESS_LM *lm, *lm_prev; 01335 JCONF_LM *l, *l_prev; 01336 01337 if (lmconf == NULL) { 01338 jlog("ERROR: j_process_lm_remove: lmconf == NULL\n"); 01339 return FALSE; 01340 } 01341 01342 /* check if still used by a process */ 01343 for(r=recog->process_list;r;r=r->next) { 01344 if (r->config->lmconf == lmconf) { 01345 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); 01346 return FALSE; 01347 } 01348 } 01349 01350 /* find corresponding LM process in engine and remove it from list */ 01351 lm_prev = NULL; 01352 for(lm=recog->lmlist;lm;lm=lm->next) { 01353 if (lm->config == lmconf) { 01354 if (lm_prev == NULL) { 01355 recog->lmlist = lm->next; 01356 } else { 01357 lm_prev->next = lm->next; 01358 } 01359 break; 01360 } 01361 lm_prev = lm; 01362 } 01363 if (!lm) { 01364 jlog("ERROR: j_process_lm_remove: specified lmconf %02d %s not found in LM process, removal failed\n", lmconf->id, lmconf->name); 01365 return FALSE; 01366 } 01367 01368 /* remove config from list in engine */ 01369 l_prev = NULL; 01370 for(l=recog->jconf->lm_root;l;l=l->next) { 01371 if (l == lmconf) { 01372 if (l_prev == NULL) { 01373 recog->jconf->lm_root = l->next; 01374 } else { 01375 l_prev->next = l->next; 01376 } 01377 break; 01378 } 01379 l_prev = l; 01380 } 01381 if (!l) { 01382 jlog("ERROR: j_process_lm_remove: lmconf %02d %s not found\n", lmconf->id, lmconf->name); 01383 return FALSE; 01384 } 01385 01386 /* free them */ 01387 j_process_lm_free(lm); 01388 if (verbose_flag) jlog("STAT: LM process %02d %s removed\n", lmconf->id, lmconf->name); 01389 j_jconf_lm_free(lmconf); 01390 01391 /* tell engine to update */ 01392 recog->process_want_reload = TRUE; 01393 01394 return TRUE; 01395 } 01396 01418 boolean 01419 j_process_am_remove(Recog *recog, JCONF_AM *amconf) 01420 { 01421 RecogProcess *r; 01422 PROCESS_LM *lm; 01423 PROCESS_AM *am, *am_prev; 01424 JCONF_AM *a, *a_prev; 01425 01426 if (amconf == NULL) { 01427 jlog("ERROR: j_process_am_remove: amconf == NULL\n"); 01428 return FALSE; 01429 } 01430 01431 /* check if still used by a process */ 01432 for(r=recog->process_list;r;r=r->next) { 01433 if (r->config->amconf == amconf) { 01434 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); 01435 return FALSE; 01436 } 01437 } 01438 01439 /* check if still used by a LM process */ 01440 for(lm=recog->lmlist;lm;lm=lm->next) { 01441 if (lm->am->config == amconf) { 01442 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); 01443 return FALSE; 01444 } 01445 } 01446 01447 /* find corresponding AM process in engine and remove it from list */ 01448 am_prev = NULL; 01449 for(am=recog->amlist;am;am=am->next) { 01450 if (am->config == amconf) { 01451 if (am_prev == NULL) { 01452 recog->amlist = am->next; 01453 } else { 01454 am_prev->next = am->next; 01455 } 01456 break; 01457 } 01458 am_prev = am; 01459 } 01460 if (!am) { 01461 jlog("ERROR: j_process_am_remove: specified amconf %02d %s not found in AM process, removal failed\n", amconf->id, amconf->name); 01462 return FALSE; 01463 } 01464 01465 /* remove config from list in engine */ 01466 a_prev = NULL; 01467 for(a=recog->jconf->am_root;a;a=a->next) { 01468 if (a == amconf) { 01469 if (a_prev == NULL) { 01470 recog->jconf->am_root = a->next; 01471 } else { 01472 a_prev->next = a->next; 01473 } 01474 break; 01475 } 01476 a_prev = a; 01477 } 01478 if (!a) { 01479 jlog("ERROR: j_process_am_remove: amconf %02d %s not found\n", amconf->id, amconf->name); 01480 return FALSE; 01481 } 01482 01483 /* free them */ 01484 j_process_am_free(am); 01485 if (verbose_flag) jlog("STAT: AM process %02d %s removed\n", amconf->id, amconf->name); 01486 j_jconf_am_free(amconf); 01487 01488 /* tell engine to update */ 01489 recog->process_want_reload = TRUE; 01490 01491 return TRUE; 01492 } 01493 01494 #ifdef DEBUG_VTLN_ALPHA_TEST 01495 void 01496 vtln_alpha(Recog *recog, RecogProcess *r) 01497 { 01498 Sentence *s; 01499 float alpha, alpha_bgn, alpha_end; 01500 float max_alpha; 01501 LOGPROB max_score; 01502 PROCESS_AM *am; 01503 MFCCCalc *mfcc; 01504 SentenceAlign *align; 01505 01506 s = &(r->result.sent[0]); 01507 align = result_align_new(); 01508 01509 max_score = LOG_ZERO; 01510 01511 printf("------------ begin VTLN -------------\n"); 01512 01513 mfcc = r->am->mfcc; 01514 01515 alpha_bgn = mfcc->para->vtln_alpha - VTLN_RANGE; 01516 alpha_end = mfcc->para->vtln_alpha + VTLN_RANGE; 01517 01518 for(alpha = alpha_bgn; alpha <= alpha_end; alpha += VTLN_STEP) { 01519 mfcc->para->vtln_alpha = alpha; 01520 if (InitFBank(mfcc->wrk, mfcc->para) == FALSE) { 01521 jlog("ERROR: VTLN: InitFBank() failed\n"); 01522 return; 01523 } 01524 if (wav2mfcc(recog->speech, recog->speechlen, recog) == FALSE) { 01525 jlog("ERROR: VTLN: wav2mfcc() failed\n"); 01526 return; 01527 } 01528 outprob_prepare(&(r->am->hmmwrk), mfcc->param->samplenum); 01529 word_align(s->word, s->word_num, mfcc->param, align, r); 01530 printf("%f: %f\n", alpha, align->allscore); 01531 if (max_score < align->allscore) { 01532 max_score = align->allscore; 01533 max_alpha = alpha; 01534 } 01535 } 01536 printf("MAX: %f: %f\n", max_alpha, max_score); 01537 mfcc->para->vtln_alpha = max_alpha; 01538 if (InitFBank(mfcc->wrk, mfcc->para) == FALSE) { 01539 jlog("ERROR: VTLN: InitFBank() failed\n"); 01540 return; 01541 } 01542 01543 printf("------------ end VTLN -------------\n"); 01544 01545 result_align_free(align); 01546 01547 } 01548 #endif 01549 01550 01551 /* end of file */