| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <pocketsphinx.h> |
| | #include <stdlib.h> |
| |
|
| | int |
| | main(int argc, char *argv[]) |
| | { |
| | ps_decoder_t *decoder; |
| | ps_config_t *config; |
| | FILE *fh; |
| | short *buf; |
| | size_t len, nsamples; |
| |
|
| | |
| | if (argc < 2) |
| | E_FATAL("Usage: %s FILE\n"); |
| | if ((fh = fopen(argv[1], "rb")) == NULL) |
| | E_FATAL_SYSTEM("Failed to open %s", argv[1]); |
| |
|
| | |
| | if (fseek(fh, 0, SEEK_END) < 0) |
| | E_FATAL_SYSTEM("Unable to find end of input file %s", argv[1]); |
| | len = ftell(fh); |
| | rewind(fh); |
| |
|
| | |
| | config = ps_config_init(NULL); |
| | ps_default_search_args(config); |
| | if (ps_config_soundfile(config, fh, argv[1]) < 0) |
| | E_FATAL("Unsupported input file %s\n", argv[1]); |
| | if ((decoder = ps_init(config)) == NULL) |
| | E_FATAL("PocketSphinx decoder init failed\n"); |
| |
|
| | |
| | len -= ftell(fh); |
| | if ((buf = malloc(len)) == NULL) |
| | E_FATAL_SYSTEM("Unable to allocate %d bytes", len); |
| | |
| | nsamples = fread(buf, sizeof(buf[0]), len / sizeof(buf[0]), fh); |
| | if (nsamples != len / sizeof(buf[0])) |
| | E_FATAL_SYSTEM("Unable to read %d samples", len / sizeof(buf[0])); |
| |
|
| | |
| | if (ps_start_utt(decoder) < 0) |
| | E_FATAL("Failed to start processing\n"); |
| | if (ps_process_raw(decoder, buf, nsamples, FALSE, TRUE) < 0) |
| | E_FATAL("ps_process_raw() failed\n"); |
| | if (ps_end_utt(decoder) < 0) |
| | E_FATAL("Failed to end processing\n"); |
| |
|
| | |
| | if (ps_get_hyp(decoder, NULL) != NULL) |
| | printf("%s\n", ps_get_hyp(decoder, NULL)); |
| |
|
| | |
| | if (fclose(fh) < 0) |
| | E_FATAL_SYSTEM("Failed to close %s", argv[1]); |
| | free(buf); |
| | ps_free(decoder); |
| | ps_config_free(config); |
| | |
| | return 0; |
| | } |
| |
|