julius/m_options.c

Go to the documentation of this file.
00001 
00017 /*
00018  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00019  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00020  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00021  * All rights reserved
00022  */
00023 
00024 #include <julius.h>
00025 
00050 char *
00051 filepath(char *filename, char *dirname)
00052 {
00053   char *p;
00054   if (dirname != NULL && filename[0] != '/'
00055 #if defined(_WIN32)
00056       && filename[0] != '\\' && !(strlen(filename) >= 3 && filename[1] == ':')
00057 #endif
00058       ) {
00059     p = (char *)mymalloc(strlen(filename) + strlen(dirname) + 1);
00060     strcpy(p, dirname);
00061     strcat(p, filename);
00062   } else {
00063     p = strcpy((char *)mymalloc(strlen(filename)+1), filename);
00064   }
00065   return p;
00066 }
00067 
00084 static char *
00085 args_needed_exit(char *opt)
00086 {
00087   j_printerr("%s: option requires argument -- %s\n", EXECNAME, opt);
00088   opt_terminate();
00089   return(NULL);
00090 }
00091 
00108 void
00109 opt_parse(int argc, char *argv[], char *cwd)
00110 {
00111   char *tmparg;
00112   int i;
00113 
00114 #define NEXTARG (++i >= argc) ? (char *)args_needed_exit(argv[i-1]) : argv[i] 
00115 
00116   if (argc == 1) {              /* no argument */
00117     usage();
00118   }
00119   
00120   for (i=1;i<argc;i++) {
00121     if (strmatch(argv[i],"-C")) { /* include jconf file  */
00122       tmparg = filepath(NEXTARG, cwd);
00123       config_file_parse(tmparg);
00124       free(tmparg);
00125       continue;
00126     } else if (strmatch(argv[i],"-input")) { /* speech input */
00127       tmparg = NEXTARG;
00128       if (strmatch(tmparg,"file")) {
00129         speech_input = SP_RAWFILE;
00130         realtime_flag = FALSE;
00131       } else if (strmatch(tmparg,"rawfile")) {
00132         speech_input = SP_RAWFILE;
00133         realtime_flag = FALSE;
00134       } else if (strmatch(tmparg,"htkparam")) {
00135         speech_input = SP_MFCFILE;
00136         realtime_flag = FALSE;
00137       } else if (strmatch(tmparg,"mfcfile")) {
00138         speech_input = SP_MFCFILE;
00139         realtime_flag = FALSE;
00140       } else if (strmatch(tmparg,"stdin")) {
00141         speech_input = SP_STDIN;
00142         realtime_flag = FALSE;
00143       } else if (strmatch(tmparg,"adinnet")) {
00144         speech_input = SP_ADINNET;
00145         realtime_flag = TRUE;
00146 #ifdef USE_NETAUDIO
00147       } else if (strmatch(tmparg,"netaudio")) {
00148         speech_input = SP_NETAUDIO;
00149         realtime_flag = TRUE;
00150 #endif
00151 #ifdef USE_MIC
00152       } else if (strmatch(tmparg,"mic")) {
00153         speech_input = SP_MIC;
00154         realtime_flag = TRUE;
00155 #endif
00156       } else if (strmatch(tmparg,"file")) { /* for 1.1 compat */
00157         speech_input = SP_RAWFILE;
00158         realtime_flag = FALSE;
00159       } else if (strmatch(tmparg,"mfc")) { /* for 1.1 compat */
00160         speech_input = SP_MFCFILE;
00161         realtime_flag = FALSE;
00162       } else {
00163         j_printerr("%s: no such speech input source \"%s\" supported\n", argv[0], tmparg);
00164         opt_terminate();
00165       }
00166       continue;
00167     } else if (strmatch(argv[i],"-filelist")) { /* input file list */
00168       if (inputlist_filename) free(inputlist_filename);
00169       tmparg = NEXTARG;
00170       inputlist_filename = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00171       continue;
00172     } else if (strmatch(argv[i],"-record")) {   /* record speech data*/
00173       if (record_dirname) free(record_dirname);
00174       tmparg = NEXTARG;
00175       record_dirname = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00176       continue;
00177     } else if (strmatch(argv[i],"-rejectshort")) { /* short input rejection */
00178       rejectshortlen = atoi(NEXTARG);
00179       continue;
00180     } else if (strmatch(argv[i],"-module")) { /* enable module mode */
00181       module_mode = TRUE;
00182       if (i+1 < argc) {
00183         if (argv[i+1][0] >= '0' && argv[i+1][0] <= '9') {
00184           module_port = atoi(NEXTARG);
00185         }
00186       }
00187       /* this option implicitly includes "-result msock" */
00188       result_output = SP_RESULT_MSOCK;
00189       continue;
00190     } else if (strmatch(argv[i],"-result")) { /* result output */
00191       tmparg = NEXTARG;
00192       if (strmatch(tmparg,"tty")) {
00193         result_output = SP_RESULT_TTY;
00194       } else if (strmatch(tmparg,"msock")) {
00195         result_output = SP_RESULT_MSOCK;
00196       } else {
00197         j_printerr("%s: no such result output \"%s\"\n", argv[0], tmparg);
00198         opt_terminate();
00199       }
00200       continue;
00201     } else if (strmatch(argv[i],"-outcode")) {
00202       decode_output_selection(NEXTARG);
00203       continue;
00204     } else if (strmatch(argv[i],"-force_realtime")) { /* force realtime */
00205       tmparg = NEXTARG;
00206       if (strmatch(tmparg, "on")) {
00207         forced_realtime = TRUE;
00208       } else if (strmatch(tmparg, "off")) {
00209         forced_realtime = FALSE;
00210       } else {
00211         j_printerr("%s: \"-force_realtime\" allows \"on\" or \"off\" only\n", EXECNAME);
00212         opt_terminate();
00213       }
00214       force_realtime_flag = TRUE;
00215       continue;
00216     } else if (strmatch(argv[i],"-realtime")) { /* equal to "-force_realtime on" */
00217       forced_realtime = TRUE;
00218       force_realtime_flag = TRUE;
00219       continue;
00220     } else if (strmatch(argv[i], "-norealtime")) { /* equal to "-force_realtime off" */
00221       forced_realtime = FALSE;
00222       force_realtime_flag = TRUE;
00223       continue;
00224     } else if (strmatch(argv[i],"-forcedict")) { /* skip dict error */
00225       forcedict_flag = TRUE;
00226       continue;
00227     } else if (strmatch(argv[i],"-check")) { /* interactive model check mode */
00228       tmparg = NEXTARG;
00229       if (strmatch(tmparg, "wchmm")) {
00230         wchmm_check_flag = TRUE;
00231       } else if (strmatch(tmparg, "trellis")) {
00232         trellis_check_flag = TRUE;
00233       } else if (strmatch(tmparg, "triphone")) {
00234         triphone_check_flag = TRUE;
00235       } else {
00236         j_printerr("%s: invalid check style: %s\n", argv[0], tmparg);
00237         opt_terminate();
00238       }
00239       continue;
00240     } else if (strmatch(argv[i],"-notypecheck")) { /* don't check param type */
00241       paramtype_check_flag = FALSE;
00242       continue;
00243     } else if (strmatch(argv[i],"-separatescore")) { /* output LM/AM score */
00244 #ifdef USE_NGRAM
00245       separate_score_flag = TRUE;
00246 #else  /* USE_DFA */
00247       j_printerr("Warning: option \"-separatescore\" ignored\n");
00248 #endif
00249       continue;
00250     } else if (strmatch(argv[i],"-nlimit")) { /* limit N token in a node */
00251 #ifdef WPAIR_KEEP_NLIMIT
00252       wpair_keep_nlimit = atoi(NEXTARG);
00253 #else
00254       j_printerr("Warning: option \"-nlimit\" ignored\n");
00255 #endif
00256       continue;
00257     } else if (strmatch(argv[i],"-lookuprange")) { /* trellis neighbor range */
00258       lookup_range = atoi(NEXTARG);
00259       continue;
00260 #ifdef GRAPHOUT
00261     } else if (strmatch(argv[i],"-graphrange")) { /* neighbor merge range frame */
00262       graph_merge_neighbor_range = atoi(NEXTARG);
00263       continue;
00264 #ifdef GRAPHOUT_DEPTHCUT
00265     } else if (strmatch(argv[i],"-graphcut")) { /* cut graph word by depth */
00266       graphout_cut_depth = atoi(NEXTARG);
00267       continue;
00268 #endif
00269 #ifdef GRAPHOUT_LIMIT_BOUNDARY_LOOP
00270     } else if (strmatch(argv[i],"-graphboundloop")) { /* neighbor merge range frame */
00271       graphout_limit_boundary_loop_num = atoi(NEXTARG);
00272       continue;
00273 #endif
00274 #ifdef GRAPHOUT_SEARCH_DELAY_TERMINATION
00275     } else if (strmatch(argv[i],"-graphsearchdelay")) { /* not do graph search termination before the 1st sentence is found */
00276       graphout_search_delay = TRUE;
00277       continue;
00278     } else if (strmatch(argv[i],"-nographsearchdelay")) { /* not do graph search termination before the 1st sentence is found */
00279       graphout_search_delay = FALSE;
00280       continue;
00281 #endif
00282 #endif /* GRAPHOUT */
00283 #ifdef USE_DFA
00284     } else if (strmatch(argv[i],"-looktrellis")) { /* activate loopuprange */
00285       looktrellis_flag = TRUE;
00286       continue;
00287     } else if (strmatch(argv[i],"-multigramout")) { /* enable per-grammar decoding on 2nd pass */
00288       multigramout_flag = TRUE;
00289       continue;
00290     } else if (strmatch(argv[i],"-nomultigramout")) { /* disable per-grammar decoding on 2nd pass */
00291       multigramout_flag = FALSE;
00292       continue;
00293 #endif
00294 #ifdef CATEGORY_TREE
00295     } else if (strmatch(argv[i],"-oldtree")) { /* use old tree function */
00296       old_tree_function_flag = TRUE;
00297       continue;
00298 #ifdef PASS1_IWCD
00299     } else if (strmatch(argv[i],"-oldiwcd")) { /* use full lcd ignoring category constraint */
00300       old_iwcd_flag = TRUE;
00301       continue;
00302 #endif
00303 #endif
00304     } else if (strmatch(argv[i],"-sb")) { /* score envelope width in 2nd pass */
00305 #ifdef SCAN_BEAM
00306       scan_beam_thres = atof(NEXTARG);
00307 #else
00308       j_printerr("Warning: option \"-sb\" ignored\n");
00309 #endif
00310       continue;
00311     } else if (strmatch(argv[i],"-discount")) { /* (bogus) */
00312       j_printerr("Warning: option \"-discount\" ignored\n");
00313       continue;
00314     } else if (strmatch(argv[i],"-cutsilence")) { /* force (long) silence detection on */
00315       silence_cut = 1;
00316       continue;
00317     } else if (strmatch(argv[i],"-nocutsilence")) { /* force (long) silence detection off */
00318       silence_cut = 0;
00319       continue;
00320     } else if (strmatch(argv[i],"-pausesegment")) { /* force (long) silence detection on (for backward compatibility) */
00321       silence_cut = 1;
00322       continue;
00323     } else if (strmatch(argv[i],"-nopausesegment")) { /* force (long) silence detection off (for backward comatibility) */
00324       silence_cut = 0;
00325       continue;
00326     } else if (strmatch(argv[i],"-lv")) { /* silence detection threshold level */
00327       level_thres = atoi(NEXTARG);
00328       continue;
00329     } else if (strmatch(argv[i],"-zc")) { /* silence detection zero cross num */
00330       zero_cross_num = atoi(NEXTARG);
00331       continue;
00332     } else if (strmatch(argv[i],"-headmargin")) { /* head silence length */
00333       head_margin_msec = atoi(NEXTARG);
00334       continue;
00335     } else if (strmatch(argv[i],"-tailmargin")) { /* tail silence length */
00336       tail_margin_msec = atoi(NEXTARG);
00337       continue;
00338     } else if (strmatch(argv[i],"-hipass")||strmatch(argv[i],"-hifreq")) { /* frequency of upper band limit */
00339       para.hipass = atoi(NEXTARG);
00340       continue;
00341     } else if (strmatch(argv[i],"-lopass")||strmatch(argv[i],"-lofreq")) { /* frequency of lower band limit */
00342       para.lopass = atoi(NEXTARG);
00343       continue;
00344     } else if (strmatch(argv[i],"-smpPeriod")) { /* sample period (ns) */
00345       para.smp_period = atoi(NEXTARG);
00346       para.smp_freq = period2freq(para.smp_period);
00347       continue;
00348     } else if (strmatch(argv[i],"-smpFreq")) { /* sample frequency (Hz) */
00349       para.smp_freq = atoi(NEXTARG);
00350       para.smp_period = freq2period(para.smp_freq);
00351       continue;
00352     } else if (strmatch(argv[i],"-fsize")) { /* Window size */
00353       para.framesize = atoi(NEXTARG);
00354       continue;
00355     } else if (strmatch(argv[i],"-fshift")) { /* Frame shiht */
00356       para.frameshift = atoi(NEXTARG);
00357       continue;
00358     } else if (strmatch(argv[i],"-preemph")) {
00359       para.preEmph = atof(NEXTARG);
00360       continue;
00361     } else if (strmatch(argv[i],"-fbank")) {
00362       para.fbank_num = atoi(NEXTARG);
00363       continue;
00364     } else if (strmatch(argv[i],"-ceplif")) {
00365       para.lifter = atoi(NEXTARG);
00366       continue;
00367     } else if (strmatch(argv[i],"-rawe")) {
00368       para.raw_e = TRUE;
00369       continue;
00370     } else if (strmatch(argv[i],"-norawe")) {
00371       para.raw_e = FALSE;
00372       continue;
00373     } else if (strmatch(argv[i],"-enormal")) {
00374       para.enormal = TRUE;
00375       continue;
00376     } else if (strmatch(argv[i],"-noenormal")) {
00377       para.enormal = FALSE;
00378       continue;
00379     } else if (strmatch(argv[i],"-escale")) {
00380       para.escale = atof(NEXTARG);
00381       continue;
00382     } else if (strmatch(argv[i],"-silfloor")) {
00383       para.silFloor = atof(NEXTARG);
00384       continue;
00385     } else if (strmatch(argv[i],"-delwin")) { /* Delta window length */
00386       para.delWin = atoi(NEXTARG);
00387       continue;
00388     } else if (strmatch(argv[i],"-accwin")) { /* Acceleration window length */
00389       para.accWin = atoi(NEXTARG);
00390       continue;
00391     } else if (strmatch(argv[i],"-ssalpha")) { /* alpha coef. for SS */
00392       para.ss_alpha = atof(NEXTARG);
00393       continue;
00394     } else if (strmatch(argv[i],"-ssfloor")) { /* spectral floor for SS */
00395       para.ss_floor = atof(NEXTARG);
00396       continue;
00397     } else if (strmatch(argv[i],"-version") || strmatch(argv[i], "--version") || strmatch(argv[i], "-setting") || strmatch(argv[i], "--setting")) { /* print version and exit */
00398       put_header(stderr);
00399       put_compile_defs(stderr);
00400       j_printerr("\n");
00401       put_library_defs(stderr);
00402       j_exit();
00403     } else if (strmatch(argv[i],"-quiet")) { /* minimum output */
00404       debug2_flag = verbose_flag = FALSE;
00405       continue;
00406     } else if (strmatch(argv[i],"-debug")) { /* debug mode: output huge log */
00407       debug2_flag = verbose_flag = TRUE;
00408       continue;
00409     } else if (strmatch(argv[i],"-progout")) { /* enable progressive output */
00410       progout_flag = TRUE;
00411       continue;
00412     } else if (strmatch(argv[i],"-proginterval")) { /* interval for -progout */
00413       progout_interval = atoi(NEXTARG);
00414       continue;
00415     } else if (strmatch(argv[i],"-nocharconv")) { /* disable character set conversion */
00416 #ifdef CHARACTER_CONVERSION
00417       if (from_code) free(from_code);
00418       if (to_code) free(to_code);
00419       from_code = NULL;
00420       to_code = NULL;
00421 #else
00422       j_printerr("Warning: character set conversion disabled, option \"-nocharconv\" ignored\n");
00423 #endif
00424       continue;
00425     } else if (strmatch(argv[i],"-charconv")) { /* enable character set conversion */
00426 #ifdef CHARACTER_CONVERSION
00427       if (from_code) free(from_code);
00428       if (to_code) free(to_code);
00429       tmparg = NEXTARG;
00430       from_code = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00431       tmparg = NEXTARG;
00432       to_code = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00433 #else
00434       j_printerr("Warning: character set conversion disabled, option \"-charconv\" ignored\n");
00435       i+=2;
00436 #endif
00437       continue;
00438     } else if (strmatch(argv[i],"-kanji")) {
00439 #ifdef CHARACTER_CONVERSION
00440       if (from_code) free(from_code);
00441       if (to_code) free(to_code);
00442       from_code = NULL;
00443       tmparg = NEXTARG;
00444       if (strmatch(tmparg, "noconv")) {
00445         to_code = NULL;
00446       } else {
00447         to_code = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00448       }
00449 #else
00450       j_printerr("Warning: character set conversion disabled, option \"-kanji\" ignored\n");
00451       i++;
00452 #endif
00453       continue;
00454     } else if (strmatch(argv[i],"-demo")) { /* quiet + progout */
00455       debug2_flag = verbose_flag = FALSE;
00456       progout_flag = TRUE;
00457       continue;
00458     } else if (strmatch(argv[i],"-walign")) { /* do forced alignment by word */
00459       align_result_word_flag = TRUE;
00460       continue;
00461     } else if (strmatch(argv[i],"-palign")) { /* do forced alignment by phoneme */
00462       align_result_phoneme_flag = TRUE;
00463       continue;
00464     } else if (strmatch(argv[i],"-salign")) { /* do forced alignment by state */
00465       align_result_state_flag = TRUE;
00466       continue;
00467     } else if (strmatch(argv[i],"-output")) { /* output up to N candidate */
00468       output_hypo_maxnum = atoi(NEXTARG);
00469       continue;
00470     } else if (strmatch(argv[i],"-1pass")) { /* do only 1st pass */
00471       compute_only_1pass = TRUE;
00472       continue;
00473     } else if (strmatch(argv[i],"-hlist")) { /* HMM list file */
00474       if (mapfilename) free(mapfilename);
00475       mapfilename = filepath(NEXTARG, cwd);
00476       continue;
00477 #ifdef USE_NGRAM
00478     } else if (strmatch(argv[i],"-nlr")) { /* word LR 2-gram (ARPA) */
00479       if (ngram_filename_lr_arpa) free(ngram_filename_lr_arpa);
00480       ngram_filename_lr_arpa = filepath(NEXTARG, cwd);
00481       if (ngram_filename) free(ngram_filename);
00482       ngram_filename = NULL;
00483       continue;
00484     } else if (strmatch(argv[i],"-nrl")) { /* word RL 3-gram (ARPA) */
00485       if (ngram_filename_rl_arpa) free(ngram_filename_rl_arpa);
00486       ngram_filename_rl_arpa = filepath(NEXTARG, cwd);
00487       if (ngram_filename) free(ngram_filename);
00488       ngram_filename = NULL;
00489       continue;
00490     } else if (strmatch(argv[i],"-lmp")) { /* LM weight and penalty (pass1) */
00491       lm_weight = (LOGPROB)atof(NEXTARG);
00492       lm_penalty = (LOGPROB)atof(NEXTARG);
00493       lmp_specified = TRUE;
00494       continue;
00495     } else if (strmatch(argv[i],"-lmp2")) { /* LM weight and penalty (pass2) */
00496       lm_weight2 = (LOGPROB)atof(NEXTARG);
00497       lm_penalty2 = (LOGPROB)atof(NEXTARG);
00498       lmp2_specified = TRUE;
00499       continue;
00500     } else if (strmatch(argv[i],"-transp")) { /* penalty for transparent word */
00501       lm_penalty_trans = (LOGPROB)atof(NEXTARG);
00502       continue;
00503 #else  /* USE_DFA */
00504     } else if (strmatch(argv[i],"-gram")) { /* comma-separatedlist of grammar prefix */
00505       multigram_add_prefix_list(NEXTARG, cwd);
00506       continue;
00507     } else if (strmatch(argv[i],"-gramlist")) { /* file of grammar prefix list */
00508       tmparg = filepath(NEXTARG, cwd);
00509       multigram_add_prefix_filelist(tmparg);
00510       free(tmparg);
00511       continue;
00512     } else if (strmatch(argv[i],"-nogram")) { /* remove grammar list */
00513       multigram_remove_gramlist();
00514       if (dfa_filename) {
00515         free(dfa_filename);
00516         dfa_filename = NULL;
00517       }
00518       if (dictfilename) {
00519         free(dictfilename);
00520         dictfilename = NULL;
00521       }
00522       continue;
00523     } else if (strmatch(argv[i],"-dfa")) { /* DFA filename */
00524       if (dfa_filename) free(dfa_filename);
00525       dfa_filename = filepath(NEXTARG, cwd);
00526       continue;
00527     } else if (strmatch(argv[i],"-penalty1")) { /* word insertion penalty (pass1) */
00528       penalty1 = (LOGPROB)atof(NEXTARG);
00529       continue;
00530     } else if (strmatch(argv[i],"-penalty2")) { /* word insertion penalty (pass2) */
00531       penalty2 = (LOGPROB)atof(NEXTARG);
00532       continue;
00533 #endif
00534     } else if (strmatch(argv[i],"-spmodel") || strmatch(argv[i], "-sp")) { /* name of short pause word */
00535       if (spmodel_name) free(spmodel_name);
00536       tmparg = NEXTARG;
00537       spmodel_name = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00538       continue;
00539 #ifdef MULTIPATH_VERSION
00540     } else if (strmatch(argv[i],"-iwsp")) { /* enable inter-word short pause handing */
00541       enable_iwsp = TRUE;
00542       continue;
00543     } else if (strmatch(argv[i],"-iwsppenalty")) { /* set inter-word short pause transition penalty */
00544       iwsp_penalty = atof(NEXTARG);
00545       continue;
00546 #endif
00547 #ifdef USE_NGRAM
00548     } else if (strmatch(argv[i],"-silhead")) { /* head silence word name */
00549       if (head_silname) free(head_silname);
00550       tmparg = NEXTARG;
00551       head_silname = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00552       continue;
00553     } else if (strmatch(argv[i],"-siltail")) { /* tail silence word name */
00554       if (tail_silname) free(tail_silname);
00555       tmparg = NEXTARG;
00556       tail_silname = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00557       continue;
00558     } else if (strmatch(argv[i],"-iwspword")) { /* add short pause word */
00559       enable_iwspword = TRUE;
00560       continue;
00561     } else if (strmatch(argv[i],"-iwspentry")) { /* content of the iwspword */
00562       if (iwspentry) free(iwspentry);
00563       tmparg = NEXTARG;
00564       iwspentry = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00565       continue;
00566     } else if (strmatch(argv[i],"-iwcache")) { /* control cross-word LM cache */
00567 #ifdef HASH_CACHE_IW
00568       iw_cache_rate = atof(NEXTARG);
00569       if (iw_cache_rate > 100) iw_cache_rate = 100;
00570       if (iw_cache_rate < 1) iw_cache_rate = 1;
00571 #else
00572       j_printerr("Warning: option \"-iwcache\" ignored\n");
00573 #endif
00574       continue;
00575     } else if (strmatch(argv[i],"-sepnum")) { /* N-best frequent word will be separated from tree */
00576 #ifdef SEPARATE_BY_UNIGRAM
00577       separate_wnum = atoi(NEXTARG);
00578 #else
00579       j_printerr("Warning: option \"-sepnum\" ignored\n");
00580       i++;
00581 #endif
00582       continue;
00583 #endif /* USE_NGRAM */
00584 #ifdef USE_NETAUDIO
00585     } else if (strmatch(argv[i],"-NA")) { /* netautio device name */
00586       if (netaudio_devname) free(netaudio_devname);
00587       tmparg = NEXTARG;
00588       netaudio_devname = strcpy((char*)mymalloc(strlen(tmparg)+1),tmparg);
00589       continue;
00590 #endif
00591     } else if (strmatch(argv[i],"-adport")) { /* adinnet port num */
00592       adinnet_port = atoi(NEXTARG);
00593       continue;
00594     } else if (strmatch(argv[i],"-nostrip")) { /* do not strip zero samples */
00595       strip_zero_sample = FALSE;
00596       continue;
00597     } else if (strmatch(argv[i],"-zmean")) { /* enable DC offset by zero mean */
00598       use_zmean = TRUE;
00599       continue;
00600     } else if (strmatch(argv[i],"-nozmean")) { /* disable DC offset by zero mean */
00601       use_zmean = FALSE;
00602       continue;
00603     } else if (strmatch(argv[i],"-zmeanframe")) { /* enable frame-wise DC offset by zero mean */
00604       para.zmeanframe = TRUE;
00605       continue;
00606     } else if (strmatch(argv[i],"-nozmeanframe")) { /* disable frame-wise DC offset by zero mean */
00607       para.zmeanframe = FALSE;
00608       continue;
00609 #ifdef SP_BREAK_CURRENT_FRAME
00610     } else if (strmatch(argv[i],"-spdur")) { /* short-pause duration threshold */
00611       sp_frame_duration = atoi(NEXTARG);
00612       continue;
00613 #endif
00614     } else if (strmatch(argv[i],"-gprune")) { /* select Gaussian pruning method */
00615       tmparg = NEXTARG;
00616       if (strmatch(tmparg,"safe")) { /* safest, slowest */
00617         gprune_method = GPRUNE_SEL_SAFE;
00618       } else if (strmatch(tmparg,"heuristic")) {
00619         gprune_method = GPRUNE_SEL_HEURISTIC;
00620       } else if (strmatch(tmparg,"beam")) { /* fastest */
00621         gprune_method = GPRUNE_SEL_BEAM;
00622       } else if (strmatch(tmparg,"none")) { /* no prune: compute all Gaussian */
00623         gprune_method = GPRUNE_SEL_NONE;
00624       } else if (strmatch(tmparg,"default")) {
00625         gprune_method = GPRUNE_SEL_UNDEF;
00626       } else {
00627         j_printerr("%s: no such pruning method \"%s\"\n", argv[0], tmparg);
00628         opt_terminate();
00629       }
00630       continue;
00631 /* 
00632  *     } else if (strmatch(argv[i],"-reorder")) {
00633  *       result_reorder_flag = TRUE;
00634  *       continue;
00635  */
00636     } else if (strmatch(argv[i],"-no_ccd")) { /* force triphone handling = OFF */
00637       ccd_flag = FALSE;
00638       ccd_flag_force = TRUE;
00639       continue;
00640     } else if (strmatch(argv[i],"-force_ccd")) { /* force triphone handling = ON */
00641       ccd_flag = TRUE;
00642       ccd_flag_force = TRUE;
00643       continue;
00644     } else if (strmatch(argv[i],"-iwcd1")) { /* select cross-word triphone computation method */
00645       tmparg = NEXTARG;
00646       if (strmatch(tmparg, "max")) { /* use maximum score in triphone variants */
00647         iwcdmethod = IWCD_MAX;
00648       } else if (strmatch(tmparg, "avg")) { /* use average in variants */
00649         iwcdmethod = IWCD_AVG;
00650       } else if (strmatch(tmparg, "best")) { /* use average in variants */
00651         iwcdmethod = IWCD_NBEST;
00652         tmparg = NEXTARG;
00653         iwcdmaxn = atoi(tmparg);
00654       } else {
00655         j_printerr("%s: -iwcd1: wrong argument (max|avg|best N): %s\n", argv[0], tmparg);
00656         opt_terminate();
00657       }
00658       continue;
00659     } else if (strmatch(argv[i],"-tmix")) { /* num of mixture to select */
00660       if (i + 1 < argc && isdigit(argv[i+1][0])) {
00661         mixnum_thres = atoi(argv[++i]);
00662       }
00663       continue;
00664     } else if (strmatch(argv[i],"-b2") || strmatch(argv[i],"-bw") || strmatch(argv[i],"-wb")) { /* word beam width in 2nd pass */
00665       enveloped_bestfirst_width = atoi(NEXTARG);
00666       continue;
00667     } else if (strmatch(argv[i],"-hgs")) { /* Gaussian selection model file */
00668       if (hmm_gs_filename) free(hmm_gs_filename);
00669       hmm_gs_filename = filepath(NEXTARG, cwd);
00670       continue;
00671     } else if (strmatch(argv[i],"-booknum")) { /* num of state to select in GS */
00672       gs_statenum = atoi(NEXTARG);
00673       continue;
00674     } else if (strmatch(argv[i],"-gshmm")) { /* same as "-hgs" */
00675       if (hmm_gs_filename) free(hmm_gs_filename);
00676       hmm_gs_filename = filepath(NEXTARG, cwd);
00677       continue;
00678     } else if (strmatch(argv[i],"-gsnum")) { /* same as "-booknum" */
00679       gs_statenum = atoi(NEXTARG);
00680       continue;
00681     } else if (strmatch(argv[i],"-cmnload")) { /* load CMN parameter from file */
00682       if (cmnload_filename) free(cmnload_filename);
00683       cmnload_filename = filepath(NEXTARG, cwd);
00684       continue;
00685     } else if (strmatch(argv[i],"-cmnsave")) { /* save CMN parameter to file */
00686       if (cmnsave_filename) free(cmnsave_filename);
00687       cmnsave_filename = filepath(NEXTARG, cwd);
00688       continue;
00689     } else if (strmatch(argv[i],"-cmnupdate")) { /* update CMN parameter */
00690       cmn_update = TRUE;
00691       continue;
00692     } else if (strmatch(argv[i],"-cmnnoupdate")) { /* not update CMN parameter */
00693       cmn_update = FALSE;
00694       continue;
00695     } else if (strmatch(argv[i],"-cmnmapweight")) { /* CMN weight for MAP */
00696       cmn_map_weight = (float)atof(NEXTARG);
00697       continue;
00698     } else if (strmatch(argv[i],"-sscalc")) { /* do spectral subtraction (SS) for raw file input */
00699       sscalc = TRUE;
00700       if (ssload_filename) free(ssload_filename);
00701       ssload_filename = NULL;
00702       continue;
00703     } else if (strmatch(argv[i],"-sscalclen")) { /* head silence length used to compute SS (in msec) */
00704       sscalc_len = atoi(NEXTARG);
00705       continue;
00706     } else if (strmatch(argv[i],"-ssload")) { /* load SS parameter from file */
00707       if (ssload_filename) free(ssload_filename);
00708       ssload_filename = filepath(NEXTARG, cwd);
00709       sscalc = FALSE;
00710       continue;
00711 #ifdef CONFIDENCE_MEASURE
00712     } else if (strmatch(argv[i],"-cmalpha")) { /* CM log score scaling factor */
00713 #ifdef CM_MULTIPLE_ALPHA
00714       cm_alpha_bgn = (LOGPROB)atof(NEXTARG);
00715       cm_alpha_end = (LOGPROB)atof(NEXTARG);
00716       cm_alpha_step = (LOGPROB)atof(NEXTARG);
00717       cm_alpha_num = (int)((cm_alpha_end - cm_alpha_bgn) / cm_alpha_step) + 1;
00718       if (cm_alpha_num > 100) j_error("too small step or wide range! outputnum > 100\n");
00719 #else
00720       cm_alpha = (LOGPROB)atof(NEXTARG);
00721 #endif
00722       continue;
00723 #ifdef CM_SEARCH_LIMIT
00724     } else if (strmatch(argv[i],"-cmthres")) { /* CM cut threshold for CM decoding */
00725       cm_cut_thres = (LOGPROB)atof(NEXTARG);
00726       continue;
00727 #endif
00728 #ifdef CM_SEARCH_LIMIT_POP
00729     } else if (strmatch(argv[i],"-cmthres2")) { /* CM cut threshold for CM decoding */
00730       cm_cut_thres_pop = (LOGPROB)atof(NEXTARG);
00731       continue;
00732 #endif
00733 #endif /* CONFIDENCE_MEASURE */
00734     } else if (strmatch(argv[i],"-gmm")) { /* load SS parameter from file */
00735       if (gmm_filename) free(gmm_filename);
00736       gmm_filename = filepath(NEXTARG, cwd);
00737       continue;
00738     } else if (strmatch(argv[i],"-gmmnum")) { /* num of Gaussian pruning for GMM */
00739       gmm_gprune_num = atoi(NEXTARG);
00740       continue;
00741     } else if (strmatch(argv[i],"-gmmreject")) {
00742       tmparg = NEXTARG;
00743       gmm_reject_cmn_string = strcpy((char *)mymalloc(strlen(tmparg)+1), tmparg);
00744       continue;
00745     } else if (strmatch(argv[i],"-htkconf")) {
00746       tmparg = NEXTARG;
00747       if (htk_config_file_parse(tmparg, &para_htk) == FALSE) {
00748         j_error("Error: failed to read %s\n", tmparg);
00749       }
00750       continue;
00751     } else if (strmatch(argv[i],"-help")) { /* output version and option */
00752       detailed_help();
00753     } else if (strmatch(argv[i],"--help")) {
00754       detailed_help();
00755     }
00756     if (argv[i][0] == '-' && strlen(argv[i]) == 2) {
00757       /* 1-letter options */
00758       switch(argv[i][1]) {
00759       case 'h':                 /* hmmdefs */
00760         if (hmmfilename) free(hmmfilename);
00761         hmmfilename = filepath(NEXTARG, cwd);
00762         break;
00763       case 'v':                 /* dictionary */
00764         if (dictfilename) free(dictfilename);
00765         dictfilename = filepath(NEXTARG, cwd);
00766         break;
00767 #ifdef USE_NGRAM
00768       case 'd':                 /* binary N-gram */
00769         if (ngram_filename) free(ngram_filename);
00770         if (ngram_filename_lr_arpa) free(ngram_filename_lr_arpa);
00771         if (ngram_filename_rl_arpa) free(ngram_filename_rl_arpa);
00772         ngram_filename = filepath(NEXTARG, cwd);
00773         ngram_filename_lr_arpa = NULL;
00774         ngram_filename_rl_arpa = NULL;
00775         break;
00776 #endif
00777       case 'b':                 /* beam width in 1st pass */
00778         specified_trellis_beam_width = atoi(NEXTARG);
00779         break;
00780       case 's':                 /* stack size in 2nd pass */
00781         stack_size = atoi(NEXTARG);
00782         break;
00783       case 'n':                 /* N-best search */
00784         nbest = atoi(NEXTARG);
00785         break;
00786       case 'm':                 /* upper limit of hypothesis generation */
00787         hypo_overflow = atoi(NEXTARG);
00788         break;
00789       default:
00790         j_printerr("%s: wrong argument: %s\n", argv[0], argv[i]);
00791         opt_terminate();
00792       }
00793     } else {                    /* error */
00794       j_printerr("%s: wrong argument: %s\n", argv[0], argv[i]);
00795       opt_terminate();
00796     }
00797   }
00798 
00799   /* set default values if not specified yet */
00800   if (!spmodel_name) {
00801     spmodel_name = strcpy((char*)mymalloc(strlen(SPMODEL_NAME_DEFAULT)+1),
00802                           SPMODEL_NAME_DEFAULT);
00803   }
00804 #ifdef USE_NGRAM
00805   if (!head_silname) {
00806     head_silname = strcpy((char*)mymalloc(strlen(BEGIN_WORD_DEFAULT)+1),
00807                           BEGIN_WORD_DEFAULT);
00808   }
00809   if (!tail_silname) {
00810     tail_silname = strcpy((char*)mymalloc(strlen(END_WORD_DEFAULT)+1),
00811                           END_WORD_DEFAULT);
00812   }
00813   if (!iwspentry) {
00814     iwspentry = strcpy((char*)mymalloc(strlen(IWSPENTRY_DEFAULT)+1),
00815                        IWSPENTRY_DEFAULT);
00816   }
00817 #endif  /* USE_NGRAM */
00818 #ifdef USE_NETAUDIO
00819   if (!netaudio_devname) {
00820     netaudio_devname = strcpy((char*)mymalloc(strlen(NETAUDIO_DEVNAME)+1),
00821                               NETAUDIO_DEVNAME);
00822   }
00823 #endif  /* USE_NETAUDIO */
00824 }
00825 
00834 void
00835 opt_release()
00836 {
00837   if (inputlist_filename) {
00838     free(inputlist_filename);
00839     inputlist_filename = NULL;
00840   }
00841   if (record_dirname) {
00842     free(record_dirname);
00843     record_dirname = NULL;
00844   }
00845 #ifdef CHARACTER_CONVERSION
00846   if (from_code) {
00847     free(from_code);
00848     from_code = NULL;
00849   }
00850   if (to_code) {
00851     free(to_code);
00852     to_code = NULL;
00853   }
00854 #endif  /* CHARACTER_CONVERSION */
00855   if (mapfilename) {
00856     free(mapfilename);
00857     mapfilename = NULL;
00858   }
00859 #ifdef USE_NGRAM
00860   if (ngram_filename) {
00861     free(ngram_filename);
00862     ngram_filename = NULL;
00863   }
00864   if (ngram_filename_lr_arpa) {
00865     free(ngram_filename_lr_arpa);
00866     ngram_filename_lr_arpa = NULL;
00867   }
00868   if (ngram_filename_rl_arpa) {
00869     free(ngram_filename_rl_arpa);
00870     ngram_filename_rl_arpa = NULL;
00871   }
00872 #endif  /* USE_NGRAM */
00873 #ifdef USE_DFA
00874   if (dfa_filename) {
00875     free(dfa_filename);
00876     dfa_filename = NULL;
00877   }
00878 #endif  /* USE_DFA */
00879   if (spmodel_name) {
00880     free(spmodel_name);
00881     spmodel_name = NULL;
00882   }
00883 #ifdef USE_NGRAM
00884   if (head_silname) {
00885     free(head_silname);
00886     head_silname = NULL;
00887   }
00888   if (tail_silname) {
00889     free(tail_silname);
00890     tail_silname = NULL;
00891   }
00892   if (iwspentry) {
00893     free(iwspentry);
00894     iwspentry = NULL;
00895   }
00896 #endif  /* USE_NGRAM */
00897 #ifdef USE_NETAUDIO
00898   if (netaudio_devname) {
00899     free(netaudio_devname);
00900     netaudio_devname = NULL;
00901   }
00902 #endif  /* USE_NETAUDIO */
00903   if (hmm_gs_filename) {
00904     free(hmm_gs_filename);
00905     hmm_gs_filename = NULL;
00906   }
00907   if (cmnload_filename) {
00908     free(cmnload_filename);
00909     cmnload_filename = NULL;
00910   }
00911   if (cmnsave_filename) {
00912     free(cmnsave_filename);
00913     cmnsave_filename = NULL;
00914   }
00915   if (ssload_filename) {
00916     free(ssload_filename);
00917     ssload_filename = NULL;
00918   }
00919   if (gmm_filename) {
00920     free(gmm_filename);
00921     gmm_filename = NULL;
00922   }
00923   if (gmm_reject_cmn_string) {
00924     free(gmm_reject_cmn_string);
00925     gmm_reject_cmn_string = NULL;
00926   }
00927   if (hmmfilename) {
00928     free(hmmfilename);
00929     hmmfilename = NULL;
00930   }
00931   if (dictfilename) {
00932     free(dictfilename);
00933     dictfilename = NULL;
00934   }
00935 }

Generated on Tue Dec 26 12:53:21 2006 for Julian by  doxygen 1.5.0