Library / SDK
cmusphinx/pocketsphinx avatar
cmusphinx/pocketsphinx

PocketSphinx: a small speech recognizer for offline, constrained decoding

A small speech recognizer

4,345 stars732 forksCNOASSERTION

At a glance

What is it?
PocketSphinx is CMU's compact, speaker-independent continuous speech recognizer, now at 5.1.1 with a CMake build and no SphinxBase dependency. It is a good fit for offline keyword spotting and forced alignment, and a poor fit for dictation.
Who is it for?
Adopt PocketSphinx if you need offline recognition on constrained hardware, a fixed grammar or keyword list, or forced alignment of known transcripts, and if you can accept a pip install or a CMake build plus a model directory. Do not adopt it for open-domain dictation, meeting transcription, or any workload where a neural model's accuracy is the deciding factor; the README itself warns that recognition results on a plain WAV file may not be wonderful.
Can I use it commercially?
Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
Is it still maintained?
Yes. The repository last received commits 4 days ago.
What is it written in?
Mainly C, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What PocketSphinx solves, and for whom

PocketSphinx is a large vocabulary, speaker-independent continuous speech recognition engine from Carnegie Mellon University. The README is candid about its age: the algorithms and models date back to the 1970s in some cases. The reason it still exists is compactness and efficiency. If you need speech recognition to run on a small device, inside a process with no network access, or with a fixed set of phrases rather than open-ended dictation, the tradeoff of older acoustic modeling for a small footprint is one many projects are willing to make.

The intended audience is narrower than "anyone who wants speech to text". It suits embedded and edge deployments, command-and-control interfaces, keyword spotting, and forced alignment, where you already know the words and want their timings. It suits researchers who want a C library with Python bindings and a permissive BSD-style licence. It does not suit someone who wants to transcribe a podcast. The README does not claim accuracy parity with modern neural systems, and the example command for a plain WAV file comes with the warning that the results may not be wonderful.

How the recognizer is put together

The repository layout tells you most of the architecture. src/ holds the C engine, include/ the public headers, cython/ the Python bindings, model/ the default acoustic and language model, programs/ the command-line front end, and examples/ a set of C and Python programs. The README notes that PocketSphinx no longer depends on SphinxBase, which used to be a separate support library. That removal simplifies the build: there is one CMake project and one set of headers.

The runtime data flow is visible in the command-line program. It reads single-channel 16-bit PCM audio, either from standard input or from one or more files, detects speech segments, and runs recognition on each segment using the default acoustic and language model. Output is line-delimited JSON, with short field names: b for start time in seconds, d for duration, p for the estimated probability of the result between 0 and 1, t for the recognized text, and w for a list of word segments that carry their own b, d, p and t fields. Passing -phone_align yes adds a nested w field with phone segmentations, and -state_align yes enables phone alignment as well. The probability field is described as the likelihood of the input according to the model, which is not the same as a calibrated confidence score; treat it as a relative ranking signal.

Three commands cover the main modes. live detects segments and streams results, single treats each input as one utterance, and align force-aligns one audio file to a word sequence. The align command takes the input as its first positional argument and concatenates everything after it into the text, so quoting mistakes do not silently split your transcript.

Installing PocketSphinx with pip

The Python package is the shortest path to a working recognizer. The README shows creating a virtual environment and installing from the top level of the source tree. The pyproject.toml declares a single runtime dependency, sounddevice, and lists Python 3.9 through 3.13 in its classifiers.

bash
python3 -m venv ~/ve_pocketsphinx
. ~/ve_pocketsphinx/bin/activate
pip install .

That installs the pocketsphinx module and the command-line program. The package metadata also declares two console scripts, pocketsphinx_lm and pocketsphinx_to_textgrid, so those names should be available on your PATH after installation. The build uses scikit-build-core and Cython, which means a C compiler is needed at install time if no wheel matches your platform.

For the C library and its bindings, the README gives a CMake sequence. The default install prefix is /usr/local, so you need write access there; otherwise pass -DCMAKE_INSTALL_PREFIX to the first cmake command.

bash
cmake -S . -B build
cmake --build build
cmake --build build --target install

If you only want to try the examples, the README lists optional Debian packages for audio and conversion: ffmpeg, libasound2-dev, libportaudio2, libportaudiocpp0, libpulse-dev, libsox-fmt-all, portaudio19-dev and sox. They are not required to build the library.

A first real use: recognizing and aligning audio

Start with a single-channel WAV file. The single command treats the whole file as one utterance and prints a JSON object. The README's own example is blunt about expectations.

bash
pocketsphinx single speech.wav

If your audio is in another format, the soxflags command exists to generate the arguments sox needs to produce the input format PocketSphinx expects. The README notes that because the sox command line is quirky, those arguments must come after the filename or after -d for the microphone.

bash
sox audio.mp3 $(pocketsphinx soxflags) | pocketsphinx -

The same pattern works for live microphone input, where -d tells sox to read from the default device and the trailing - tells pocketsphinx to read from standard input.

bash
sox -d $(pocketsphinx soxflags) | pocketsphinx -

Forced alignment is the mode where PocketSphinx is most defensible. You supply the transcript and it returns timings. The README stresses that you must normalize the text yourself, removing punctuation and uppercase, and gives this example.

bash
pocketsphinx align goforward.wav "go forward ten meters"

