# PocketSphinx

> CMU's compact offline speech recogniser, still maintained

- Category: Multimodal Generation / Audio, Music & Voice
- Language: C
- Licence: BSD-style (Carnegie Mellon University)
- Repository: https://github.com/cmusphinx/pocketsphinx
- Canonical page: https://ai-tldr.dev/tools/pocketsphinx/

## In short

PocketSphinx is one of Carnegie Mellon University's open-source large-vocabulary, speaker-independent continuous speech recognition engines. It sits in the Audio, Music & Voice category of the Multimodal Generation tools and is open-source, written in C and licensed BSD-style (Carnegie Mellon University). To get started: install the optional example dependencies.

## Overview

PocketSphinx is one of Carnegie Mellon University's open-source large-vocabulary, speaker-independent continuous speech recognition engines. The maintainers are candid about what it is: the algorithms and models it implements are old — dating back to the 1970s in some cases — but still useful in many applications because of how compact and efficient they are. Nothing leaves the machine and no GPU is involved, which is exactly why it survives in embedded and offline settings where a neural ASR stack will not fit.

The project builds with CMake and has no dependency on SphinxBase any more; the audio library that never reliably worked on any platform was removed. It ships as a C library with bindings, plus a `pocketsphinx` command-line program that reads single-channel 16-bit PCM audio from standard input or files and recognises speech using its default acoustic and language model. The oddly large version number (5.1.1) is a legacy of the old "5prealpha" release that people were using; the project follows semantic versioning now.

Three commands cover most work. `live` detects speech segments in each input, recognises them and writes line-delimited JSON with start time, duration, probability and text — down to per-word and, with the right flags, per-phone or per-state segments. `single` treats each input as one utterance. `align` force-aligns an audio file to a word sequence you supply, which is what makes PocketSphinx a common choice for generating timings rather than transcripts.

## What it does

- Fully offline, speaker-independent continuous speech recognition with a small footprint and no GPU requirement
- C library plus a command-line program and Python bindings, built with CMake across Linux and Windows
- Line-delimited JSON output with start time, duration, probability and text, plus nested word segments
- Forced alignment (`align`) of audio to a supplied word sequence, optionally down to phone or state level
- Ships with default acoustic and language models — no training step needed to get a first transcript
- No SphinxBase dependency, and configuration can be dumped to and loaded from JSON

## Getting started

PocketSphinx builds with CMake. You can install just the Python module, or the C library and bindings. Its inputs are single-channel 16-bit PCM, so convert other formats with sox first.

1. Install the optional example dependencies

   Not strictly needed to build and install, but useful for running the example code on Debian-derived systems including Raspberry Pi OS and Ubuntu.

```bash
sudo apt install \
    ffmpeg \
    libasound2-dev \
    libportaudio2 \
    libportaudiocpp0 \
    libpulse-dev \
    libsox-fmt-all \
    portaudio19-dev \
    sox
```

2. Install the Python module in a virtual environment

   From the top level of the repository. Replace the path with whichever virtual environment you want to create.

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

3. Or build and install the C library

   Standard CMake three-step. Pass `-DCMAKE_INSTALL_PREFIX` on the first command if you do not have access to /usr/local.

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

4. Transcribe a file

   `single` recognises the whole input as one utterance and writes a JSON object. `live` instead segments the stream and emits one JSON line per detected utterance.

```bash
pocketsphinx single speech.wav
```

5. Force-align audio to a known transcript

   The first positional argument is the audio; everything after it is concatenated into the text. Normalise that text yourself — remove punctuation and casing. Add `-phone_align yes` or `-state_align yes` for finer granularity.

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

pocketsphinx -phone_align yes align audio.wav "go forward ten meters"
```

## When to use it

- Reach for it for offline voice control on embedded hardware, where a neural ASR model will not fit in the compute or memory budget
- Reach for it to force-align audio against a known transcript and get word, phone or state timings
- Reach for it when audio must never leave the device and a small, auditable C dependency beats a model server
- Reach for it as a cheap keyword or command recogniser in front of a heavier pipeline
