Introduction to sphinxwrapper¶
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
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 = p.open(format=paInt16, channels=1, rate=16000, input=True, frames_per_buffer=2048) while True: ps.process_audio(stream.read(2048)) time.sleep(0.1)
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.