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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for sphinxwrapper-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c03f57098c25744074c5f34d0506776877b3c4902c4b5e5d57ce538d4d1839bd |
|
MD5 | d348f18a0354cf183e6d92973a9f3363 |
|
BLAKE2b-256 | 26033c5f1ccbe4837cda3700596bbd169f17760432a5f9b1ba1a12770b151952 |
Hashes for sphinxwrapper-1.2.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb894192f1795565acf451e1fb22ac6df83e99e87ae4d63750c1875a51a5971c |
|
MD5 | f92ef49a006728cb52e2c940a4fa83da |
|
BLAKE2b-256 | 3f96585789f9f4dd1bc7a0e9b1e915d46acba6c5b349396185bf08fdbca41633 |