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; }
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; }
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[]) { 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; }
/* * Handles option parsing for cmd_ln_parse_file_r() and cmd_ln_init() * also takes care of storing argv. * DO NOT call it from cmd_ln_parse_r() */ static cmd_ln_t * parse_options(cmd_ln_t *cmdln, const arg_t *defn, int32 argc, char* argv[], int32 strict) { cmd_ln_t *new_cmdln; new_cmdln = cmd_ln_parse_r(cmdln, defn, argc, argv, strict); /* If this failed then clean up and return NULL. */ if (new_cmdln == NULL) { int32 i; for (i = 0; i < argc; ++i) ckd_free(argv[i]); ckd_free(argv); return NULL; } /* Otherwise, we need to add the contents of f_argv to the new object. */ if (new_cmdln == cmdln) { /* If we are adding to a previously passed-in cmdln, then * store our allocated strings in its f_argv. */ new_cmdln->f_argv = ckd_realloc(new_cmdln->f_argv, (new_cmdln->f_argc + argc) * sizeof(*new_cmdln->f_argv)); memcpy(new_cmdln->f_argv + new_cmdln->f_argc, argv, argc * sizeof(*argv)); ckd_free(argv); new_cmdln->f_argc += argc; } else { /* Otherwise, store f_argc and f_argv. */ new_cmdln->f_argc = argc; new_cmdln->f_argv = argv; } return new_cmdln; }
int main(int argc, char *argv[]) { sphinx_wave2feat_t *wtf; cmd_ln_t *config; int rv; config = cmd_ln_parse_r(NULL, defn, argc, argv, TRUE); if (config && cmd_ln_str_r(config, "-argfile")) config = cmd_ln_parse_file_r(config, defn, cmd_ln_str_r(config, "-argfile"), FALSE); if (config == NULL) { E_ERROR("Command line parsing failed\n"); return 1; } if ((wtf = sphinx_wave2feat_init(config)) == NULL) { E_ERROR("Failed to initialize wave2feat object\n"); return 1; } /* If there's a control file run through it, otherwise we will do * a single file (which is what run_control_file will do * internally too) */ if (cmd_ln_str_r(config, "-c")) rv = run_control_file(wtf, cmd_ln_str_r(config, "-c")); else rv = sphinx_wave2feat_convert_file(wtf, cmd_ln_str_r(config, "-i"), cmd_ln_str_r(config, "-o")); sphinx_wave2feat_free(wtf); cmd_ln_free_r(config); return rv; }
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; }
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; }
int main(int argc, char *argv[]) { jsgf_t *jsgf; fsg_model_t *fsg; cmd_ln_t *config; const char *rule; if ((config = cmd_ln_parse_r(NULL, defn, argc, argv, TRUE)) == NULL) return 1; if (cmd_ln_boolean_r(config, "-help")) { usagemsg(argv[0]); } jsgf = jsgf_parse_file(cmd_ln_str_r(config, "-jsgf"), NULL); if (jsgf == NULL) { return 1; } rule = cmd_ln_str_r(config, "-toprule") ? cmd_ln_str_r(config, "-toprule") : NULL; if (!(fsg = get_fsg(jsgf, rule))) { E_ERROR("No fsg was built for the given rule '%s'.\n" "Check rule name; it should be qualified (with grammar name)\n" "and not enclosed in angle brackets (e.g. 'grammar.rulename').", rule); return 1; } if (cmd_ln_boolean_r(config, "-compile")) { fsg_model_null_trans_closure(fsg, NULL); } if (cmd_ln_str_r(config, "-fsm")) { const char* outfile = cmd_ln_str_r(config, "-fsm"); const char* symfile = cmd_ln_str_r(config, "-symtab"); if (outfile) fsg_model_writefile_fsm(fsg, outfile); else fsg_model_write_fsm(fsg, stdout); if (symfile) fsg_model_writefile_symtab(fsg, symfile); } else { const char *outfile = cmd_ln_str_r(config, "-fsg"); if (outfile) fsg_model_writefile(fsg, outfile); else fsg_model_write(fsg, stdout); } fsg_model_free(fsg); jsgf_grammar_free(jsgf); return 0; }
int main(int argc, char *argv[]) { char const *cfg; int i; argc = 7; argv[1] = "-dict"; argv[2] = "../../../../../../home/pi/guggug/speech/knowledgebase/3/dictionary"; argv[3] = "-lm"; argv[4] = "../../../../../../home/pi/guggug/speech/knowledgebase/3/langmodel"; argv[5] = "-adcdev"; argv[6] = "hw:1,0"; 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__); if (cmd_ln_str_r(config, "-infile") != NULL) { recognize_from_file(); } else { /* Make sure we exit cleanly (needed for profiling among other things) */ /* Signals seem to be broken in arm-wince-pe. */ #if !defined(GNUWINCE) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) signal(SIGINT, &sighandler); #endif if (setjmp(jbuf) == 0) { recognize_from_microphone(); } } ps_free(ps); return 0; }
int main(int argc, char *argv[]) { jsgf_t *jsgf; fsg_model_t *fsg; cmd_ln_t *config; if ((config = cmd_ln_parse_r(NULL, defn, argc, argv, TRUE)) == NULL) return 1; if (cmd_ln_boolean_r(config, "-help")) { usagemsg(argv[0]); } jsgf = jsgf_parse_file(cmd_ln_str_r(config, "-jsgf"), NULL); if (jsgf == NULL) { return 1; } fsg = get_fsg(jsgf, cmd_ln_str_r(config, "-rule") ? cmd_ln_str_r(config, "-rule") : NULL); if (cmd_ln_boolean_r(config, "-compile")) { fsg_model_null_trans_closure(fsg, NULL); } if (cmd_ln_str_r(config, "-fsm")) { const char* outfile = cmd_ln_str_r(config, "-fsm"); const char* symfile = cmd_ln_str_r(config, "-symtab"); if (outfile) fsg_model_writefile_fsm(fsg, outfile); else fsg_model_write_fsm(fsg, stdout); if (symfile) fsg_model_writefile_symtab(fsg, symfile); } else { const char *outfile = cmd_ln_str_r(config, "-fsg"); if (outfile) fsg_model_writefile(fsg, outfile); else fsg_model_write(fsg, stdout); } fsg_model_free(fsg); jsgf_grammar_free(jsgf); return 0; }
int main(int argc, char *argv[]) { cmd_ln_t *config; ngram_model_t *lm = NULL; logmath_t *lmath; const char *lmfn, *probdefn, *lsnfn, *text; if ((config = cmd_ln_parse_r(NULL, defn, argc, argv, TRUE)) == NULL) return 1; verbose = cmd_ln_boolean_r(config, "-verbose"); /* Create log math object. */ if ((lmath = logmath_init (cmd_ln_float64_r(config, "-logbase"), 0, 0)) == NULL) { E_FATAL("Failed to initialize log math\n"); } /* Load the language model. */ lmfn = cmd_ln_str_r(config, "-lm"); if (lmfn == NULL || (lm = ngram_model_read(config, lmfn, NGRAM_AUTO, lmath)) == NULL) { E_FATAL("Failed to load language model from %s\n", cmd_ln_str_r(config, "-lm")); } if ((probdefn = cmd_ln_str_r(config, "-probdef")) != NULL) ngram_model_read_classdef(lm, probdefn); ngram_model_apply_weights(lm, cmd_ln_float32_r(config, "-lw"), cmd_ln_float32_r(config, "-wip"), cmd_ln_float32_r(config, "-uw")); /* Now evaluate some text. */ lsnfn = cmd_ln_str_r(config, "-lsn"); text = cmd_ln_str_r(config, "-text"); if (lsnfn) { evaluate_file(lm, lmath, lsnfn); } else if (text) { evaluate_string(lm, lmath, text); } return 0; }
int cmd_ln_parse(const arg_t * defn, int32 argc, char *argv[], int strict) { cmd_ln_t *cmdln; cmdln = cmd_ln_parse_r(global_cmdln, defn, argc, argv, strict); if (cmdln == NULL) { /* Old, bogus behaviour... */ E_ERROR("Failed to parse arguments list, forced exit\n"); exit(-1); } /* Initialize global_cmdln if not present. */ if (global_cmdln == NULL) { global_cmdln = cmdln; } return 0; }
void listen::run(char *application){ //Init manually for now int argcnt = 5; char *arguments[argcnt]; arguments[0] = new char[strlen(application)]; strcpy(arguments[0], application); arguments[1] = new char[c.getValue("[General]", "Argument1").size()]; strcpy(arguments[1], c.getValue("[General]", "Argument1").c_str()); arguments[2] = new char[c.getValue("[General]", "Argument2").size()]; strcpy(arguments[2], c.getValue("[General]", "Argument2").c_str()); arguments[3] = new char[c.getValue("[General]", "Argument3").size()]; strcpy(arguments[3], c.getValue("[General]", "Argument3").c_str()); arguments[4] = new char[c.getValue("[General]", "Argument4").size()]; strcpy(arguments[4], c.getValue("[General]", "Argument4").c_str()); if (argcnt == 2) { config = cmd_ln_parse_file_r(NULL, cont_args_def, arguments[1], TRUE); } else { config = cmd_ln_parse_r(NULL, cont_args_def, argcnt, arguments, FALSE); } ps = ps_init(config); //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) */ /* Signals seem to be broken in arm-wince-pe. */ #if !defined(GNUWINCE) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) signal(SIGINT, &sighandler); #endif if(setjmp(jbuf) == 0){ recognize_from_microphone(); } ps_free(ps); }
int main(int argc, char *argv[]) { cmd_ln_t *config; config = cmd_ln_parse_r(NULL, defs, argc, argv, TRUE); if (config == NULL) return 1; printf("%d %s %d %f\n", cmd_ln_int32_r(config, "-a"), cmd_ln_str_r(config, "-b") ? cmd_ln_str_r(config, "-b") : "(null)", cmd_ln_boolean_r(config, "-c"), cmd_ln_float64_r(config, "-d")); cmd_ln_free_r(config); config = cmd_ln_init(NULL, NULL, FALSE, "-b", "foobie", NULL); if (config == NULL) return 1; cmd_ln_free_r(config); config = cmd_ln_init(NULL, defs, TRUE, "-b", "foobie", NULL); if (config == NULL) return 1; printf("%d %s %d %f\n", cmd_ln_int32_r(config, "-a"), cmd_ln_str_r(config, "-b") ? cmd_ln_str_r(config, "-b") : "(null)", cmd_ln_boolean_r(config, "-c"), cmd_ln_float64_r(config, "-d")); cmd_ln_free_r(config); config = cmd_ln_init(NULL, NULL, FALSE, "-b", "foobie", NULL); if (config == NULL) return 1; printf("%s\n", cmd_ln_str_r(config, "-b") ? cmd_ln_str_r(config, "-b") : "(null)"); cmd_ln_set_str_r(config, "-b", "blatz"); printf("%s\n", cmd_ln_str_r(config, "-b") ? cmd_ln_str_r(config, "-b") : "(null)"); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { sbthread_t *threads[10]; cmd_ln_t *config; int i; E_INFO("Processing chan3.raw in 10 threads\n"); if ((config = cmd_ln_parse_r(NULL, fe_args, 0, NULL, FALSE)) == NULL) return -1; err_set_callback(err_threaded_cb, NULL); pthread_key_create(&logfp_index, NULL); pthread_setspecific(logfp_index, (void*)stderr); for (i = 0; i < 10; ++i) { config = cmd_ln_retain(config); threads[i] = sbthread_start(config, process, (void *)(long)i); } for (i = 0; i < 10; ++i) { int rv; rv = sbthread_wait(threads[i]); E_INFO("Thread %d exited with status %d\n", i, rv); sbthread_free(threads[i]); } /* Now check to make sure they all created logfiles with the * correct contents. */ for (i = 0; i < 10; ++i) { char logfile[16], line[256]; FILE *logfh; sprintf(logfile, "%03d.log", i); TEST_ASSERT(logfh = fopen(logfile, "r")); while (fgets(line, sizeof(line), logfh)) { string_trim(line, STRING_BOTH); printf("%s: |%s|\n", logfile, line); /* total number of frames in audio file is 1436, but there are only 1290 voiced */ TEST_EQUAL(0, strcmp(line, "INFO: test_tls_log.c(61): nfr = 1290")); } fclose(logfh); } cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { cmd_ln_t *config; char const *cfg; /* Make sure we exit cleanly (needed for profiling among other things) */ /* Signals seem to be broken in arm-wince-pe. */ #if !defined(GNUWINCE) && !defined(_WIN32_WCE) signal(SIGINT, &sighandler); #endif 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; if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int)cmd_ln_float32_r(config, "-samprate"))) == NULL) E_FATAL("ad_open_dev failed\n"); E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__); if (setjmp(jbuf) == 0) { utterance_loop(); } ps_free(ps); ad_close(ad); return 0; }
static void gst_sphinx_decoder_init (GstSphinxSink *sink) { char **argv; int argc; cmd_ln_t *config; char *sphinx_command; sphinx_command = gst_sphinx_get_command(); g_shell_parse_argv (sphinx_command, &argc, &argv, NULL); setlocale (LC_ALL, "C"); config = cmd_ln_parse_r(NULL, ps_args(), argc, argv, TRUE); sink->decoder = ps_init (config); setlocale (LC_ALL, ""); g_strfreev (argv); g_free (sphinx_command); }
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; }
ReturnType Recognizer::init(const Config& config) { parseStringList(HMM_FOLDERS, &acoustic_models, &default_acoustic_model); #ifdef LM_FILES parseStringList(LM_FILES, &language_models, &default_language_model); #endif /* LM_FILES */ #ifdef DICT_FILES parseStringList(DICT_FILES, &dictionaries, &default_dictionary); #endif /* DICT_FILES */ const arg_t cont_args_def[] = { POCKETSPHINX_OPTIONS, { "-argfile", ARG_STRING, NULL, "Argument file giving extra arguments." }, { "-adcdev", ARG_STRING, NULL, "Name of audio device to use for input." }, { "-infile", ARG_STRING, NULL, "Audio file to transcribe." }, { "-time", ARG_BOOLEAN, "no", "Print word times in file transcription." }, CMDLN_EMPTY_OPTION }; std::map<std::string, std::string> parameters; for (int i=0 ; i< config.size() ; ++i) parameters[config[i].key] = config[i].value; if ((parameters.find("-hmm") == parameters.end()) || (acoustic_models.find(parameters["-hmm"]) == acoustic_models.end())) parameters["-hmm"] = default_acoustic_model; if (parameters.find("-bestpath") == parameters.end()) parameters["-bestpath"] = "no"; if (parameters.find("-remove_noise") == parameters.end()) parameters["-remove_noise"] = "no"; int argc = 2 * parameters.size(); char ** argv = new char*[argc]; int index = 0; for (StringsMapIterator i = parameters.begin() ; i != parameters.end(); ++i) { if (isValidParameter(i->first, i->second)) { if (i->first == "-lm") is_fsg = false; argv[index++] = (char*) i->first.c_str(); argv[index++] = (char*) i->second.c_str(); } } cmd_ln_t * cmd_line = cmd_ln_parse_r(NULL, cont_args_def, argc, argv, FALSE); if (cmd_line == NULL) { delete [] argv; return RUNTIME_ERROR; } decoder = ps_init(cmd_line); delete [] argv; if (decoder == NULL) { return RUNTIME_ERROR; } logmath = logmath_init(1.0001, 0, 0); if (logmath == NULL) { return RUNTIME_ERROR; } return SUCCESS; }
int main(int argc, char *argv[]) { char const *cfg; int i; int16 buf[2048]; 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; singlefile = cmd_ln_boolean_r(config, "-singlefile"); if ((infile_path = cmd_ln_str_r(config, "-infile")) != NULL) { if ((infile = fopen(infile_path, "rb")) == NULL) { E_FATAL_SYSTEM("Failed to read audio from '%s'", infile_path); return 1; } read_audio = &read_audio_file; /* skip wav header */ read_audio(buf, 44); } else { if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"), (int) cmd_ln_float32_r(config, "-samprate"))) == NULL) { E_FATAL("Failed to open audio device\n"); return 1; } read_audio = &read_audio_adev; printf("Start recording ...\n"); fflush(stdout); if (ad_start_rec(ad) < 0) E_FATAL("Failed to start recording\n"); /* TODO remove this thing */ for (i = 0; i < 5; i++) { sleep_msec(200); read_audio(buf, 2048); } printf("You may speak now\n"); fflush(stdout); } fe = fe_init_auto_r(config); if (fe == NULL) return 1; segment_audio(); if (ad) ad_close(ad); if (infile) fclose(infile); fe_free(fe); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { cmd_ln_t *config; ngram_model_t *lm = NULL; logmath_t *lmath; int itype, otype; char const *kase; if ((config = cmd_ln_parse_r(NULL, defn, argc, argv, TRUE)) == NULL) return 1; if (cmd_ln_boolean_r(config, "-help")) { usagemsg(argv[0]); } err_set_debug_level(cmd_ln_int32_r(config, "-debug")); /* Create log math object. */ if ((lmath = logmath_init (cmd_ln_float64_r(config, "-logbase"), 0, 0)) == NULL) { E_FATAL("Failed to initialize log math\n"); } if (cmd_ln_str_r(config, "-i") == NULL || cmd_ln_str_r(config, "-i") == NULL) { E_ERROR("Please specify both input and output models\n"); goto error_out; } /* Load the input language model. */ if (cmd_ln_str_r(config, "-ifmt")) { if ((itype = ngram_str_to_type(cmd_ln_str_r(config, "-ifmt"))) == NGRAM_INVALID) { E_ERROR("Invalid input type %s\n", cmd_ln_str_r(config, "-ifmt")); goto error_out; } lm = ngram_model_read(config, cmd_ln_str_r(config, "-i"), itype, lmath); } else { lm = ngram_model_read(config, cmd_ln_str_r(config, "-i"), NGRAM_AUTO, lmath); } /* Guess or set the output language model type. */ if (cmd_ln_str_r(config, "-ofmt")) { if ((otype = ngram_str_to_type(cmd_ln_str_r(config, "-ofmt"))) == NGRAM_INVALID) { E_ERROR("Invalid output type %s\n", cmd_ln_str_r(config, "-ofmt")); goto error_out; } } else { otype = ngram_file_name_to_type(cmd_ln_str_r(config, "-o")); } /* Recode the language model if desired. */ if (cmd_ln_str_r(config, "-ienc")) { if (ngram_model_recode(lm, cmd_ln_str_r(config, "-ienc"), cmd_ln_str_r(config, "-oenc")) != 0) { E_ERROR("Failed to recode language model from %s to %s\n", cmd_ln_str_r(config, "-ienc"), cmd_ln_str_r(config, "-oenc")); goto error_out; } } /* Case fold if requested. */ if ((kase = cmd_ln_str_r(config, "-case"))) { if (0 == strcmp(kase, "lower")) { ngram_model_casefold(lm, NGRAM_LOWER); } else if (0 == strcmp(kase, "upper")) { ngram_model_casefold(lm, NGRAM_UPPER); } else { E_ERROR("Unknown value for -case: %s\n", kase); goto error_out; } } /* Write the output language model. */ if (ngram_model_write(lm, cmd_ln_str_r(config, "-o"), otype) != 0) { E_ERROR("Failed to write language model in format %s to %s\n", ngram_type_to_str(otype), cmd_ln_str_r(config, "-o")); goto error_out; } /* That's all folks! */ ngram_model_free(lm); return 0; error_out: ngram_model_free(lm); return 1; }
batch_decoder_t * batch_decoder_init_argv(int argc, char *argv[]) { batch_decoder_t *bd; char const *str; bd = ckd_calloc(1, sizeof(*bd)); bd->config = cmd_ln_parse_r(NULL, ms_args_def, argc, argv, FALSE); if ((str = cmd_ln_str_r(bd->config, "-ctl")) == NULL) { E_ERROR("-ctl argument not present, nothing to do in batch mode!\n"); goto error_out; } if ((bd->ctlfh = fopen(str, "r")) == NULL) { E_ERROR_SYSTEM("Failed to open control file '%s'", str); goto error_out; } if ((str = cmd_ln_str_r(bd->config, "-align")) != NULL) { if ((bd->alignfh = fopen(str, "r")) == NULL) { E_ERROR_SYSTEM("Failed to open align file '%s'", str); } } if ((str = cmd_ln_str_r(bd->config, "-hyp")) != NULL) { if ((bd->hypfh = fopen(str, "w")) == NULL) { E_ERROR_SYSTEM("Failed to open hypothesis file '%s'", str); } } if ((bd->sf = search_factory_init_cmdln(bd->config)) == NULL) goto error_out; if ((str = cmd_ln_str_r(bd->config, "-fwdtreelm")) != NULL) { if ((bd->fwdtree = search_factory_create(bd->sf, NULL, "fwdtree", "-fwdtreelm", str, NULL)) == NULL) goto error_out; if ((bd->fwdflat = search_factory_create(bd->sf, NULL, "fwdflat", NULL)) == NULL) goto error_out; } else { if ((bd->fwdtree = search_factory_create(bd->sf, NULL, "fwdtree", NULL)) == NULL) goto error_out; if ((bd->fwdflat = search_factory_create(bd->sf, bd->fwdtree, "fwdflat", NULL)) == NULL) goto error_out; } if ((str = cmd_ln_str_r(bd->config, "-vm")) != NULL) { vocab_map_t *vm = vocab_map_init(search_factory_d2p(bd->sf)->dict); FILE *vmfh; if (vm == NULL) goto error_out; if ((vmfh = fopen(str, "r")) == NULL) { vocab_map_free(vm); goto error_out; } if (vocab_map_read(vm, vmfh) < 0) { vocab_map_free(vm); goto error_out; } fclose(vmfh); fwdflat_search_set_vocab_map(bd->fwdflat, vm); } //if ((bd->latgen = search_factory_create(bd->sf, "latgen", NULL)) == NULL) //goto error_out; search_link(bd->fwdtree, bd->fwdflat, "fwdtree", FALSE); // search_link(bd->fwdflat, bd->latgen, "fwdflat", TRUE); search_set_cb(bd->fwdtree, search_cb, bd); search_set_cb(bd->fwdflat, search_cb, bd); bd->hypfiles = hash_table_new(0, FALSE); if ((str = cmd_ln_str_r(bd->config, "-hypprefix"))) { char *hypfile; FILE *hypfh; hypfile = string_join(str, ".fwdtree.hyp", NULL); hypfh = fopen(hypfile, "w"); if (hypfh == NULL) { E_ERROR_SYSTEM("Could not open %s", hypfile); } else { hash_table_enter(bd->hypfiles, "fwdtree", hypfh); } ckd_free(hypfile); hypfile = string_join(str, ".fwdflat.hyp", NULL); hypfh = fopen(hypfile, "w"); if (hypfh == NULL) { E_ERROR_SYSTEM("Could not open %s", hypfile); } else { hash_table_enter(bd->hypfiles, "fwdflat", hypfh); } ckd_free(hypfile); } return bd; error_out: return NULL; }
int main(int argc, char *argv[]) { static const arg_t fe_args[] = { waveform_to_cepstral_command_line_macro(), { NULL, 0, NULL, NULL } }; FILE *raw; cmd_ln_t *config; fe_t *fe; int16 buf[1024]; int16 const *inptr; int32 frame_shift, frame_size; mfcc_t **cepbuf1, **cepbuf2, **cptr; int32 nfr, i; size_t nsamp; TEST_ASSERT(config = cmd_ln_parse_r(NULL, fe_args, argc, argv, FALSE)); TEST_ASSERT(fe = fe_init_auto_r(config)); TEST_EQUAL(fe_get_output_size(fe), DEFAULT_NUM_CEPSTRA); fe_get_input_size(fe, &frame_shift, &frame_size); TEST_EQUAL(frame_shift, DEFAULT_FRAME_SHIFT); TEST_EQUAL(frame_size, (int)(DEFAULT_WINDOW_LENGTH*DEFAULT_SAMPLING_RATE)); TEST_ASSERT(raw = fopen(TESTDATADIR "/chan3.raw", "rb")); TEST_EQUAL(0, fe_start_utt(fe)); TEST_EQUAL(1024, fread(buf, sizeof(int16), 1024, raw)); nsamp = 1024; TEST_ASSERT(fe_process_frames(fe, NULL, &nsamp, NULL, &nfr) >= 0); TEST_EQUAL(1024, nsamp); TEST_EQUAL(4, nfr); cepbuf1 = ckd_calloc_2d(5, DEFAULT_NUM_CEPSTRA, sizeof(**cepbuf1)); inptr = &buf[0]; nfr = 1; printf("frame_size %d frame_shift %d\n", frame_size, frame_shift); /* Process the first frame. */ TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[0], &nfr) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr); TEST_EQUAL(nfr, 1); /* Note that this next one won't actually consume any frames * of input, because it already got sufficient overflow * samples last time around. This is implementation-dependent * so we shouldn't actually test for it. */ TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[1], &nfr) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr); TEST_EQUAL(nfr, 1); TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[2], &nfr) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr); TEST_EQUAL(nfr, 1); TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, &cepbuf1[3], &nfr) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, nfr); TEST_EQUAL(nfr, 1); TEST_ASSERT(fe_end_utt(fe, cepbuf1[4], &nfr) >= 0); printf("nfr %d\n", nfr); TEST_EQUAL(nfr, 1); /* What we *should* test is that the output we get by * processing one frame at a time is exactly the same as what * we get from doing them all at once. So let's do that */ cepbuf2 = ckd_calloc_2d(5, DEFAULT_NUM_CEPSTRA, sizeof(**cepbuf2)); inptr = &buf[0]; nfr = 5; nsamp = 1024; TEST_EQUAL(0, fe_start_utt(fe)); TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cepbuf2, &nfr) >= 0); printf("nfr %d\n", nfr); TEST_EQUAL(nfr, 4); nfr = 1; TEST_ASSERT(fe_end_utt(fe, cepbuf2[4], &nfr) >= 0); printf("nfr %d\n", nfr); TEST_EQUAL(nfr, 1); for (i = 0; i < 5; ++i) { int j; printf("%d: ", i); for (j = 0; j < DEFAULT_NUM_CEPSTRA; ++j) { printf("%.2f,%.2f ", MFCC2FLOAT(cepbuf1[i][j]), MFCC2FLOAT(cepbuf2[i][j])); TEST_EQUAL_FLOAT(cepbuf1[i][j], cepbuf2[i][j]); } printf("\n"); } /* Now, also test to make sure that even if we feed data in * little tiny bits we can still make things work. */ memset(cepbuf2[0], 0, 5 * DEFAULT_NUM_CEPSTRA * sizeof(**cepbuf2)); inptr = &buf[0]; cptr = &cepbuf2[0]; nfr = 5; i = 5; nsamp = 256; TEST_EQUAL(0, fe_start_utt(fe)); TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i); cptr += i; nfr -= i; i = nfr; nsamp = 256; TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i); cptr += i; nfr -= i; i = nfr; nsamp = 256; TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i); cptr += i; nfr -= i; i = nfr; nsamp = 256; TEST_ASSERT(fe_process_frames(fe, &inptr, &nsamp, cptr, &i) >= 0); printf("inptr %d nsamp %d nfr %d\n", inptr - buf, nsamp, i); cptr += i; nfr -= i; TEST_ASSERT(fe_end_utt(fe, *cptr, &nfr) >= 0); printf("nfr %d\n", nfr); TEST_EQUAL(nfr, 1); for (i = 0; i < 5; ++i) { int j; printf("%d: ", i); for (j = 0; j < DEFAULT_NUM_CEPSTRA; ++j) { printf("%.2f,%.2f ", MFCC2FLOAT(cepbuf1[i][j]), MFCC2FLOAT(cepbuf2[i][j])); TEST_EQUAL_FLOAT(cepbuf1[i][j], cepbuf2[i][j]); } printf("\n"); } /* And now, finally, test fe_process_utt() */ inptr = &buf[0]; i = 0; TEST_EQUAL(0, fe_start_utt(fe)); TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0); printf("i %d nfr %d\n", i, nfr); if (nfr) memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr)); ckd_free_2d(cptr); i += nfr; inptr += 256; TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0); printf("i %d nfr %d\n", i, nfr); if (nfr) memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr)); ckd_free_2d(cptr); i += nfr; inptr += 256; TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0); printf("i %d nfr %d\n", i, nfr); if (nfr) memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr)); ckd_free_2d(cptr); i += nfr; inptr += 256; TEST_ASSERT(fe_process_utt(fe, inptr, 256, &cptr, &nfr) >= 0); printf("i %d nfr %d\n", i, nfr); if (nfr) memcpy(cepbuf2[i], cptr[0], nfr * DEFAULT_NUM_CEPSTRA * sizeof(**cptr)); ckd_free_2d(cptr); i += nfr; inptr += 256; TEST_ASSERT(fe_end_utt(fe, cepbuf2[i], &nfr) >= 0); printf("i %d nfr %d\n", i, nfr); TEST_EQUAL(nfr, 1); for (i = 0; i < 5; ++i) { int j; printf("%d: ", i); for (j = 0; j < DEFAULT_NUM_CEPSTRA; ++j) { printf("%.2f,%.2f ", MFCC2FLOAT(cepbuf1[i][j]), MFCC2FLOAT(cepbuf2[i][j])); TEST_EQUAL_FLOAT(cepbuf1[i][j], cepbuf2[i][j]); } printf("\n"); } ckd_free_2d(cepbuf1); ckd_free_2d(cepbuf2); fclose(raw); fe_free(fe); 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; }