Skip to main content

Official Python bindings for PocketSphinx

Project description

PocketSphinx 5.0.1

This is PocketSphinx, one of Carnegie Mellon University's open source large vocabulary, speaker-independent continuous speech recognition engines.

Although this was at one point a research system, active development has largely ceased and it has become very, very far from the state of the art. I am making a release, because people are nonetheless using it, and there are a number of historical errors in the build system and API which needed to be corrected.

The version number is strangely large because there was a "release" that people are using called 5prealpha, and we will use proper semantic versioning from now on.

Please see the LICENSE file for terms of use.

Installation

You should be able to install this with pip for recent platforms and versions of Python:

pip3 install pocketsphinx

Alternately, you can also compile it from the source tree. I highly suggest doing this in a virtual environment (replace ~/ve_pocketsphinx with the virtual environment you wish to create), from the top level directory:

python3 -m venv ~/ve_pocketsphinx
. ~/ve_pocketsphinx/bin/activate
pip3 install .

On GNU/Linux and maybe other platforms, you must have PortAudio installed for the LiveSpeech class to work (we may add a fall-back to sox in the near future). On Debian-like systems this can be achieved by installing the libportaudio2 package:

sudo apt-get install libportaudio2

Usage

See the examples directory for a number of examples of using the library from Python. You can also read the documentation for the Python API or the C API.

It also mostly supports the same APIs as the previous pocketsphinx-python module, as described below.

LiveSpeech

An iterator class for continuous recognition or keyword search from a microphone. For example, to do speech-to-text with the default (some kind of US English) model:

from pocketsphinx import LiveSpeech
for phrase in LiveSpeech(): print(phrase)

Or to do keyword search:

from pocketsphinx import LiveSpeech

speech = LiveSpeech(keyphrase='forward', kws_threshold=1e-20)
for phrase in speech:
    print(phrase.segments(detailed=True))

With your model and dictionary:

import os
from pocketsphinx import LiveSpeech, get_model_path

speech = LiveSpeech(
    sampling_rate=16000,  # optional
    hmm=get_model_path('en-us'),
    lm=get_model_path('en-us.lm.bin'),
    dic=get_model_path('cmudict-en-us.dict')
)

for phrase in speech:
    print(phrase)

AudioFile

This is an iterator class for continuous recognition or keyword search from a file. Currently it supports only raw, single-channel, 16-bit PCM data in native byte order.

from pocketsphinx import AudioFile
for phrase in AudioFile("goforward.raw"): print(phrase) # => "go forward ten meters"

An example of a keyword search:

from pocketsphinx import AudioFile

audio = AudioFile("goforward.raw", keyphrase='forward', kws_threshold=1e-20)
for phrase in audio:
    print(phrase.segments(detailed=True)) # => "[('forward', -617, 63, 121)]"

With your model and dictionary:

import os
from pocketsphinx import AudioFile, get_model_path

model_path = get_model_path()

config = {
    'verbose': False,
    'audio_file': 'goforward.raw',
    'hmm': get_model_path('en-us'),
    'lm': get_model_path('en-us.lm.bin'),
    'dict': get_model_path('cmudict-en-us.dict')
}

audio = AudioFile(**config)
for phrase in audio:
    print(phrase)

Convert frame into time coordinates:

from pocketsphinx import AudioFile

# Frames per Second
fps = 100

for phrase in AudioFile(frate=fps):  # frate (default=100)
    print('-' * 28)
    print('| %5s |  %3s  |   %4s   |' % ('start', 'end', 'word'))
    print('-' * 28)
    for s in phrase.seg():
        print('| %4ss | %4ss | %8s |' % (s.start_frame / fps, s.end_frame / fps, s.word))
    print('-' * 28)

# ----------------------------
# | start |  end  |   word   |
# ----------------------------
# |  0.0s | 0.24s | <s>      |
# | 0.25s | 0.45s | <sil>    |
# | 0.46s | 0.63s | go       |
# | 0.64s | 1.16s | forward  |
# | 1.17s | 1.52s | ten      |
# | 1.53s | 2.11s | meters   |
# | 2.12s |  2.6s | </s>     |
# ----------------------------

Authors

PocketSphinx is ultimately based on Sphinx-II which in turn was based on some older systems at Carnegie Mellon University, which were released as free software under a BSD-like license thanks to the efforts of Kevin Lenzo. Much of the decoder in particular was written by Ravishankar Mosur (look for "rkm" in the comments), but various other people contributed as well, see the AUTHORS file for more details.

David Huggins-Daines (the author of this document) is guilty^H^H^H^H^Hresponsible for creating PocketSphinx which added various speed and memory optimizations, fixed-point computation, JSGF support, portability to various platforms, and a somewhat coherent API. He then disappeared for a while.

