julius/m_chkparam.c

説明を見る。
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 
00038 void
00039 checkpath(char *filename)
00040 {
00041   if (access(filename, R_OK) == -1) {
00042     perror("checkpath");
00043     j_error("%s: cannot access %s\n", EXECNAME, filename);
00044   }
00045 }
00046 
00059 static void
00060 checkdir(char *dirname)
00061 {
00062   if (access(dirname, R_OK | W_OK | X_OK) == -1) {
00063     perror("checkdir");
00064     j_error("%s: cannot write to dir %s\n", EXECNAME, dirname);
00065   }
00066 }
00067 
00086 void
00087 check_specs()
00088 {
00089   boolean ok_p;
00090 
00091   VERMES("###### check configurations\n");
00092 
00093   /* check if needed files are specified */
00094   ok_p = TRUE;
00095   if (hmmfilename == NULL) {
00096     j_printerr("Error: needs HMM definition file (-h hmmdef_file)\n");
00097     ok_p = FALSE;
00098   }
00099 #ifdef USE_NGRAM
00100   if (dictfilename == NULL) {
00101     j_printerr("Error: needs dictionary file (-v dict_file)\n");
00102     ok_p = FALSE;
00103   }
00104   /* only LR 2-gram specified .... calculate only 1-pass */
00105   /* only RL 3-gram specified .... ERROR */
00106   if (ngram_filename == NULL) {
00107     if (ngram_filename_lr_arpa == NULL && ngram_filename_rl_arpa == NULL) {
00108       j_printerr("Error: needs word n-gram file (-d bingram | -nlr ARPA_2gram -nrl ARPA_r3gram)\n");
00109       ok_p = FALSE;
00110     } else if (ngram_filename_lr_arpa == NULL) {
00111       j_printerr("Error: also needs ARPA 2-gram file (-nlr ARPA_2gram_file)\n");
00112       ok_p = FALSE;
00113     } else if (ngram_filename_rl_arpa == NULL) {
00114       compute_only_1pass = TRUE;
00115     }
00116   }
00117 #else  /* USE_DFA */
00118   if (!module_mode) {
00119     if (gramlist_root == NULL) {
00120       if (dfa_filename == NULL) {
00121         j_printerr("Error: needs DFA grammar file (-dfa file)\n");
00122         j_printerr("Error: or specify grammar prefix (-gram prefix | -gramlist listfile)\n");
00123         ok_p = FALSE;
00124       }
00125       if (dictfilename == NULL) {
00126         j_printerr("Error: needs dictionary file (-v file)\n");
00127         j_printerr("Error: or specify grammar prefix (-gram prefix | -gramlist listfile)\n");
00128         ok_p = FALSE;
00129       }
00130     }
00131   }
00132 #endif
00133 
00134   /* file existence check */
00135   if (hmmfilename != NULL) checkpath(hmmfilename);
00136   if (mapfilename != NULL) checkpath(mapfilename);
00137   if (dictfilename != NULL) checkpath(dictfilename);
00138 #ifdef USE_NGRAM
00139   if (ngram_filename != NULL) checkpath(ngram_filename);
00140   if (ngram_filename_lr_arpa != NULL) checkpath(ngram_filename_lr_arpa);
00141   if (ngram_filename_rl_arpa != NULL) checkpath(ngram_filename_rl_arpa);
00142 #else
00143   if (dfa_filename != NULL) checkpath(dfa_filename);
00144 #endif
00145   if (hmm_gs_filename != NULL) checkpath(hmm_gs_filename);
00146   if (gmm_filename != NULL) checkpath(gmm_filename);
00147   if (inputlist_filename != NULL) {
00148     if (speech_input != SP_RAWFILE && speech_input != SP_MFCFILE) {
00149       j_printerr("Warning: not file input, \"-filelist %s\" ignored\n", inputlist_filename);
00150     } else {
00151       checkpath(inputlist_filename);
00152     }
00153   }
00154   /* cmn{save,load}_filename allows missing file (skipped if missing) */
00155   if (ssload_filename != NULL) checkpath(ssload_filename);
00156 
00157   /* check if record dir exists */
00158   if (record_dirname != NULL) checkdir(record_dirname);
00159 
00160   /* set default realtime flag according to input mode */
00161   if (force_realtime_flag) {
00162     if (speech_input == SP_MFCFILE) {
00163       j_printerr("Warning: realtime decoding of mfcfile is not supported yet\n");
00164       j_printerr("Warning: -realtime turned off\n");
00165       realtime_flag = FALSE;
00166     } else {
00167       realtime_flag = forced_realtime;
00168     }
00169   }
00170 
00171   /* check for cmn */
00172   if (realtime_flag) {
00173     if (cmn_update == FALSE && cmnload_filename == NULL) {
00174       j_error("Error: when \"-cmnnoupdate\", initial cepstral mean should be given by \"-cmnload\"\n");
00175     }
00176   }
00177 
00178 #ifdef CONFIDENCE_MEASURE
00179 #ifdef CM_MULTIPLE_ALPHA
00180   if (module_mode) {
00181     j_error("module mode conflicts with \"--enable-cm-multiple-alpha\"!\n");
00182   }
00183 #endif
00184 #endif /* CONFIDENCE_MEASURE */
00185 
00186   if (!ok_p) {
00187     j_error("check spec failed\n");            /* exit on error */
00188   }
00189 }
00190 
00191 /******* set default params suitable for the models and setting *******/
00192 
00217 static int
00218 default_width()
00219 {
00220   if (strmatch(SETUP, "fast")) { /* for fast setup */
00221     if (hmminfo->is_triphone) {
00222       if (hmminfo->is_tied_mixture) {
00223         /* tied-mixture triphones (PTM etc.) */
00224         return(600);
00225       } else {
00226         /* shared-state triphone */
00227 #ifdef PASS1_IWCD
00228         return(800);
00229 #else
00230         /* v2.1 compliant (no IWCD on 1st pass) */
00231         return(1000);           
00232 #endif
00233       }
00234     } else {
00235       /* monophone */
00236       return(400);
00237     }
00238   } else {                      /* for standard / v2.1 setup */
00239     if (hmminfo->is_triphone) {
00240       if (hmminfo->is_tied_mixture) {
00241         /* tied-mixture triphones (PTM etc.) */
00242         return(800);
00243       } else {
00244         /* shared-state triphone */
00245 #ifdef PASS1_IWCD
00246         return(1500);
00247 #else
00248         return(1500);           /* v2.1 compliant (no IWCD on 1st pass) */
00249 #endif
00250       }
00251     } else {
00252       /* monophone */
00253       return(700);
00254     }
00255   }
00256 }
00257 
00282 int
00283 set_beam_width(WCHMM_INFO *wchmm, int specified)
00284 {
00285   int width;
00286   int standard_width;
00287   
00288   if (specified == 0) { /* full search */
00289     VERMES("doing full search\n");
00290     VERMES("Warning: this can be extremely slow\n");
00291     width = wchmm->n;
00292   } else if (specified == -1) { /* not specified */
00293     standard_width = default_width(); /* system default */
00294     width = (int)(sqrt(wchmm->winfo->num) * 15.0); /* heuristic value!! */
00295     if (width > standard_width) width = standard_width;
00296   } else {                      /* actual value has been specified */
00297     width = specified;
00298   }
00299   if (width > wchmm->n) width = wchmm->n;
00300 
00301   return(width);
00302 }
00303 
00304 #ifdef USE_NGRAM
00305 
00317 void
00318 set_lm_weight()
00319 {
00320   if (hmminfo->is_triphone) {
00321     lm_weight = DEFAULT_LM_WEIGHT_TRI_PASS1;
00322     lm_penalty = DEFAULT_LM_PENALTY_TRI_PASS1;
00323   } else {
00324     lm_weight = DEFAULT_LM_WEIGHT_MONO_PASS1;
00325     lm_penalty = DEFAULT_LM_PENALTY_MONO_PASS1;
00326   }
00327 }
00328 
00341 void
00342 set_lm_weight2()
00343 {
00344   if (hmminfo->is_triphone) {
00345     lm_weight2 = DEFAULT_LM_WEIGHT_TRI_PASS2;
00346     lm_penalty2 = DEFAULT_LM_PENALTY_TRI_PASS2;
00347   } else {
00348     lm_weight2 = DEFAULT_LM_WEIGHT_MONO_PASS2;
00349     lm_penalty2 = DEFAULT_LM_PENALTY_MONO_PASS2;
00350   }
00351 }
00352     
00353 #endif /* USE_NGRAM */

Juliusに対してTue Dec 26 16:19:27 2006に生成されました。  doxygen 1.5.0