int cTumkwsjSink::setupJulius() { try { int argc=3; char* argv[3] = {"julius","-C",NULL}; if (configfile != NULL) argv[2]=strdup(configfile); else argv[2]=strdup("kws.cfg"); /* add application option dummies */ /* j_add_option("-gprob", 1, 1, "garbage probability", opt_gprob); j_add_option("-kprob", 1, 1, "keyword probability", opt_kprob); j_add_option("-knum", 1, 1, "number of keywords", opt_knum); */ /* create a configuration variables container */ jconf = j_jconf_new(); // j_config_load_file(jconf, strdup(configfile)); if (j_config_load_args(jconf, argc, argv) == -1) { COMP_ERR("error parsing julius decoder options, this might be a bug. see tumkwsjSink.cpp!"); j_jconf_free(jconf); free(argv[2]); return 0; } free(argv[2]); /* output system log to a file */ if (getInt("debug") != 1) { jlog_set_output(NULL); } /* here you can set/modify any parameter in the jconf before setup */ jconf->input.type = INPUT_VECTOR; jconf->input.speech_input = SP_EXTERN; jconf->decodeopt.realtime_flag = TRUE; // ??? jconf->ext.period = (float)(reader->getLevelT()); jconf->ext.veclen = reader->getLevelN(); jconf->ext.userptr = (void *)this; jconf->ext.fv_read = external_fv_read_loader; /* Fixate jconf parameters: it checks whether the jconf parameters are suitable for recognition or not, and set some internal parameters according to the values for recognition. Modifying a value in jconf after this function may be errorous. */ if (j_jconf_finalize(jconf) == FALSE) { SMILE_IERR(1,"error finalising julius jconf in setupJulius()!"); j_jconf_free(jconf); return 0; } /* create a recognition instance */ recog = j_recog_new(); /* use user-definable data hook to set a pointer to our class instance */ recog->hook = (void *)this; /* assign configuration to the instance */ recog->jconf = jconf; /* load all files according to the configurations */ if (j_load_all(recog, jconf) == FALSE) { SMILE_IERR(1, "Error in loading model for Julius decoder"); j_recog_free(recog); return 0; } SMILE_IMSG(2,"garbage prob.: %f",glogprob); SMILE_IMSG(2,"keyword prob.: %f",klogprob); SMILE_IMSG(2,"number of phonemes: %i",numphon); // register user LM, get vocab size, and init lmWeights with zero or load from file PROCESS_LM *lm; for(lm=recog->lmlist;lm;lm=lm->next) { if (lm->lmtype == LM_PROB) { lm->winfo->userptr = (void*)this; // PATCH: sent/vocabulary.h (WORD_INFO struct): ++ void * userptr; // Pointer to userdata.... j_regist_user_lm_func(lm, userlm_uni_loader, userlm_bi_loader, userlm_lm_loader); if ((numWords==0)&&((long)(lm->winfo->num)>0)) { lmWinfo = lm->winfo; numWords = (long)(lm->winfo->num); } } } // load lmWeights data: //printf("XXX HEREA"); if (dynamicLm) { //printf("XXX HERE0"); if (lmWinfo != NULL) { //printf("XXX HERE"); lmWeights = (LOGPROB*)malloc(sizeof(LOGPROB)*numWords); if (lmWeights == NULL) { OUT_OF_MEMORY; } int i; for (i=0; i<numWords; i++) { lmWeights[i] = (LOGPROB)lmpenalty; } const char *lmfile = getStr("lmfile"); if (lmfile != NULL) { FILE *lf=fopen(lmfile,"r"); if (lf == NULL) { SMILE_IERR(1,"Error opening word weights file (lmfile) '%s'",lmfile); } else { SMILE_IMSG(1,"lmfile: '%s'",lmfile); long lineNr = 0; char *line=NULL; size_t len=0; size_t r=-1; do { r = getline(&line, &len, lf); //printf("XXX LINE '%s'",line); if ((r != (size_t)-1)&&(line!=NULL)) { lineNr++; parseLmWeightsLine(line,lineNr,lmfile); } } while (r != (size_t)-1); } } } else { SMILE_IERR(1,"no language model word info (vocabulary) found, check julius config!"); } } //---- /* checkout for recognition: build lexicon tree, allocate cache */ if (j_final_fusion(recog) == FALSE) { fprintf(stderr, "ERROR: Error while setup work area for recognition\n"); j_recog_free(recog); if (logfile) fclose(fp); return 0; } setupCallbacks(recog, NULL); /* output system information to log */ j_recog_info(recog); terminated = FALSE; } catch (int) { } juliusIsSetup=1; return 1; }
int main(int argc, char *argv[]) { FILE *fp; Recog *recog; Jconf *jconf; /* inihibit system log output (default: stdout) */ //jlog_set_output(NULL); /* output system log to a file */ // FILE *fp = fopen(logfile, "w"); jlog_set_output(fp); /* if no option argument, output julius usage and exit */ if (argc == 1) { fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION); j_put_version(stderr); fprintf(stderr, "Try '-setting' for built-in engine configuration.\n"); fprintf(stderr, "Try '-help' for run time options.\n"); return -1; } /* add application options */ record_add_option(); module_add_option(); charconv_add_option(); j_add_option("-separatescore", 0, 0, "output AM and LM scores separately", opt_separatescore); j_add_option("-logfile", 1, 1, "output log to file", opt_logfile); j_add_option("-nolog", 0, 0, "not output any log", opt_nolog); j_add_option("-outfile", 0, 0, "save result in separate .out file", opt_outfile); j_add_option("-help", 0, 0, "display this help", opt_help); j_add_option("--help", 0, 0, "display this help", opt_help); /* create a configuration variables container */ jconf = j_jconf_new(); // j_config_load_file(jconf, jconffile); if (j_config_load_args(jconf, argc, argv) == -1) { fprintf(stderr, "Try `-help' for more information.\n"); return -1; } /* output system log to a file */ if (nolog) { jlog_set_output(NULL); } else if (logfile) { fp = fopen(logfile, "w"); jlog_set_output(fp); } /* here you can set/modify any parameter in the jconf before setup */ // jconf->input.input_speech = SP_MIC; /* Fixate jconf parameters: it checks whether the jconf parameters are suitable for recognition or not, and set some internal parameters according to the values for recognition. Modifying a value in jconf after this function may be errorous. */ if (j_jconf_finalize(jconf) == FALSE) { if (logfile) fclose(fp); return -1; } /* create a recognition instance */ recog = j_recog_new(); /* assign configuration to the instance */ recog->jconf = jconf; /* load all files according to the configurations */ if (j_load_all(recog, jconf) == FALSE) { fprintf(stderr, "ERROR: Error in loading model\n"); if (logfile) fclose(fp); return -1; } #ifdef USER_LM_TEST { PROCESS_LM *lm; for(lm=recog->lmlist;lm;lm=lm->next) { if (lm->lmtype == LM_PROB) { j_regist_user_lm_func(lm, my_uni, my_bi, my_lm); } } #endif /* checkout for recognition: build lexicon tree, allocate cache */ if (j_final_fusion(recog) == FALSE) { fprintf(stderr, "ERROR: Error while setup work area for recognition\n"); j_recog_free(recog); if (logfile) fclose(fp); return -1; } /* Set up some application functions */ /* set character conversion mode */ if (charconv_setup() == FALSE) { if (logfile) fclose(fp); return -1; } if (is_module_mode()) { /* set up for module mode */ /* register result output callback functions to network module */ module_setup(recog, NULL); } else { /* register result output callback functions to stdout */ setup_output_tty(recog, NULL); } /* if -outfile option specified, callbacks for file output will be regitered */ if (outfile_enabled) { if (jconf->input.speech_input == SP_MFCFILE || jconf->input.speech_input == SP_RAWFILE) { setup_output_file(recog, NULL); } else { fprintf(stderr, "Warning: -outfile works only for file input, disabled now\n"); outfile_enabled = FALSE; } } /* setup recording if option was specified */ record_setup(recog, NULL); /* on module connect with client */ if (is_module_mode()) module_server(); /* initialize and standby the specified audio input source */ /* for microphone or other threaded input, ad-in thread starts here */ if (j_adin_init(recog) == FALSE) return; /* output system information to log */ j_recog_info(recog); #ifdef VISUALIZE /* Visualize: initialize GTK */ visual_init(recog); callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, visual_show, NULL); callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, visual2_init, NULL); callback_add(recog, CALLBACK_DEBUG_PASS2_POP, visual2_popped, NULL); callback_add(recog, CALLBACK_DEBUG_PASS2_PUSH, visual2_next_word, NULL); /* below should be called at result */ visual2_best(now, winfo); /* 音声取り込みはコールバックで新規作成 */ /* 第2パスで認識結果出力時に以下を実行 */ visual2_best(now, recog->model->winfo); #endif /* if no grammar specified on startup, start with pause status */ { RecogProcess *r; boolean ok_p; ok_p = TRUE; for(r=recog->process_list;r;r=r->next) { if (r->lmtype == LM_DFA) { if (r->lm->winfo == NULL) { /* stop when no grammar found */ j_request_pause(recog); } } } } /* enter recongnition loop */ main_recognition_stream_loop(recog); /* end proc */ if (is_module_mode()) module_disconnect(); /* release all */ j_recog_free(recog); if (logfile) fclose(fp); return(0); }