int ps_load_dict(ps_decoder_t *ps, char const *dictfile, char const *fdictfile, char const *format) { cmd_ln_t *newconfig; dict2pid_t *d2p; dict_t *dict; hash_iter_t *search_it; /* Create a new scratch config to load this dict (so existing one * won't be affected if it fails) */ newconfig = cmd_ln_init(NULL, ps_args(), TRUE, NULL); cmd_ln_set_boolean_r(newconfig, "-dictcase", cmd_ln_boolean_r(ps->config, "-dictcase")); cmd_ln_set_str_r(newconfig, "-dict", dictfile); if (fdictfile) cmd_ln_set_str_r(newconfig, "-fdict", fdictfile); else cmd_ln_set_str_r(newconfig, "-fdict", cmd_ln_str_r(ps->config, "-fdict")); /* Try to load it. */ if ((dict = dict_init(newconfig, ps->acmod->mdef, ps->acmod->lmath)) == NULL) { cmd_ln_free_r(newconfig); return -1; } /* Reinit the dict2pid. */ if ((d2p = dict2pid_build(ps->acmod->mdef, dict)) == NULL) { cmd_ln_free_r(newconfig); return -1; } /* Success! Update the existing config to reflect new dicts and * drop everything into place. */ cmd_ln_free_r(newconfig); cmd_ln_set_str_r(ps->config, "-dict", dictfile); if (fdictfile) cmd_ln_set_str_r(ps->config, "-fdict", fdictfile); dict_free(ps->dict); ps->dict = dict; dict2pid_free(ps->d2p); ps->d2p = d2p; /* And tell all searches to reconfigure themselves. */ for (search_it = hash_table_iter(ps->searches); search_it; search_it = hash_table_iter_next(search_it)) { if (ps_search_reinit(hash_entry_val(search_it->ent), dict, d2p) < 0) { hash_table_iter_free(search_it); return -1; } } return 0; }
int ps_load_dict(ps_decoder_t *ps, char const *dictfile, char const *fdictfile, char const *format) { cmd_ln_t *newconfig; dict2pid_t *d2p; dict_t *dict; gnode_t *gn; int rv; /* Create a new scratch config to load this dict (so existing one * won't be affected if it fails) */ newconfig = cmd_ln_init(NULL, ps_args(), TRUE, NULL); cmd_ln_set_boolean_r(newconfig, "-dictcase", cmd_ln_boolean_r(ps->config, "-dictcase")); cmd_ln_set_str_r(newconfig, "-dict", dictfile); if (fdictfile) cmd_ln_set_str_r(newconfig, "-fdict", fdictfile); else cmd_ln_set_str_r(newconfig, "-fdict", cmd_ln_str_r(ps->config, "-fdict")); /* Try to load it. */ if ((dict = dict_init(newconfig, ps->acmod->mdef)) == NULL) { cmd_ln_free_r(newconfig); return -1; } /* Reinit the dict2pid. */ if ((d2p = dict2pid_build(ps->acmod->mdef, dict)) == NULL) { cmd_ln_free_r(newconfig); return -1; } /* Success! Update the existing config to reflect new dicts and * drop everything into place. */ cmd_ln_free_r(newconfig); cmd_ln_set_str_r(ps->config, "-dict", dictfile); if (fdictfile) cmd_ln_set_str_r(ps->config, "-fdict", fdictfile); dict_free(ps->dict); ps->dict = dict; dict2pid_free(ps->d2p); ps->d2p = d2p; /* And tell all searches to reconfigure themselves. */ for (gn = ps->searches; gn; gn = gnode_next(gn)) { ps_search_t *search = gnode_ptr(gn); if ((rv = ps_search_reinit(search, dict, d2p)) < 0) return rv; } return 0; }
static void ps_expand_model_config(ps_decoder_t *ps) { char const *hmmdir, *featparams; /* Disable memory mapping on Blackfin (FIXME: should be uClinux in general). */ #ifdef __ADSPBLACKFIN__ E_INFO("Will not use mmap() on uClinux/Blackfin."); cmd_ln_set_boolean_r(ps->config, "-mmap", FALSE); #endif /* Get acoustic model filenames and add them to the command-line */ if ((hmmdir = cmd_ln_str_r(ps->config, "-hmm")) != NULL) { ps_add_file(ps, "-mdef", hmmdir, "mdef"); ps_add_file(ps, "-mean", hmmdir, "means"); ps_add_file(ps, "-var", hmmdir, "variances"); ps_add_file(ps, "-tmat", hmmdir, "transition_matrices"); ps_add_file(ps, "-mixw", hmmdir, "mixture_weights"); ps_add_file(ps, "-sendump", hmmdir, "sendump"); ps_add_file(ps, "-fdict", hmmdir, "noisedict"); ps_add_file(ps, "-lda", hmmdir, "feature_transform"); ps_add_file(ps, "-featparams", hmmdir, "feat.params"); ps_add_file(ps, "-senmgau", hmmdir, "senmgau"); } /* Look for feat.params in acoustic model dir. */ if ((featparams = cmd_ln_str_r(ps->config, "-featparams"))) { if (NULL != cmd_ln_parse_file_r(ps->config, feat_defn, featparams, FALSE)) E_INFO("Parsed model-specific feature parameters from %s\n", featparams); } /* Print here because acmod_init might load feat.params file */ if (err_get_logfp() != NULL) { cmd_ln_print_values_r(ps->config, err_get_logfp(), ps_args()); } }
static void ps_init_defaults(ps_decoder_t *ps) { /* Disable memory mapping on Blackfin (FIXME: should be uClinux in general). */ #ifdef __ADSPBLACKFIN__ E_INFO("Will not use mmap() on uClinux/Blackfin."); cmd_ln_set_boolean_r(ps->config, "-mmap", FALSE); #endif char const *hmmdir; /* Get acoustic model filenames and add them to the command-line */ if ((hmmdir = cmd_ln_str_r(ps->config, "-hmm")) != NULL) { ps_add_file(ps, "-mdef", hmmdir, "mdef"); ps_add_file(ps, "-mean", hmmdir, "means"); ps_add_file(ps, "-var", hmmdir, "variances"); ps_add_file(ps, "-tmat", hmmdir, "transition_matrices"); ps_add_file(ps, "-mixw", hmmdir, "mixture_weights"); ps_add_file(ps, "-sendump", hmmdir, "sendump"); ps_add_file(ps, "-fdict", hmmdir, "noisedict"); ps_add_file(ps, "-lda", hmmdir, "feature_transform"); ps_add_file(ps, "-featparams", hmmdir, "feat.params"); ps_add_file(ps, "-senmgau", hmmdir, "senmgau"); } }
static void gst_pocketsphinx_set_boolean(GstPocketSphinx *ps, const gchar *key, const GValue *value) { cmd_ln_set_boolean_r(ps->config, key, g_value_get_boolean(value)); }
SWIGINTERN void Config_setBoolean(Config *self,char const *key,bool val){ cmd_ln_set_boolean_r(self, key, val); }
static void ps_init_defaults(ps_decoder_t *ps) { char const *hmmdir, *lmfile, *dictfile; /* Disable memory mapping on Blackfin (FIXME: should be uClinux in general). */ #ifdef __ADSPBLACKFIN__ E_INFO("Will not use mmap() on uClinux/Blackfin."); cmd_ln_set_boolean_r(ps->config, "-mmap", FALSE); #endif #ifdef MODELDIR /* Set default acoustic and language models. */ hmmdir = cmd_ln_str_r(ps->config, "-hmm"); lmfile = cmd_ln_str_r(ps->config, "-lm"); dictfile = cmd_ln_str_r(ps->config, "-dict"); if (hmmdir == NULL && hmmdir_exists(MODELDIR "/hmm/en_US/hub4wsj_sc_8k")) { hmmdir = MODELDIR "/hmm/en_US/hub4wsj_sc_8k"; cmd_ln_set_str_r(ps->config, "-hmm", hmmdir); } if (lmfile == NULL && !cmd_ln_str_r(ps->config, "-fsg") && !cmd_ln_str_r(ps->config, "-jsgf") && file_exists(MODELDIR "/lm/en_US/hub4.5000.DMP")) { lmfile = MODELDIR "/lm/en_US/hub4.5000.DMP"; cmd_ln_set_str_r(ps->config, "-lm", lmfile); } if (dictfile == NULL && file_exists(MODELDIR "/lm/en_US/cmu07a.dic")) { dictfile = MODELDIR "/lm/en_US/cmu07a.dic"; cmd_ln_set_str_r(ps->config, "-dict", dictfile); } /* Expand acoustic and language model filenames relative to installation path. */ if (hmmdir && !path_is_absolute(hmmdir) && !hmmdir_exists(hmmdir)) { char *tmphmm = string_join(MODELDIR "/hmm/", hmmdir, NULL); cmd_ln_set_str_r(ps->config, "-hmm", tmphmm); ckd_free(tmphmm); } if (lmfile && !path_is_absolute(lmfile) && !file_exists(lmfile)) { char *tmplm = string_join(MODELDIR "/lm/", lmfile, NULL); cmd_ln_set_str_r(ps->config, "-lm", tmplm); ckd_free(tmplm); } if (dictfile && !path_is_absolute(dictfile) && !file_exists(dictfile)) { char *tmpdict = string_join(MODELDIR "/lm/", dictfile, NULL); cmd_ln_set_str_r(ps->config, "-dict", tmpdict); ckd_free(tmpdict); } #endif /* Get acoustic model filenames and add them to the command-line */ if ((hmmdir = cmd_ln_str_r(ps->config, "-hmm")) != NULL) { ps_add_file(ps, "-mdef", hmmdir, "mdef"); ps_add_file(ps, "-mean", hmmdir, "means"); ps_add_file(ps, "-var", hmmdir, "variances"); ps_add_file(ps, "-tmat", hmmdir, "transition_matrices"); ps_add_file(ps, "-mixw", hmmdir, "mixture_weights"); ps_add_file(ps, "-sendump", hmmdir, "sendump"); ps_add_file(ps, "-fdict", hmmdir, "noisedict"); ps_add_file(ps, "-lda", hmmdir, "feature_transform"); ps_add_file(ps, "-featparams", hmmdir, "feat.params"); ps_add_file(ps, "-senmgau", hmmdir, "senmgau"); } }
SWIGINTERN void cmd_ln_s_setBoolean(struct cmd_ln_s *self,char const *key,bool val){ cmd_ln_set_boolean_r(self, key, val); }