Skip to main content

Docs Status

Simplified Python API for the CMU Pocket Sphinx speech recogniser

This package provides a simple API for recognising speech using CMU Pocket Sphinx, an open source, lightweight speech recognition engine. More information on CMU Pocket Sphinx, and other CMU speech recognition libraries, may be found at cmusphinx.github.io.

There are some usage examples in the repository’s examples folder demonstrating how to use this library to scan and process speech audio from a microphone. Each of these examples require the PyAudio package, which may be installed by running the following command:

pip install pyaudio

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 version 0.1.15 of the required pocketsphinx-python package.

Usage example

The following example demonstrates how to use sphinxwrapper and PyAudio to scan and interpret audio from the microphone using the default language model and dictionary.

import os
import time

from pyaudio import PyAudio, paInt16

from sphinxwrapper import PocketSphinx, DefaultConfig

# Initialise a Pocket Sphinx decoder with the default configuration.
config = DefaultConfig()
config.set_string("-logfn", os.devnull)  # Suppress log output.
ps = PocketSphinx(config)

# Define decoder callback functions.
def speech_start_callback():
    print("Speech started.")

def hypothesis_callback(hyp):
    hypstr = hyp.hypstr if hyp else None
    print("Hypothesis: %r" % hypstr)

# Set decoder callback functions.
ps.speech_start_callback = speech_start_callback
ps.hypothesis_callback = hypothesis_callback

# Open an audio stream on the default input audio device.
p = PyAudio()
stream = p.open(format=paInt16, channels=1, rate=16000, input=True,
                frames_per_buffer=2048, input_device_index=None)
stream.start_stream()

# Recognise from the microphone in a loop until interrupted.
try:
    print("Listening... Press Ctrl+C to exit...")
    while True:
        ps.process_audio(stream.read(2048))
        time.sleep(0.1)
except KeyboardInterrupt:
    stream.stop_stream()
    p.terminate()

Python versions

This package has been written for Python 2.7 and above. It should work the same way for each supported version. Please file an issue if you encounter a problem specific to the Python version you’re using.

Documentation

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

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

cd docs
pip install -r requirements.txt
make html

Metadata

Release files for sphinxwrapper 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinxwrapper 1.3.0
File Size Uploaded
sphinxwrapper-1.3.0.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinxwrapper 1.3.0
File Interpreter ABI Platform
sphinxwrapper-1.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 21.2 kB

Release files / sphinxwrapper-1.3.0.tar.gz

Download URL sphinxwrapper-1.3.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f9296e9e13bfd18b83f86db95afe2cc84f6fc51e75bb0c9c7a4a128065de554c
BLAKE2b-256 checksum
How to use checksums
4b0565d062b3cf1fafd6a4f5cb52432873ff994e8601244c541494fe1715a3e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.1

Release files / sphinxwrapper-1.3.0-py2.py3-none-any.whl

Download URL sphinxwrapper-1.3.0-py2.py3-none-any.whl
Size 11.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
581cf92947e0bd126164a8172f04d7a15edf27bb82a5fbf2b6fec64c3cc851c1
BLAKE2b-256 checksum
How to use checksums
c794b5206b60b26cfba166889007a3f13c70374b9b9edb6deaf50494f4f9b0b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.1

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page