From cc4febfba133c2c3e404e8548cbf9ec07f355a30 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 16 Aug 2022 11:48:32 -0400 Subject: [PATCH] docs: add basic example documentation --- examples/README.md | 29 +++++++++++++++++++++++++++++ examples/simple.c | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 examples/README.md diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..54069cdc --- /dev/null +++ b/examples/README.md @@ -0,0 +1,29 @@ +PocketSphinx Examples +===================== + +This directory contains some examples of basic PocketSphinx library +usage in C and Python. To compile the C example, you can either use +the library directly in-place: + + cmake -DBUILD_SHARED_LIBS=OFF .. && make + cc -o simple simple.c -I../include -Iinclude -L. -lpocketsphinx -lm + +Or if PocketSphinx is installed: + + cc -o simple simple.c $(pkg-config --static --libs --cflags pocketsphinx) + +By default it assumes you are running it from this directory, +otherwise you could define `MODELDIR` when compiling, e.g.: + + cc -o simple simple.c -DMODELDIR=/my/models \ + $(pkg-config --static --libs --cflags pocketsphinx) + +The Python script, assuming you have installed the `pocketsphinx5` +module (see [the top-leve README](../README.md) for instructions), can +just be run as-is: + + python simple.py + +Now speak. It should start printing partial results, and not stop, +until you interrupt it with Control-C, whereupon it will print one +last final result. diff --git a/examples/simple.c b/examples/simple.c index f9e91c43..8f9c4f3c 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -19,7 +19,9 @@ main(int argc, char *argv[]) short buf[BUFLEN]; size_t len; + #ifndef MODELDIR #define MODELDIR "../model" + #endif if ((config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", MODELDIR "/en-us/en-us", "-lm", MODELDIR "/en-us/en-us.lm.bin",