PocketSphinx Documentation

repository·main·Indexed 26 days ago

https://github.com/cmusphinx/pocketsphinx

An open-source, large vocabulary, speaker-independent continuous speech recognition engine designed for compactness and efficiency. It provides a C library and official Python bindings (version 5.1.1) for resource-constrained applications. Key features include real-time recognition via LiveSpeech, file-based recognition with AudioFile, keyword search, and a CLI for tasks like force-alignment. The library supports N-gram, FSG, and JSGF models, and includes tools for Voice Activity Detection (VAD) and speech segmentation.

Tokens
3.7K
Snippets
20
Records
34
Agent score
88%

What's inside pocketsphinx

  1. Overview of PocketSphinx example types

    main

    The PocketSphinx examples demonstrate three primary modes of operation:

    1. Simplest possible example (simple.c, simple.py): Reads an entire WAV audio file and recognizes it as a single utterance.
    2. Segmentation (segment.py): Uses voice activity detection (VAD) to segment an input stream into speech-like regions.
    3. Live recognition (live.c, live.py): Performs online segmentation and recognition (real-time processing).
  2. Enable thread-local RNG for thread safety

    main

    PocketSphinx uses a Mersenne Twister random number generator for tasks like audio dithering. To ensure thread safety and prevent race conditions when using PocketSphinx in multi-threaded applications, you must use a build where thread-local storage is enabled. This allows each thread to maintain its own independent RNG state without locks or synchronization.

    Thread-local storage is enabled by default when building with CMake on supported platforms. If you need to explicitly configure this behavior, use the PS_THREAD_LOCAL_RNG CMake flag.

  3. Compile C examples manually

    main

    If you want to compile a C example (like simple.c) manually without using the standard build system, you can use the following methods depending on your environment.

    Option 1: Building from the source directory If you are building within the source tree:

    cmake -DBUILD_SHARED_LIBS=OFF .. && make
    cc -o simple simple.c -I../include -Iinclude -L. -lpocketsphinx -lm

    Option 2: Using pkg-config (if installed) If PocketSphinx is already installed on your system:

    cc -o simple simple.c $(pkg-config --static --libs --cflags pocketsphinx)
    cmake -DBUILD_SHARED_LIBS=OFF .. && make
    cc -o simple simple.c -I../include -Iinclude -L. -lpocketsphinx -lm
  4. Install the Python module

    main

    To install the PocketSphinx Python module in a virtual environment, run the following commands from the top-level directory of the repository. Replace ~/ve_pocketsphinx with your desired virtual environment path.

    python3 -m venv ~/ve_pocketsphinx
    . ~/ve_pocketsphinx/bin/activate
    pip install .
  5. Install dependencies for example code

    main

    On Debian GNU/Linux and its derivatives (such as Raspberry Pi OS, Ubuntu, etc), you can install the following dependencies required to run the example code using apt:

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