void ps_free(ps_node* node) { struct array *what = NULL; switch (node->type) { case NODE_BOOL : case NODE_INT : case NODE_FLOAT : case NODE_NULL : break; case NODE_STRING : free(node->val.s.val); break; case NODE_OBJECT : what = &node->val.o.val; free(node->val.o.type); goto inside_array; case NODE_ARRAY : what = &node->val.a; inside_array: for (int i = 0; i < what->len; i++) { ps_free(what->pairs[i].key); ps_free(what->pairs[i].val); } free(what->pairs); break; default: _err("Invalid node type %d in %s", node->type, __func__); }; free(node); }
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 main(int argc, char *argv[]) { char const *cfg; config = cmd_ln_parse_r(NULL, cont_args_def, argc, argv, TRUE); /* Handle argument file as -argfile. */ if (config && (cfg = cmd_ln_str_r(config, "-argfile")) != NULL) { config = cmd_ln_parse_file_r(config, cont_args_def, cfg, FALSE); } if (config == NULL || (cmd_ln_str_r(config, "-infile") == NULL && cmd_ln_boolean_r(config, "-inmic") == FALSE)) { E_INFO("Specify '-infile <file.wav>' to recognize from file or '-inmic yes' to recognize from microphone."); cmd_ln_free_r(config); return 1; } ps_default_search_args(config); ps = ps_init(config); if (ps == NULL) { cmd_ln_free_r(config); return 1; } E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__); if (cmd_ln_boolean_r(config, "-inmic")) { recognize_from_microphone(); } ps_free(ps); cmd_ln_free_r(config); return 0; }
/*! function to close the asr interface */ static switch_status_t pocketsphinx_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags) { pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>>pocketsphinx_asr_close<<<<<<<<<\n"); switch_mutex_lock(ps->flag_mutex); if (switch_test_flag(ps, PSFLAG_ALLOCATED)) { if (switch_test_flag(ps, PSFLAG_READY)) { ps_end_utt(ps->ps); } ps_free(ps->ps); ps->ps = NULL; } switch_safe_free(ps->grammar); switch_mutex_unlock(ps->flag_mutex); switch_clear_flag(ps, PSFLAG_HAS_TEXT); switch_clear_flag(ps, PSFLAG_READY); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Port Closed.\n"); switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED); /* ifly end session */ QISRSessionEnd(ps->ifly_session_id, ps->ifly_hints); return SWITCH_STATUS_SUCCESS; }
void add_to_best_list(APPROX_PARAMS *ap, OPTION **new_b_options, int *new_cand_num, OPTION *to_add) { ASSERT(*new_cand_num < ap->beam || to_add->lprob > new_b_options[ap->beam - 1]->lprob); int i; for (i = *new_cand_num - 1; i >= 0; i--) { if (new_b_options[i]->lprob < to_add->lprob) { new_b_options[i + 1] = new_b_options[i]; } else { new_b_options[i + 1] = to_add; break; } } //should be inserted on the first position if (i == -1) { new_b_options[0] = to_add; } if (*new_cand_num == ap->beam) { pt_free(&(new_b_options[ap->beam]->pt)); ps_free(&(new_b_options[ap->beam]->ps)); free_options(new_b_options[ap->beam]); } else { (*new_cand_num)++; } return; }
double label_sentence(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent) { ASSERT(ap->beam >= 1 && ap->beam < MAX_BEAM); ASSERT(ap->search_br_factor >= 1); OPTION *best_options[MAX_SENT_LEN + 1][MAX_BEAM + 1]; best_options[0][0] = root_prediction(ap, mp, sent); int cand_num = 1; int t; for (t = 1; t < sent->len + 1; t++) { cand_num = search_options(ap, mp, sent, best_options[t-1], cand_num, best_options[t]); ASSERT(cand_num <= ap->beam); } double best_lprob = best_options[sent->len][0]->lprob; pt_fill_sentence(best_options[sent->len][0]->pt, mp, sent); ps_fill_sentence(best_options[sent->len][0]->ps, mp, sent); save_candidates(ap, mp, sent, best_options[sent->len], cand_num); int i; for (i = 0; i < cand_num; i++) { pt_free(&(best_options[sent->len][i]->pt)); ps_free(&(best_options[sent->len][i]->ps)); free_options(best_options[sent->len][i]); } return best_lprob; }
int main(int argc, char *argv[]) { char const *cfg; if (argc == 2) { config = cmd_ln_parse_file_r(NULL, cont_args_def, argv[1], TRUE); } else { config = cmd_ln_parse_r(NULL, cont_args_def, argc, argv, FALSE); } if (config && (cfg = cmd_ln_str_r(config, "-argfile")) != NULL) { config = cmd_ln_parse_file_r(config, cont_args_def, cfg, FALSE); } if (config == NULL) return 1; ps = ps_init(config); if (ps == NULL) return 1; E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__); if (cmd_ln_str_r(config, "-infile") != NULL) { recognize_from_file(); } ps_free(ps); 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; }
int main(int argc, char *argv[]) { char const *cfg; if (argc == 2) { config = cmd_ln_parse_file_r(NULL, cont_args_def, argv[1], TRUE); } else { config = cmd_ln_parse_r(NULL, cont_args_def, argc, argv, FALSE); } /* Handle argument file as -argfile. */ if (config && (cfg = cmd_ln_str_r(config, "-argfile")) != NULL) { config = cmd_ln_parse_file_r(config, cont_args_def, cfg, FALSE); } if (config == NULL) return 1; ps = ps_init(config); if (ps == NULL) return 1; E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__); /* Make sure we exit cleanly (needed for profiling among other things) */ signal(SIGINT, &sighandler); if (setjmp(jbuf) == 0) { recognize_from_microphone(); } ps_free(ps); 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; }
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[]) { 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; }
void Recognizer::cleanup() { if (decoder) ps_free(decoder); if (logmath) logmath_free(logmath); decoder = NULL; grammar_set = NULL; logmath = NULL; }
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; }
void sbrDecodeEnd(sbr_info *sbr) { uint8_t j; if (sbr) { qmfa_end(sbr->qmfa[0]); qmfs_end(sbr->qmfs[0]); if (sbr->qmfs[1] != NULL) { qmfa_end(sbr->qmfa[1]); qmfs_end(sbr->qmfs[1]); } for (j = 0; j < 5; j++) { if (sbr->G_temp_prev[0][j]) faad_free(sbr->G_temp_prev[0][j]); if (sbr->Q_temp_prev[0][j]) faad_free(sbr->Q_temp_prev[0][j]); if (sbr->G_temp_prev[1][j]) faad_free(sbr->G_temp_prev[1][j]); if (sbr->Q_temp_prev[1][j]) faad_free(sbr->Q_temp_prev[1][j]); } #ifdef PS_DEC if (sbr->ps != NULL) ps_free(sbr->ps); #endif #ifdef DRM_PS if (sbr->drm_ps != NULL) drm_ps_free(sbr->drm_ps); #endif faad_free(sbr); } }
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; }
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; }
static void test_no_search() { cmd_ln_t *config = default_config(); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(ps_start_utt(ps) < 0); ps_free(ps); cmd_ln_free_r(config); }
int sphinxClose() { if (ps_free(ps) != 0) { printf("Error freeing pocketsphinx.\n"); return 0; } return 1; }
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; }
static av_cold void asr_uninit(AVFilterContext *ctx) { ASRContext *s = ctx->priv; ps_free(s->ps); s->ps = NULL; cmd_ln_free_r(s->config); s->config = NULL; }
static void test_default_lm() { cmd_ln_t *config = default_config(); cmd_ln_set_str_r(config, "-lm", MODELDIR "/en-us/en-us.lm.dmp"); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(!ps_get_fsg(ps, PS_DEFAULT_SEARCH)); TEST_ASSERT(ps_get_lm(ps, PS_DEFAULT_SEARCH)); ps_free(ps); cmd_ln_free_r(config); }
static void test_default_jsgf() { cmd_ln_t *config = default_config(); cmd_ln_set_str_r(config, "-jsgf", DATADIR "/goforward.gram"); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(!ps_get_lm(ps, PS_DEFAULT_SEARCH)); TEST_ASSERT(ps_get_fsg(ps, PS_DEFAULT_SEARCH)); ps_free(ps); cmd_ln_free_r(config); }
static void gst_pocketsphinx_finalize(GObject * gobject) { GstPocketSphinx *ps = GST_POCKETSPHINX(gobject); ps_free(ps->ps); cmd_ln_free_r(ps->config); g_free(ps->last_result); G_OBJECT_CLASS(gst_pocketsphinx_parent_class)->finalize(gobject); }
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; }
static void gst_pocketsphinx_finalize(GObject * gobject) { GstPocketSphinx *ps = GST_POCKETSPHINX(gobject); g_hash_table_foreach(ps->arghash, string_disposal, NULL); g_hash_table_destroy(ps->arghash); g_free(ps->last_result); ps_free(ps->ps); cmd_ln_free_r(ps->config); GST_CALL_PARENT(G_OBJECT_CLASS, finalize,(gobject)); }
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; }
Recognizer::~Recognizer() { // Set stop flag: mStop = true; // Join thread: if( mThread.joinable() ) mThread.join(); // Cleanup decoder: if( mDecoder ) ps_free( mDecoder ); // Cleanup config: if( mConfig ) cmd_ln_free_r( mConfig ); // Cleanup models: mModelMap.clear(); }
static void test_default_fsg() { cmd_ln_t *config = default_config(); cmd_ln_set_str_r(config, "-hmm", DATADIR "/tidigits/hmm"); cmd_ln_set_str_r(config, "-dict", DATADIR "/tidigits/lm/tidigits.dic"); cmd_ln_set_str_r(config, "-fsg", DATADIR "/tidigits/lm/tidigits.fsg"); ps_decoder_t *ps = ps_init(config); TEST_ASSERT(!ps_get_lm(ps, PS_DEFAULT_SEARCH)); TEST_ASSERT(ps_get_fsg(ps, PS_DEFAULT_SEARCH)); ps_free(ps); cmd_ln_free_r(config); }
ps_decoder_t * ps_init(cmd_ln_t *config) { ps_decoder_t *ps; ps = ckd_calloc(1, sizeof(*ps)); ps->refcount = 1; if (ps_reinit(ps, config) < 0) { ps_free(ps); return NULL; } return ps; }