To get phone-level output, pass -phone_align yes before the command. The README suggests jq for making the nested JSON readable, for example extracting word names and start times with pocketsphinx align audio.wav $text | jq '.w[]|[.t,.b]'. By default only errors go to standard error; -loglevel INFO raises the verbosity. Partial results are not printed, and the README says they may be added in the future without much enthusiasm.

Where PocketSphinx is the wrong tool

The clearest limitation is stated by the project itself: the algorithms and models are old, and the README warns that recognition results on a plain WAV file may not be wonderful. The probability field is a model likelihood, not a calibrated confidence, so thresholding on it to decide whether a transcript is trustworthy is guesswork. There is no mention of partial results, so any interface that needs incremental hypotheses has to build its own segmentation on top of the streamed segments.

The language model is the default one shipped in model/. If your vocabulary or domain is not covered, accuracy degrades in ways the README does not quantify, and it does not document how to swap in a custom model beyond the existence of the model directory and the pocketsphinx_lm script. Audio handling is also narrow: single-channel 16-bit PCM only, with everything else delegated to sox. The README notes that the audio library was removed entirely because it never built or worked correctly on any platform, so there is no built-in file decoding.

Platform coverage is uneven by the project's own admission. CMake is described as giving reasonable results across Linux and Windows, while the README says the maintainer is not certain about Mac OS X because they do not have one. If you need a supported, tested path on macOS, that statement is a warning rather than a guarantee.

PocketSphinx compared with Whisper and Vosk

The most common comparison is with Whisper-style neural models. The difference is architectural, not just a matter of version numbers. PocketSphinx uses hidden Markov models with older acoustic modeling, which is why it runs in a small footprint and can decode without a GPU. Whisper-style systems use large neural networks and generally need far more memory and compute, and they are trained for open-domain transcription. If your problem is "transcribe arbitrary speech accurately", the neural approach is the one built for it. If your problem is "recognize a fixed command set on a device with kilobytes of headroom", PocketSphinx was designed for that and the neural model was not.

Vosk is the closer alternative in deployment shape: both target offline recognition with small models. The practical difference to check is model size, supported languages, and whether the API you need exists. PocketSphinx ships a C library with Python bindings and a documented C API, which matters if you are embedding it in a C or C++ program. The README points to examples/ for C and Python usage and to the Python API documentation and the C API documentation for reference. Neither comparison can be settled from this repository alone; the honest position is that PocketSphinx wins on footprint and embeddability, and loses on raw transcription accuracy.

Maintenance, licensing and upgrade cost

The repository is not archived, and the last push was on 2026-09-14, two days before this writing. Release v5.1.1 is dated 2026-06-06 and is described as security and robustness fixes; v5.1.0, dated 2026-05-06, is described as mostly bug fixes with a few new features. That release cadence suggests a project still receiving fixes rather than one being rewritten.

The licence is not identified by a standard SPDX tag in the repository metadata, and the README defers to the LICENSE file for terms of use. The Python package metadata classifies it as BSD, but that classification is not the same as reading the LICENSE file. If you are distributing a product that embeds the library or the models, read LICENSE and the model directory's own terms before you ship; this is a factual check, not legal advice.

The upgrade cost from the 5prealpha era is real. The README explains that the version number jumped because 5prealpha was widely used and the project moved to semantic versioning. More importantly, SphinxBase no longer exists, so any build scripts or code that referenced it must be updated. The audio library was removed, which means code that relied on it for file decoding needs a replacement such as sox. The Dockerfile in the repository shows the current expected shape: build with CMake and Ninja, produce a wheel, then install it into a runtime image that already has python3, sox, portaudio and alsa-utils.

Editorial conclusion

Adopt PocketSphinx if you need offline recognition on constrained hardware, a fixed grammar or keyword list, or forced alignment of known transcripts, and if you can accept a pip install or a CMake build plus a model directory. Do not adopt it for open-domain dictation, meeting transcription, or any workload where a neural model's accuracy is the deciding factor; the README itself warns that recognition results on a plain WAV file may not be wonderful. Before committing, verify that the default model covers your language, that your audio is single-channel 16-bit PCM or can be converted with sox, and that the align command's word-level output is detailed enough for your use case.

Frequently asked questions

How do I install PocketSphinx using pip?

The README shows creating a virtual environment and running pip install . from the top level of the source tree. That installs the pocketsphinx module and the command-line program, and requires a C compiler if no wheel matches your platform.

how to use pocketsphinx

The command-line program takes a command such as single, live or align plus one or more inputs. For example, pocketsphinx single speech.wav recognizes a single-channel WAV file and prints a JSON object with the text and timings.

how to install pocketsphinx

There are two documented paths: pip install . inside a virtual environment for the Python module, or a CMake sequence (cmake -S . -B build, then cmake --build build, then cmake --build build --target install) for the C library and bindings. The CMake path installs to /usr/local unless you set -DCMAKE_INSTALL_PREFIX.

What is a PocketSphinx alternative?

The README does not name alternatives, but the architectural contrast is with neural recognizers such as Whisper-style models, which need far more compute and target open-domain transcription, and with Vosk, which also targets offline recognition with small models. PocketSphinx's advantage is compactness and embeddability, not raw accuracy.

Official sources

  1. cmusphinx/pocketsphinx on GitHub
  2. Issues
  3. README
  4. Releases
Community notes

Community notes