Skip to main content

Alternative Python API for recognising speech with CMU Pocket Sphinx

Project description

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 = 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)

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.

Documentation

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinxwrapper-1.2.0.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distributions

sphinxwrapper-1.2.0-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

sphinxwrapper-1.2.0-py2-none-any.whl (9.5 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page