Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Introduction to sphinxwrapper

Docs Status

Alternative Python API for recognising speech with CMU Pocket Sphinx

This package aims to provide a simple API for recognising speech using the Pocket Sphinx API. Pocket Sphinx is an open source, lightweight speech recognition engine. You can read more about the CMU Sphinx speech recognition projects here.

There are some usage examples in the repository's examples folder.

Installation & dependencies

To install this package via pip, run the following command:

pip install sphinxwrapper

If you are installing in order to develop sphinxwrapper, clone/download the repository, move to the root directory and run:

pip install -e .

Either of the above commands will also install the required pocketsphinx-python package.

The usage examples for sphinxwrapper require the cross-platform pyaudio Python package. It can be installed by running the following:

pip install pyaudio

Usage example

The following is a simple usage example showing how to use the sphinxwrapper package to make Pocket Sphinx continuously recognise speech from the microphone using the default decoder configuration.

import time

from pyaudio import PyAudio, paInt16

from sphinxwrapper import PocketSphinx

# Set up a Pocket Sphinx decoder with the default config
ps = PocketSphinx()

# Set up and register a callback function to print Pocket Sphinx's
# hypothesis for  recognised speech
def print_hypothesis(hyp):
    # Get the hypothesis string from the Hypothesis object or None, then
    # print it
    speech = hyp.hypstr if hyp else None
    print("Hypothesis: %s" % speech)

ps.hypothesis_callback = print_hypothesis

# Decode from the default audio input device continously.
p = PyAudio()
stream =, channels=1, rate=16000, input=True,
while True:

Python versions

This package has been written for Python 2.7 and above. It should work exactly the same way for each supported version. please file an issue if you come across any problems that are specific to the Python version you're using.

Future CMU Sphinx API changes

As the CMU Sphinx libraries are pre-alpha, there may be future changes that break this package in some way. I'm happy to fix any such issues, just file an issue.


The documentation for this project is written in reStructuredText and built using the Sphinx documentation engine.

Run the following in the repository folder to build it locally:

cd docs
pip install -r requirements.txt
make html


Alternative Python API for recognising speech with CMU Pocket Sphinx








No packages published