int main(int argc, char *argv[]) { logmath_t *lmath; cmd_ln_t *config; acmod_t *acmod; ps_mgau_t *ps; ptm_mgau_t *s; int i, lastcb; lmath = logmath_init(1.0001, 0, 0); config = cmd_ln_init(NULL, ps_args(), TRUE, "-compallsen", "yes", "-input_endian", "little", NULL); cmd_ln_parse_file_r(config, ps_args(), MODELDIR "/en-us/en-us/feat.params", FALSE); cmd_ln_set_str_extra_r(config, "_mdef", MODELDIR "/en-us/en-us/mdef"); cmd_ln_set_str_extra_r(config, "_mean", MODELDIR "/en-us/en-us/means"); cmd_ln_set_str_extra_r(config, "_var", MODELDIR "/en-us/en-us/variances"); cmd_ln_set_str_extra_r(config, "_tmat", MODELDIR "/en-us/en-us/transition_matrices"); cmd_ln_set_str_extra_r(config, "_sendump", MODELDIR "/en-us/en-us/sendump"); cmd_ln_set_str_extra_r(config, "_mixw", NULL); cmd_ln_set_str_extra_r(config, "_lda", NULL); cmd_ln_set_str_extra_r(config, "_senmgau", NULL); err_set_debug_level(3); TEST_ASSERT(config); TEST_ASSERT((acmod = acmod_init(config, lmath, NULL, NULL))); TEST_ASSERT((ps = acmod->mgau)); TEST_EQUAL(0, strcmp(ps->vt->name, "ptm")); s = (ptm_mgau_t *)ps; E_DEBUG(2,("PTM model loaded: %d codebooks, %d senones, %d frames of history\n", s->g->n_mgau, s->n_sen, s->n_fast_hist)); E_DEBUG(2,("Senone to codebook mappings:\n")); lastcb = s->sen2cb[0]; E_DEBUG(2,("\t%d: 0", lastcb)); for (i = 0; i < s->n_sen; ++i) { if (s->sen2cb[i] != lastcb) { lastcb = s->sen2cb[i]; E_DEBUGCONT(2,("-%d\n", i-1)); E_DEBUGCONT(2,("\t%d: %d", lastcb, i)); } } E_INFOCONT("-%d\n", i-1); run_acmod_test(acmod); #if 0 /* Replace it with ms_mgau. */ ptm_mgau_free(ps); cmd_ln_set_str_r(config, "-mixw", MODELDIR "/en-us/en-us/mixture_weights"); TEST_ASSERT((acmod->mgau = ms_mgau_init(acmod, lmath, acmod->mdef))); run_acmod_test(acmod); cmd_ln_free_r(config); #endif return 0; }
int main(int argc, char *argv[]) { ps_decoder_t *ps; cmd_ln_t *config; TEST_ASSERT(config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-lm", MODELDIR "/lm/en_US/wsj0vp.5000.DMP", "-dict", MODELDIR "/lm/en_US/cmu07a.dic", "-fwdtree", "yes", "-fwdflat", "yes", "-bestpath", "yes", "-input_endian", "little", "-samprate", "16000", NULL)); TEST_ASSERT(ps = ps_init(config)); TEST_ASSERT(config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en/tidigits", "-lm", MODELDIR "/lm/en/tidigits.DMP", "-dict", MODELDIR "/lm/en/tidigits.dic", "-fwdtree", "yes", "-fwdflat", "yes", "-bestpath", "yes", "-input_endian", "little", "-samprate", "16000", NULL)); TEST_EQUAL(0, ps_reinit(ps, config)); ps_free(ps); return 0; }
int main(int argc, char *argv[]) { int go = 1; const char *lang = argv[1]; const char *rawFile = argv[2]; cmd_ln_t *config; // Configure recognizer for English or Spanish if (strcmp(lang, "engl") == 0) { config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-lm", MODELDIR "/en-us/en-us.lm.bin", "-dict", MODELDIR "/en-us/cmudict-en-us.dict", NULL); } else if (strcmp(lang, "span") == 0) { config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", "/home/pi/es_MX_broadcast_cont_2500/model_parameters/hub4_spanish_itesm.cd_cont_2500", "-lm", "/home/pi/es_MX_broadcast_cont_2500/etc/H4.arpa.Z.DMP", "-dict", "/home/pi/es_MX_broadcast_cont_2500/etc/h4.dict", NULL); } if (config == NULL) { fprintf(stderr, "Failed to create config object, see log for details\n"); return -1; } // Initialize pocketsphinx ps = ps_init(config); if (ps == NULL) { fprintf(stderr, "Failed to create recognizer, see log for details\n"); return -1; } fflush(stdout); // Wait for signal from stdin while (1) { // Waiting for command scanf("%d", &go); if (go) { processRaw(rawFile); } else break; } // free memory ps_free(ps); cmd_ln_free_r(config); return 0; }
static void gst_pocketsphinx_init(GstPocketSphinx * ps, GstPocketSphinxClass * gclass) { ps->sinkpad = gst_pad_new_from_static_template(&sink_factory, "sink"); ps->srcpad = gst_pad_new_from_static_template(&src_factory, "src"); /* Create the hash table to store argument strings. */ ps->arghash = g_hash_table_new(g_str_hash, g_str_equal); /* Parse default command-line options. */ ps->config = cmd_ln_parse_r(NULL, ps_args(), default_argc, default_argv, FALSE); /* Set up pads. */ gst_element_add_pad(GST_ELEMENT(ps), ps->sinkpad); gst_pad_set_chain_function(ps->sinkpad, gst_pocketsphinx_chain); gst_pad_set_event_function(ps->sinkpad, gst_pocketsphinx_event); gst_pad_use_fixed_caps(ps->sinkpad); gst_element_add_pad(GST_ELEMENT(ps), ps->srcpad); gst_pad_use_fixed_caps(ps->srcpad); /* Initialize time. */ ps->last_result_time = 0; ps->last_result = NULL; /* Nbest size */ ps->n_best_size = 10; }
static cmd_ln_t * default_config() { return cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-dict", MODELDIR "/en-us/cmudict-en-us.dict", NULL); }
int main(int argc, char *argv[]) { cmd_ln_t *config; ps_decoder_t *ps; FILE *rawfh; char const *hyp; char const *uttid; int32 score; TEST_ASSERT(config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", DATADIR "/an4_ci_cont", "-lm", MODELDIR "/lm/en/turtle.DMP", "-dict", MODELDIR "/lm/en/turtle.dic", "-mllr", DATADIR "/mllr_matrices", "-samprate", "16000", NULL)); TEST_ASSERT(ps = ps_init(config)); TEST_ASSERT(rawfh = fopen(DATADIR "/goforward.raw", "rb")); ps_decode_raw(ps, rawfh, "goforward", -1); fclose(rawfh); hyp = ps_get_hyp(ps, &score, &uttid); printf("FWDFLAT (%s): %s (%d)\n", uttid, hyp, score); ps_free(ps); cmd_ln_free_r(config); return 0; }
void* sphinx_gui_listen_main(void *arg) { int outfd = (int)arg; char const *cfg; char hmm[256]; char lm[256]; char dict[256]; snprintf(hmm, 256, "%s/%s", modeldir, hmmdir); snprintf(lm, 256, "%s/%s", modeldir, lmdump); snprintf(dict, 256, "%s/%s", modeldir, lmdict); config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", hmm, "-lm", lm, "-dict", dict, NULL); if (config == NULL) return NULL; ps = ps_init(config); if (ps == NULL) return NULL; recognize_from_microphone(outfd); ps_free(ps); return NULL; }
bool GqAndroidSphinx::init_sphinx(IGqRecord *precord) { m_pconfig = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", m_shmm.c_str(), "-lm", m_slm.c_str(), "-dict", m_sdict.c_str(), NULL); if (m_pconfig == NULL) { return false; } if (m_pdecoder) { LOGD("m_pdecoder"); ps_free(m_pdecoder); m_pdecoder = NULL; } m_pdecoder = ps_init(m_pconfig); if (m_pdecoder == 0) { return false; } if (m_precord) { LOGD("delete m_precord;"); m_precord->stop_record(); delete m_precord; m_precord = NULL; } m_precord = precord; m_precord->set_record_cb(this); m_precord->init_recorder(); LOGD("after init_recorder"); return true; }
int main(int argc, char *argv[]) { cmd_ln_t *config; logmath_t *lmath; acmod_t *acmod[5]; sbthread_t *thr[5]; featbuf_t *fb; FILE *raw; int16 buf[2048]; int nsamp; int i; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", TESTDATADIR "/hub4wsj_sc_8k", "-lm", TESTDATADIR "/bn10000.3g.arpa", "-dict", TESTDATADIR "/bn10000.dic", "-compallsen", "yes", NULL); ps_init_defaults(config); fb = featbuf_init(config); TEST_ASSERT(fb); lmath = logmath_init(cmd_ln_float32_r(config, "-logbase"), 0, FALSE); acmod[0] = acmod_init(config, lmath, fb); TEST_ASSERT(acmod[0]); /* Create a couple threads to pull features out of it. */ for (i = 0; i < 5; ++i) { if (i != 0) acmod[i] = acmod_copy(acmod[0]); thr[i] = sbthread_start(NULL, consumer, acmod[i]); } /* Feed them some data. */ raw = fopen(TESTDATADIR "/chan3.raw", "rb"); featbuf_producer_start_utt(fb, "chan3"); while ((nsamp = fread(buf, 2, 2048, raw)) > 0) { int rv; rv = featbuf_producer_process_raw(fb, buf, nsamp, FALSE); printf("Producer processed %d samples\n", nsamp); TEST_ASSERT(rv > 0); } fclose(raw); printf("Waiting for consumers\n"); featbuf_producer_end_utt(fb); printf("Finished waiting\n"); /* Reap those threads. */ for (i = 0; i < 5; ++i) { sbthread_wait(thr[i]); sbthread_free(thr[i]); acmod_free(acmod[i]); printf("Reaped consumer %p\n", acmod[i]); } featbuf_free(fb); logmath_free(lmath); cmd_ln_free_r(config); return 0; }
static av_cold int asr_init(AVFilterContext *ctx) { ASRContext *s = ctx->priv; const float frate = s->rate; char *rate = av_asprintf("%f", frate); const char *argv[] = { "-logfn", s->logfn, "-hmm", s->hmm, "-lm", s->lm, "-lmctl", s->lmctl, "-lmname", s->lmname, "-dict", s->dict, "-samprate", rate, NULL }; s->config = cmd_ln_parse_r(NULL, ps_args(), 14, (char **)argv, 0); av_free(rate); if (!s->config) return AVERROR(ENOMEM); ps_default_search_args(s->config); s->ps = ps_init(s->config); if (!s->ps) return AVERROR(ENOMEM); return 0; }
int main(int argc, char* argv[]) { /*FILE *fh;*/ /*int rv;*/ /*char const *hyp, *uttid;*/ /*int16 buf[512];*/ if (argc < 2) { printf("Usage: %s <config.gram>\n", argv[0]); return 0; } config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-lm", MODELDIR "/lm/en_US/wsj0vp.5000.DMP", "-dict", MODELDIR "/lm/en_US/cmu07a.dic", "-jsgf", argv[1], NULL); /*config = cmd_ln_parse_file_r(NULL, ps_args(), "config.es", FALSE);*/ if ( config == NULL ) return 1; ps = ps_init(config); if ( ps == NULL ) { printf("Unable to allocate decoder.\n"); return 1; } recognize_from_microphone(); // Cleaning up ps_free(ps); return 0; }
int run(CallbackType callback, char* kpath) { //string path ="C:/Users/Reza/Documents/GitHub/speech_agent/speech/Release/"; listenCallback = callback; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", "C:/Users/Reza/Documents/GitHub/speech_agent/speech/Release/model/en-us/en-us", //"-lm","C:/Users/Reza/Documents/GitHub/speech_agent/speech/Release/model/en-us/en-us.lm.dmp", //"-lm","C:/Users/Reza/Documents/GitHub/speech_agent/speech/Release/cristina.lm", //"-jsgf", "grammar.gram", "-vad_threshold","3", "-kws", kpath, "-dict", "C:/Users/Reza/Documents/GitHub/speech_agent/speech/Release/model/en-us/cmudict-en-us2.dict", //"-beam", "1e-20", "-pbeam", "1e-20", "-lw", "2.0", //"-logfn","model", NULL); if (config == NULL) return -1; ps = ps_init(config); if (ps == NULL) return -1; recognize_from_mic(); //recognize_from_file(); ps_free(ps); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { ps_decoder_t *ps; cmd_ln_t *config; int rv; TEST_ASSERT(config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-lm", MODELDIR "/en-us/en-us.lm.dmp", "-dict", MODELDIR "/en-us/cmudict-en-us.dict", "-fwdtree", "yes", "-fwdflat", "no", "-bestpath", "yes", "-input_endian", "little", "-cmninit", "37", "-samprate", "16000", NULL)); TEST_ASSERT(ps = ps_init(config)); rv = test_decode(ps); ps_free(ps); cmd_ln_free_r(config); return rv; }
static void gst_pocketsphinx_init(GstPocketSphinx * ps) { ps->sinkpad = gst_pad_new_from_static_template(&sink_factory, "sink"); ps->srcpad = gst_pad_new_from_static_template(&src_factory, "src"); /* Parse default command-line options. */ ps->config = cmd_ln_parse_r(NULL, ps_args(), default_argc, default_argv, FALSE); ps_default_search_args(ps->config); ps->ps = ps_init(ps->config); if (ps->ps == NULL) { GST_ELEMENT_ERROR(GST_ELEMENT(ps), LIBRARY, INIT, ("Failed to initialize PocketSphinx"), ("Failed to initialize PocketSphinx")); } /* Set up pads. */ gst_element_add_pad(GST_ELEMENT(ps), ps->sinkpad); gst_pad_set_chain_function(ps->sinkpad, gst_pocketsphinx_chain); gst_pad_set_event_function(ps->sinkpad, gst_pocketsphinx_event); gst_pad_use_fixed_caps(ps->sinkpad); gst_element_add_pad(GST_ELEMENT(ps), ps->srcpad); gst_pad_use_fixed_caps(ps->srcpad); /* Initialize time. */ ps->last_result_time = 0; ps->last_result = NULL; }
bool FSpeechRecognitionWorker::Init() { std::string modelPath = contentPath_str + "model/" + langStr + "/" + langStr; std::string languageModel = contentPath_str + "model/" + langStr + "/" + langStr + ".lm.bin"; std::string dictionaryPath = contentPath_str + "model/" + langStr + "/" + langStr + ".dict"; // load dictionary dictionaryMap.clear(); std::ifstream file(dictionaryPath); std::vector<std::string> words; std::string currentLine; while (file.good()) { std::getline(file, currentLine); std::string word = currentLine.substr(0, currentLine.find(" ")); std::string phrase = currentLine.substr(currentLine.find(" ") + 1, currentLine.size()); dictionaryMap.insert(make_pair(word, phrase)); } // Start Sphinx config = cmd_ln_init(NULL, ps_args(), 1, "-hmm", modelPath.c_str(), "-lm", languageModel.c_str(), NULL); ps = ps_init(config); if (!Manager | !ps) { ClientMessage(FString(TEXT("Speech Recognition Thread failed to start"))); initSuccess = false; return false; } // only include the words/phrases that have been added for (auto It = dictionaryList.CreateConstIterator(); It; ++It) { FString word = *It; std::string wordStr = std::string(TCHAR_TO_UTF8(*word)); if (dictionaryMap.find(wordStr) != dictionaryMap.end()) { std::string phraseStr = dictionaryMap.at(wordStr); ps_add_word(ps, wordStr.c_str(), phraseStr.c_str(), TRUE); } } // attempt to open the default recording device if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int)cmd_ln_float32_r(config, "-samprate"))) == NULL) { ClientMessage(FString(TEXT("Failed to open audio device"))); initSuccess = false; return initSuccess; } utt_started = 0; return true; }
int main(int argc, char *argv[]) { ps_decoder_t *ps; cmd_ln_t *config; FILE *fh; char const *hyp, *uttid; int16 buf[512]; int rv; int32 score; //int i; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-lm", MODELDIR "/lm/en/turtle.DMP", "-dict", MODELDIR "/lm/en/turtle.dic", NULL); if (config == NULL) return 1; ps = ps_init(config); if (ps == NULL) return 1; fh = fopen("goforward.raw", "rb"); if (fh == NULL) { perror("Failed to open goforward.raw"); return 1; } rv = ps_decode_raw(ps, fh, "goforward", -1); if (rv < 0) return 1; hyp = ps_get_hyp(ps, &score, &uttid); if (hyp == NULL) return 1; printf("Recognized: %s\n", hyp); fseek(fh, 0, SEEK_SET); rv = ps_start_utt(ps, "goforward"); if (rv < 0) return 1; while (!feof(fh)) { size_t nsamp; nsamp = fread(buf, 2, 512, fh); rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE); } rv = ps_end_utt(ps); if (rv < 0) return 1; hyp = ps_get_hyp(ps, &score, &uttid); if (hyp == NULL) return 1; printf("Recognized: %s\n", hyp); fclose(fh); ps_free(ps); return 0; }
int main(int argc, char *argv[]) { ps_decoder_t *ps; cmd_ln_t *config; FILE *fh; char const *hyp, *uttid; int16 buf[512]; int rv; int32 score; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-lm", MODELDIR "/en-us/en-us.lm.bin", "-dict", MODELDIR "/en-us/cmudict-en-us.dict", NULL); if (config == NULL) { fprintf(stderr, "Failed to create config object, see log for details\n"); return -1; } // Initialize pocketsphinx ps = ps_init(config); if (ps == NULL) { fprintf(stderr, "Failed to create recognizer, see log for details\n"); return -1; } // Open the wav file passed from argument printf("file: %s\n", argv[1]); fh = fopen(argv[1], "rb"); if (fh == NULL) { fprintf(stderr, "Unable to open input file %s\n", argv[1]); return -1; } // Start utterance rv = ps_start_utt(ps); // Process buffer, 512 samples at a time while (!feof(fh)) { size_t nsamp; nsamp = fread(buf, 2, 512, fh); rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE); } // Recieve the recognized string rv = ps_end_utt(ps); hyp = ps_get_hyp(ps, &score); printf("Recognized: |%s|\n", hyp); // free memory fclose(fh); ps_free(ps); cmd_ln_free_r(config); 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; 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 main(int argc, char *argv[]) { ps_decoder_t *ps; cmd_ln_t *config; FILE *fh; const char *filename = "goforward.raw"; const char *word = "goforward"; char const *hyp, *uttid; int rv; int32 score; /* setup the sphinx config */ config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-lm", MODELDIR "/lm/en/turtle.DMP", "-dict", MODELDIR "/lm/en/turtle.dic", NULL); if(config == NULL) { EXIT_ERROR; } /* initialize the config */ ps = ps_init(config); if(ps == NULL) { EXIT_ERROR; } /* open the audio file (stream?) */ fh = fopen(filename, "rb"); if(fh == NULL) { perror(filename); exit(1); } /* decode the file */ rv = ps_decode_raw(ps, fh, word, -1); if(rv < 0) { EXIT_ERROR; } /* get hypothesis */ hyp = ps_get_hyp(ps, &score, &uttid); if(hyp == NULL) { EXIT_ERROR; } printf("Recognized: %s; score: %d; uttid: %s\n", hyp, score, uttid); /* clean up */ fclose(fh); ps_free(ps); 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; }
int main(int argc, char *argv[]) { ngram_trie_t *t; dict_t *dict; bin_mdef_t *mdef; logmath_t *lmath; cmd_ln_t *config; FILE *arpafh; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", TESTDATADIR "/hub4wsj_sc_8k", "-dict", TESTDATADIR "/bn10000.homos.dic", NULL); ps_init_defaults(config); lmath = logmath_init(cmd_ln_float32_r(config, "-logbase"), 0, FALSE); mdef = bin_mdef_read(config, cmd_ln_str_r(config, "-mdef")); dict = dict_init(config, mdef); t = ngram_trie_init(dict, lmath); arpafh = fopen(TESTDATADIR "/bn10000.3g.arpa", "r"); ngram_trie_read_arpa(t, arpafh); fclose(arpafh); /* Test 1, 2, 3-gram probs without backoff. */ test_lookups(t, lmath); arpafh = fopen("tmp.bn10000.3g.arpa", "w"); ngram_trie_write_arpa(t, arpafh); fclose(arpafh); ngram_trie_free(t); t = ngram_trie_init(dict, lmath); arpafh = fopen("tmp.bn10000.3g.arpa", "r"); ngram_trie_read_arpa(t, arpafh); fclose(arpafh); /* Test 1, 2, 3-gram probs without backoff. */ test_lookups(t, lmath); /* Test adding nodes. */ test_add_nodes(t, lmath); ngram_trie_free(t); dict_free(dict); logmath_free(lmath); bin_mdef_free(mdef); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { cmd_ln_t *config; TEST_ASSERT(config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-kws", DATADIR "/goforward.kws", "-dict", MODELDIR "/en-us/cmudict-en-us.dict", NULL)); return ps_decoder_test(config, "KEYPHRASE", "forward"); }
int main(int argc, char *argv[]) { ps_decoder_t *ps; cmd_ln_t *config; FILE *fh; char const *hyp, *uttid; int16 buf[512]; int rv; int32 score; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-keyphrase", "marieta", "-dict", MODELDIR "/en-us/cmudict-en-us.dict", "-kws_threshold", "1e-30", NULL); if (config == NULL) { fprintf(stderr, "Failed to create config object, see log for details\n"); return -1; } ps = ps_init(config); if (ps == NULL) { fprintf(stderr, "Failed to create recognizer, see log for details\n"); return -1; } fh = fopen("data/marieta.raw", "rb"); if (fh == NULL) { fprintf(stderr, "Unable to open input file goforward.raw\n"); return -1; } rv = ps_start_utt(ps); while (!feof(fh)) { size_t nsamp; nsamp = fread(buf, 2, 512, fh); rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE); } rv = ps_end_utt(ps); hyp = ps_get_hyp(ps, &score); printf("Recognized: %s\n", hyp); fclose(fh); ps_free(ps); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { cmd_ln_t *config; TEST_ASSERT(config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-allphone", MODELDIR "/en-us/en-us-phone.lm.bin", "-beam", "1e-20", "-pbeam", "1e-10", "-allphone_ci", "no", "-lw", "2.0", NULL)); return ps_decoder_test(config, "ALLPHONE", "SIL G OW F AO R W ER D T AE N M IY IH ZH ER Z S V SIL"); }
SPLEXPORT bool spInitListener( const char *hmm_path, const char *kws_path, const char *lm_path, const char *dict_path, int32_t sample_rate, int delay) { sp_log.open("splog.txt", std::ios_base::app); sp_error = ""; if (kws_path) { config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", hmm_path, "-kws", kws_path, "-dict", dict_path, NULL); } else { config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", hmm_path, "-lm", lm_path, "-dict", dict_path, NULL); } if (config == NULL) { spFatal("pocketsphinx command line initialization failed :("); return false; } if ((ps = ps_init(config)) == NULL) { spFatal("pocketsphinx decoder initialization failed :("); return false; } // Record on new thread listen_thread = std::thread(spListen, sample_rate, delay); return true; }
static void test_reinit_fsg_missing() { ps_decoder_t *ps; cmd_ln_t *config; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-dict", MODELDIR "/lm/en_US/cmu07a.dic", NULL); ps = ps_init(config); cmd_ln_set_str_r(config, "-fsg", "/some/fsg"); ps_update_fsgset (ps); ps_free(ps); cmd_ln_free_r(config); }
void Recognizer::initialize(const ci::fs::path& hmmPath, const ci::fs::path& dictPath) { // Configure recognizer: mConfig = cmd_ln_init( NULL, ps_args(), true, "-hmm", hmmPath.c_str(), "-dict", dictPath.c_str(), "-logfn", "/dev/null", NULL ); if( mConfig == NULL ) throw std::runtime_error( "Could not configure speech recognizer" ); // Initialize recognizer: mDecoder = ps_init( mConfig ); if( mDecoder == NULL ) throw std::runtime_error( "Could not initialize speech recognizer" ); }
static void test_reinit_lm() { ps_decoder_t *ps; cmd_ln_t *config; ngram_model_t *model; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k", "-lm", MODELDIR "/lm/en_US/wsj0vp.5000.DMP", "-dict", MODELDIR "/lm/en_US/cmu07a.dic", NULL); ps = ps_init(config); model = ps_update_lmset (ps, NULL); ps_free(ps); cmd_ln_free_r(config); }
PocketSphinxServer::PocketSphinxServer() { cmd_ln_t* cfg = cmd_ln_init(nullptr, ps_args(), TRUE, "-hmm", "/usr/share/pocketsphinx/model/hmm/lium_french_f0", "-lm", "/usr/share/pocketsphinx/model/lm/french3g62k.lm.dmp", "-dict", "/usr/share/pocketsphinx/model/lm/frenchWords62k.dic", nullptr); if (!cfg) throw std::runtime_error("Error in cmd_ln_init"); ps = ps_init(cfg); if (!ps) throw std::runtime_error("Error in ps_init"); }
int main(int argc, char *argv[]) { ps_decoder_t *ps; ps_nbest_t *nbest; cmd_ln_t *config; FILE *rawfh; char const *hyp; int32 score, n; TEST_ASSERT(config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-lm", MODELDIR "/en-us/en-us.lm.bin", "-dict", MODELDIR "/en-us/cmudict-en-us.dict", "-fwdtree", "yes", "-fwdflat", "yes", "-bestpath", "yes", "-input_endian", "little", "-samprate", "16000", NULL)); TEST_ASSERT(ps = ps_init(config)); TEST_ASSERT(rawfh = fopen(DATADIR "/goforward.raw", "rb")); ps_decode_raw(ps, rawfh, -1); fclose(rawfh); hyp = ps_get_hyp(ps, &score); printf("BESTPATH: %s (%d)\n", hyp, score); for (n = 1, nbest = ps_nbest(ps); nbest && n < 10; nbest = ps_nbest_next(nbest), n++) { ps_seg_t *seg; hyp = ps_nbest_hyp(nbest, &score); printf("NBEST %d: %s (%d)\n", n, hyp, score); for (seg = ps_nbest_seg(nbest); seg; seg = ps_seg_next(seg)) { char const *word; int sf, ef; word = ps_seg_word(seg); ps_seg_frames(seg, &sf, &ef); printf("%s %d %d\n", word, sf, ef); } } if (nbest) ps_nbest_free(nbest); ps_free(ps); cmd_ln_free_r(config); return 0; }