Nickolay Shmyrev took over maintenance for quite a long time afterwards, and a lot of code was contributed by Alexander Solovets, Vyacheslav Klimkov, and others. The pocketsphinx-python module was originally written by Dmitry Prazdnichnov.

Currently this is maintained by David Huggins-Daines again.

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

pocketsphinx-5.0.1.tar.gz (33.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pocketsphinx-5.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pocketsphinx-5.0.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (29.1 MB view details)

Uploaded PyPymacOS 10.9+ x86-64

pocketsphinx-5.0.1-cp311-cp311-win_amd64.whl (29.0 MB view details)

Uploaded CPython 3.11Windows x86-64

pocketsphinx-5.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pocketsphinx-5.0.1-cp311-cp311-macosx_10_9_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

pocketsphinx-5.0.1-cp310-cp310-win_amd64.whl (29.0 MB view details)

Uploaded CPython 3.10Windows x86-64

pocketsphinx-5.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pocketsphinx-5.0.1-cp310-cp310-macosx_10_9_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

pocketsphinx-5.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pocketsphinx-5.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

Details for the file pocketsphinx-5.0.1.tar.gz.

File metadata

  • Download URL: pocketsphinx-5.0.1.tar.gz
  • Upload date:
  • Size: 33.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pocketsphinx-5.0.1.tar.gz
Algorithm Hash digest
SHA256 cadfe42cf1596399ff1a6818ad75970c658e567c7250d67e758b29444facede9
MD5 fdd1227fb750f087f0636f8c222cbbb9
BLAKE2b-256 94b234e55d48ce1cbf8bdf831d9edbf7f61ccf8852edc54da4f05fe7d1fd9034

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6917c627bad7106ea9ac9e1cb5b84dab4187c3dc05fc526eec83ea4924608eb6
MD5 7657b4f652c5f82ec263e41de1287f43
BLAKE2b-256 a345052eed77b95fa7e9ca710c8aedfcb28ebe6d0bde1a4e374b3e83baadf7ce

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 274fd8b7254c0d5e7904dea6b262ba011ef71f0ea4270cf3044dfbf60bf3390c
MD5 ed60b2af550575603def8efc5c5c0250
BLAKE2b-256 360cfba0d280c8becd89bfd79644c6ea55ca266c1b4ce8c6483cb3888ff57863

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 42c4bd5c0e03f2120362e8eb31587694a14a94dc097d8dbde7e74e0291b1700b
MD5 14f373a3f92aa8752fd4883925d9fa70
BLAKE2b-256 f26fe81fa18ea74b9222ef588c14ffe8832b700ef8f1ab7e7eced3ef7d4135a8

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4f5e4a18c04af9d52ffe2638518d842c55fadbdfcf6637f894cab9b713c651a
MD5 e2bf766bd18cf6da5470da95e667ea9a
BLAKE2b-256 a2e1eb8ad4fbf44931c1b73c9b45dfdb43dcbd67f627f7aca5b79125f5014c0b

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8cd5146010da260e7546a5590077c5b7ac5f8bda65c0335be5f41921fb2d2e0f
MD5 e506529c607fe29cbdf86a0a0a494c93
BLAKE2b-256 93050bb14ea7d21efec8ff636caffe04059df60bc93f69f4bfd295186c5ef95d

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 66b37053047513c3727d93399cb49d5a031d5204f96915399344ae3fde67aee5
MD5 280e7c33d62d217cade03e5b485a73b3
BLAKE2b-256 5fbb5299d807417281832dcb92531e7543dd6b48e3178e015de00f3932e2e6f6

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f583cc0a14782660b8e4fc830aaadfc6e8799a50fca310cc0081f581f566bd05
MD5 726d659ce715c76276567ef1b5fc69a3
BLAKE2b-256 1c3a8cb650f138ca63f55988a451e31f694cb13c3ad762631cfcd7cc6ff0b3f5

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1577e9148a575942e1a1e4811e3a9eef353bdc964dd86055413e306e0ede41a8
MD5 7316e666b7ab93b20956ce7c08aee57e
BLAKE2b-256 c4d0f51dd20cd1ecd50abe1f34abde517d91a667a03790acd0359af75e4a0f8c

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50b65ce69e0ea865c16563174ccb10cd1e194b05c889c777555f2f6af3702614
MD5 7d270eeca0fb5f4c78007c7676d11c71
BLAKE2b-256 ba14914935ba10dbcfae6bb76f44343aa4a9198f2fc97b710ece21075bec495a

See more details on using hashes here.

File details

Details for the file pocketsphinx-5.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60f1e6267d532feb664c9db68ec4e721e3ee8d8054ca62c196a601766cc438f0
MD5 100bc2de8ff7ad90e7d872079d662048
BLAKE2b-256 54768da1284eef565b0ec2205ca977c0b22bb9945f124a88f892107e73542c12

See more details on using hashes here.

Supported by

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