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; }
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[]) { 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; }
int main(int32 argc, char *argv[]) { ps_decoder_t *ps; cmd_ln_t *config; char const *ctl; FILE *ctlfh; config = cmd_ln_parse_r(NULL, ps_args_def, argc, argv, TRUE); /* Handle argument file as -argfile. */ if (config && (ctl = cmd_ln_str_r(config, "-argfile")) != NULL) { config = cmd_ln_parse_file_r(config, ps_args_def, ctl, FALSE); } if (config == NULL) { /* This probably just means that we got no arguments. */ return 1; } if ((ctl = cmd_ln_str_r(config, "-ctl")) == NULL) { E_FATAL("-ctl argument not present, nothing to do in batch mode!\n"); } if ((ctlfh = fopen(ctl, "r")) == NULL) { E_FATAL_SYSTEM("Failed to open control file '%s'", ctl); } ps_default_search_args(config); if (!(ps = ps_init(config))) { cmd_ln_free_r(config); fclose(ctlfh); E_FATAL("PocketSphinx decoder init failed\n"); } process_ctl(ps, config, ctlfh); fclose(ctlfh); ps_free(ps); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { cmd_ln_t *config; ps_decoder_t *ps; int32 out_score; const char *input_file_path; const char *cfg; const char *utt_id; const char *hyp; FILE *input_file; int16 buf[PCM_BUF_LEN]; int k; 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) return 1; if (cmd_ln_str_r(config, "-kws") == NULL && cmd_ln_str_r(config, "-keyphrase") == NULL) { E_ERROR("Keyword is missing. Use -keyphrase <keyphrase> or -kws <kws_file> to specify the phrase to look for."); return 1; } input_file_path = cmd_ln_str_r(config, "-infile"); if (input_file_path == NULL) { E_ERROR("Input file is missing. Use -infile <input_file> to specify the file to look in.\n"); return 1; } ps_default_search_args(config); ps = ps_init(config); if (ps == NULL) { E_ERROR("Failed to create the decoder\n"); return 1; } input_file = fopen(input_file_path, "rb"); if (input_file == NULL) { E_FATAL_SYSTEM("Failed to open input file '%s'", input_file_path); } ps_start_utt(ps, NULL); if (cmd_ln_boolean_r(config, "-adcin")) { fread(buf, 1, 44, input_file); while ((k = fread(buf, sizeof(int16), PCM_BUF_LEN, input_file)) > 0) { ps_process_raw(ps, buf, k, FALSE, FALSE); } } else { mfcc_t **mfcs; int nfr; if (NULL == (mfcs = read_mfc_file(input_file, &nfr, cmd_ln_int32_r(config, "-ceplen")))) { E_ERROR("Failed to read MFCC from the file '%s'\n", input_file_path); fclose(input_file); return -1; } ps_process_cep(ps, mfcs, nfr, FALSE, TRUE); ckd_free_2d(mfcs); } ps_end_utt(ps); hyp = ps_get_hyp(ps, &out_score, &utt_id); printf("hypothesis: %s\n", hyp); fflush(stdout); fclose(input_file); ps_free(ps); cmd_ln_free_r(config); return 0; }