00001
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "app.h"
00027
00028 boolean separate_score_flag = FALSE;
00029 boolean callback_debug_flag = FALSE;
00030 boolean outfile_enabled = FALSE;
00031
00032 static char *logfile = NULL;
00033 static boolean nolog = FALSE;
00034
00035
00040 static boolean
00041 opt_help(Jconf *jconf, char *arg[], int argnum)
00042 {
00043 fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION);
00044 j_output_argument_help(stderr);
00045 exit(1);
00046 return TRUE;
00047 }
00048 static boolean
00049 opt_separatescore(Jconf *jconf, char *arg[], int argnum)
00050 {
00051 separate_score_flag = TRUE;
00052 return TRUE;
00053 }
00054 static boolean
00055 opt_callbackdebug(Jconf *jconf, char *arg[], int argnum)
00056 {
00057 callback_debug_flag = TRUE;
00058 return TRUE;
00059 }
00060 static boolean
00061 opt_logfile(Jconf *jconf, char *arg[], int argnum)
00062 {
00063 logfile = (char *)malloc(strlen(arg[0]) + 1);
00064 strcpy(logfile, arg[0]);
00065 return TRUE;
00066 }
00067 static boolean
00068 opt_nolog(Jconf *jconf, char *arg[], int argnum)
00069 {
00070 nolog = TRUE;
00071 return TRUE;
00072 }
00073 static boolean
00074 opt_outfile(Jconf *jconf, char *arg[], int argnum)
00075 {
00076 outfile_enabled = TRUE;
00077 return TRUE;
00078 }
00079
00080
00081 int
00082 main(int argc, char *argv[])
00083 {
00084 FILE *fp;
00085 Recog *recog;
00086 Jconf *jconf;
00087
00088
00089
00090
00091
00092
00093
00094 if (argc == 1) {
00095 fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION);
00096 j_put_version(stderr);
00097 fprintf(stderr, "Try '-setting' for built-in engine configuration.\n");
00098 fprintf(stderr, "Try '-help' for run time options.\n");
00099 return -1;
00100 }
00101
00102
00103 record_add_option();
00104 module_add_option();
00105 charconv_add_option();
00106 j_add_option("-separatescore", 0, 0, "output AM and LM scores separately", opt_separatescore);
00107 j_add_option("-callbackdebug", 0, 0, "output callback debug message", opt_callbackdebug);
00108 j_add_option("-logfile", 1, 1, "output log to file", opt_logfile);
00109 j_add_option("-nolog", 0, 0, "not output any log", opt_nolog);
00110 j_add_option("-outfile", 0, 0, "save result in separate .out file", opt_outfile);
00111 j_add_option("-help", 0, 0, "display this help", opt_help);
00112 j_add_option("--help", 0, 0, "display this help", opt_help);
00113
00114
00115 jconf = j_jconf_new();
00116
00117 if (j_config_load_args(jconf, argc, argv) == -1) {
00118 fprintf(stderr, "Try `-help' for more information.\n");
00119 return -1;
00120 }
00121
00122
00123 if (nolog) {
00124 jlog_set_output(NULL);
00125 } else if (logfile) {
00126 fp = fopen(logfile, "w");
00127 jlog_set_output(fp);
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 if (j_jconf_finalize(jconf) == FALSE) {
00139 if (logfile) fclose(fp);
00140 return -1;
00141 }
00142
00143
00144 recog = j_recog_new();
00145
00146 recog->jconf = jconf;
00147
00148 if (j_load_all(recog, jconf) == FALSE) {
00149 fprintf(stderr, "ERROR: Error in loading model\n");
00150 if (logfile) fclose(fp);
00151 return -1;
00152 }
00153
00154 #ifdef USER_LM_TEST
00155 {
00156 PROCESS_LM *lm;
00157 for(lm=recog->lmlist;lm;lm=lm->next) {
00158 if (lm->lmtype == LM_PROB) {
00159 j_regist_user_lm_func(lm, my_uni, my_bi, my_lm);
00160 }
00161 }
00162 #endif
00163
00164
00165 if (j_final_fusion(recog) == FALSE) {
00166 fprintf(stderr, "ERROR: Error while setup work area for recognition\n");
00167 j_recog_free(recog);
00168 if (logfile) fclose(fp);
00169 return -1;
00170 }
00171
00172
00173
00174 if (charconv_setup() == FALSE) {
00175 if (logfile) fclose(fp);
00176 return -1;
00177 }
00178 if (is_module_mode()) {
00179
00180
00181 module_setup(recog, NULL);
00182 } else {
00183
00184 setup_output_tty(recog, NULL);
00185 }
00186
00187
00188 if (outfile_enabled) {
00189 if (jconf->input.speech_input == SP_MFCFILE || jconf->input.speech_input == SP_RAWFILE) {
00190 setup_output_file(recog, NULL);
00191 } else {
00192 fprintf(stderr, "Warning: -outfile works only for file input, disabled now\n");
00193 outfile_enabled = FALSE;
00194 }
00195 }
00196
00197
00198 record_setup(recog, NULL);
00199
00200
00201 if (is_module_mode()) module_server();
00202
00203
00204
00205 if (j_adin_init(recog) == FALSE) return;
00206
00207
00208 j_recog_info(recog);
00209
00210 #ifdef VISUALIZE
00211
00212 visual_init(recog);
00213 callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, visual_show, NULL);
00214 callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, visual2_init, NULL);
00215 callback_add(recog, CALLBACK_DEBUG_PASS2_POP, visual2_popped, NULL);
00216 callback_add(recog, CALLBACK_DEBUG_PASS2_PUSH, visual2_next_word, NULL);
00217
00218 visual2_best(now, winfo);
00219
00220
00221 visual2_best(now, recog->model->winfo);
00222 #endif
00223
00224
00225 {
00226 RecogProcess *r;
00227 boolean ok_p;
00228 ok_p = TRUE;
00229 for(r=recog->process_list;r;r=r->next) {
00230 if (r->lmtype == LM_DFA) {
00231 if (r->lm->winfo == NULL) {
00232 j_request_pause(recog);
00233 }
00234 }
00235 }
00236 }
00237
00238
00239 main_recognition_stream_loop(recog);
00240
00241
00242 if (is_module_mode()) module_disconnect();
00243
00244
00245 j_recog_free(recog);
00246
00247 if (logfile) fclose(fp);
00248 return(0);
00249 }