00001
00018
00019
00020
00021
00022
00023
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);
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
00082
00083
00084
00085
00086
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
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
00107 jconf = j_jconf_new();
00108
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
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
00123
00124
00125
00126
00127
00128
00129
00130 if (j_jconf_finalize(jconf) == FALSE) {
00131 if (logfile) fclose(fp);
00132 return -1;
00133 }
00134
00135
00136 recog = j_recog_new();
00137
00138 recog->jconf = jconf;
00139
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
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
00165
00166 if (charconv_setup() == FALSE) {
00167 if (logfile) fclose(fp);
00168 return -1;
00169 }
00170 if (is_module_mode()) {
00171
00172
00173 module_setup(recog, NULL);
00174 } else {
00175
00176 setup_output_tty(recog, NULL);
00177 }
00178
00179
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
00190 record_setup(recog, NULL);
00191
00192
00193 if (is_module_mode()) module_server();
00194
00195
00196
00197 if (j_adin_init(recog) == FALSE) return;
00198
00199
00200 j_recog_info(recog);
00201
00202 #ifdef VISUALIZE
00203
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
00210 visual2_best(now, winfo);
00211
00212
00213 visual2_best(now, recog->model->winfo);
00214 #endif
00215
00216
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) {
00224 j_request_pause(recog);
00225 }
00226 }
00227 }
00228 }
00229
00230
00231 main_recognition_stream_loop(recog);
00232
00233
00234 if (is_module_mode()) module_disconnect();
00235
00236
00237 j_recog_free(recog);
00238
00239 if (logfile) fclose(fp);
00240 return(0);
00241 }