Julius 4.2
|
00001 00018 /* 00019 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00020 * Copyright (c) 1997-2000 Information-technology Promotion Agency, Japan 00021 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00022 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00023 * All rights reserved 00024 */ 00025 00026 #include "app.h" 00027 00028 boolean separate_score_flag = FALSE; 00029 boolean outfile_enabled = FALSE; 00030 00031 static char *logfile = NULL; 00032 static boolean nolog = FALSE; 00033 00034 /************************************************************************/ 00039 static boolean 00040 opt_help(Jconf *jconf, char *arg[], int argnum) 00041 { 00042 fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION); 00043 j_output_argument_help(stderr); 00044 exit(1); /* terminates here! */ 00045 return TRUE; 00046 } 00047 static boolean 00048 opt_separatescore(Jconf *jconf, char *arg[], int argnum) 00049 { 00050 separate_score_flag = TRUE; 00051 return TRUE; 00052 } 00053 static boolean 00054 opt_logfile(Jconf *jconf, char *arg[], int argnum) 00055 { 00056 logfile = (char *)malloc(strlen(arg[0]) + 1); 00057 strcpy(logfile, arg[0]); 00058 return TRUE; 00059 } 00060 static boolean 00061 opt_nolog(Jconf *jconf, char *arg[], int argnum) 00062 { 00063 nolog = TRUE; 00064 return TRUE; 00065 } 00066 static boolean 00067 opt_outfile(Jconf *jconf, char *arg[], int argnum) 00068 { 00069 outfile_enabled = TRUE; 00070 return TRUE; 00071 } 00072 00073 /**********************************************************************/ 00074 int 00075 main(int argc, char *argv[]) 00076 { 00077 FILE *fp; 00078 Recog *recog; 00079 Jconf *jconf; 00080 00081 /* inihibit system log output (default: stdout) */ 00082 //jlog_set_output(NULL); 00083 /* output system log to a file */ 00084 // FILE *fp = fopen(logfile, "w"); jlog_set_output(fp); 00085 00086 /* if no option argument, output julius usage and exit */ 00087 if (argc == 1) { 00088 fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION); 00089 j_put_version(stderr); 00090 fprintf(stderr, "Try '-setting' for built-in engine configuration.\n"); 00091 fprintf(stderr, "Try '-help' for run time options.\n"); 00092 return -1; 00093 } 00094 00095 /* add application options */ 00096 record_add_option(); 00097 module_add_option(); 00098 charconv_add_option(); 00099 j_add_option("-separatescore", 0, 0, "output AM and LM scores separately", opt_separatescore); 00100 j_add_option("-logfile", 1, 1, "output log to file", opt_logfile); 00101 j_add_option("-nolog", 0, 0, "not output any log", opt_nolog); 00102 j_add_option("-outfile", 0, 0, "save result in separate .out file", opt_outfile); 00103 j_add_option("-help", 0, 0, "display this help", opt_help); 00104 j_add_option("--help", 0, 0, "display this help", opt_help); 00105 00106 /* create a configuration variables container */ 00107 jconf = j_jconf_new(); 00108 // j_config_load_file(jconf, jconffile); 00109 if (j_config_load_args(jconf, argc, argv) == -1) { 00110 fprintf(stderr, "Try `-help' for more information.\n"); 00111 return -1; 00112 } 00113 00114 /* output system log to a file */ 00115 if (nolog) { 00116 jlog_set_output(NULL); 00117 } else if (logfile) { 00118 fp = fopen(logfile, "w"); 00119 jlog_set_output(fp); 00120 } 00121 00122 /* here you can set/modify any parameter in the jconf before setup */ 00123 // jconf->input.input_speech = SP_MIC; 00124 00125 /* Fixate jconf parameters: it checks whether the jconf parameters 00126 are suitable for recognition or not, and set some internal 00127 parameters according to the values for recognition. Modifying 00128 a value in jconf after this function may be errorous. 00129 */ 00130 if (j_jconf_finalize(jconf) == FALSE) { 00131 if (logfile) fclose(fp); 00132 return -1; 00133 } 00134 00135 /* create a recognition instance */ 00136 recog = j_recog_new(); 00137 /* assign configuration to the instance */ 00138 recog->jconf = jconf; 00139 /* load all files according to the configurations */ 00140 if (j_load_all(recog, jconf) == FALSE) { 00141 fprintf(stderr, "ERROR: Error in loading model\n"); 00142 if (logfile) fclose(fp); 00143 return -1; 00144 } 00145 00146 #ifdef USER_LM_TEST 00147 { 00148 PROCESS_LM *lm; 00149 for(lm=recog->lmlist;lm;lm=lm->next) { 00150 if (lm->lmtype == LM_PROB) { 00151 j_regist_user_lm_func(lm, my_uni, my_bi, my_lm); 00152 } 00153 } 00154 #endif 00155 00156 /* checkout for recognition: build lexicon tree, allocate cache */ 00157 if (j_final_fusion(recog) == FALSE) { 00158 fprintf(stderr, "ERROR: Error while setup work area for recognition\n"); 00159 j_recog_free(recog); 00160 if (logfile) fclose(fp); 00161 return -1; 00162 } 00163 00164 /* Set up some application functions */ 00165 /* set character conversion mode */ 00166 if (charconv_setup() == FALSE) { 00167 if (logfile) fclose(fp); 00168 return -1; 00169 } 00170 if (is_module_mode()) { 00171 /* set up for module mode */ 00172 /* register result output callback functions to network module */ 00173 module_setup(recog, NULL); 00174 } else { 00175 /* register result output callback functions to stdout */ 00176 setup_output_tty(recog, NULL); 00177 } 00178 /* if -outfile option specified, callbacks for file output will be 00179 regitered */ 00180 if (outfile_enabled) { 00181 if (jconf->input.speech_input == SP_MFCFILE || jconf->input.speech_input == SP_RAWFILE) { 00182 setup_output_file(recog, NULL); 00183 } else { 00184 fprintf(stderr, "Warning: -outfile works only for file input, disabled now\n"); 00185 outfile_enabled = FALSE; 00186 } 00187 } 00188 00189 /* setup recording if option was specified */ 00190 record_setup(recog, NULL); 00191 00192 /* on module connect with client */ 00193 if (is_module_mode()) module_server(); 00194 00195 /* initialize and standby the specified audio input source */ 00196 /* for microphone or other threaded input, ad-in thread starts here */ 00197 if (j_adin_init(recog) == FALSE) return; 00198 00199 /* output system information to log */ 00200 j_recog_info(recog); 00201 00202 #ifdef VISUALIZE 00203 /* Visualize: initialize GTK */ 00204 visual_init(recog); 00205 callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, visual_show, NULL); 00206 callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, visual2_init, NULL); 00207 callback_add(recog, CALLBACK_DEBUG_PASS2_POP, visual2_popped, NULL); 00208 callback_add(recog, CALLBACK_DEBUG_PASS2_PUSH, visual2_next_word, NULL); 00209 /* below should be called at result */ 00210 visual2_best(now, winfo); 00211 /* 音声取り込みはコールバックで新規作成 */ 00212 /* 第2パスで認識結果出力時に以下を実行 */ 00213 visual2_best(now, recog->model->winfo); 00214 #endif 00215 00216 /* if no grammar specified on startup, start with pause status */ 00217 { 00218 RecogProcess *r; 00219 boolean ok_p; 00220 ok_p = TRUE; 00221 for(r=recog->process_list;r;r=r->next) { 00222 if (r->lmtype == LM_DFA) { 00223 if (r->lm->winfo == NULL) { /* stop when no grammar found */ 00224 j_request_pause(recog); 00225 } 00226 } 00227 } 00228 } 00229 00230 /* enter recongnition loop */ 00231 main_recognition_stream_loop(recog); 00232 00233 /* end proc */ 00234 if (is_module_mode()) module_disconnect(); 00235 00236 /* release all */ 00237 j_recog_free(recog); 00238 00239 if (logfile) fclose(fp); 00240 return(0); 00241 }