Skip to main content

Official Python bindings for PocketSphinx

Project description

PocketSphinx 5.0.2

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.2.tar.gz (34.2 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.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded PyPymacOS 10.9+ x86-64

pocketsphinx-5.0.2-cp311-cp311-win_amd64.whl (29.1 MB view details)

Uploaded CPython 3.11Windows x86-64

pocketsphinx-5.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

pocketsphinx-5.0.2-cp310-cp310-win_amd64.whl (29.1 MB view details)

Uploaded CPython 3.10Windows x86-64

pocketsphinx-5.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 10.9+ x86-64

pocketsphinx-5.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pocketsphinx-5.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.2 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pocketsphinx-5.0.2.tar.gz
Algorithm Hash digest
SHA256 e976dd55ffb26f5d4e14f2b4c7b69c200ed337107f45b79b66b415c388c3fc00
MD5 9c84163cc6897f3bbdaa7c5960db871d
BLAKE2b-256 e06da46f9500b38f2844b15d861a2b5a6bea248b3026fafc8eb94b56d60cffc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cbe870a2ac7ed0222fdd45459b7c579fcab226d1d9aade0edd150810465c281c
MD5 3b9d20db59297c062cabced4256caaa0
BLAKE2b-256 ade47e5edba198bc5523988f0d3ffd5419831061cc79fc3f935e6081e9707e89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 521be4c1a612aff24b7fc35a3333b89a8acce2229eae5d4b8b6284e3043f4e0d
MD5 d4681b5064e5298ba1611f1a1c6110be
BLAKE2b-256 1b9a7f7f09437d7b322649a69748b1a1dd062af2b9f57fbb159f65590c716119

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4baf4f2be222e136ea8b31b320a76944c6372e4813302ece0f2b272d8881acb0
MD5 905068e34cedb6c6282c8028bfc4444b
BLAKE2b-256 b10f667a18bdff3de6b5897594c8e08d09b113cfc428c750314658f48de8fc01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cf1e349d0e9783f93941179f675f42f7073a27385cf90839fb96809039d1c026
MD5 960e316245b52d5eb3223cd9ed9844c2
BLAKE2b-256 461732f6cf32994412a2f871a5e2e5c1a6a1a6b5b523fbf33575213305195b09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9ae46768ae1ccf868cdcd5147b5f090e994e91e82ac923de44e3d83d337212d6
MD5 a7d893965889b8f283dbf465851a00d3
BLAKE2b-256 c431c9acc92861a61d72f37fe95fd258edb36df4ee57771bdeafb5f5d7fbe3d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 298c6661be29387806b160fb7b38b32bd4732e44338a1478d79efc2aeda61f6c
MD5 53cb8abd4ce392991ec8041b5d502bc0
BLAKE2b-256 d34fdaceb03e0167998caa8d4f006138ba9c75a15a88b4c2947d8265af9b394b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6cc813422034b2d1252a6381acfe917fe47979358dbd2468c4a73526b9487d37
MD5 32a109a7d281ccb65a47e4d4f61c9c8e
BLAKE2b-256 ef0a78d229fb8716b6c863d63d83549bf90023c3d653281182f58a44b34725be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 12466fe1141dab12ba59304bc14ba1ee55af2c1131b80fe9724314d9310b2f32
MD5 de4366d86d1710e974346590fd50bd65
BLAKE2b-256 d2498cb0718624cceaf57a841b30b08b20abf3092c810a6f0409444c47eaef14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09520da93e1d42c3ad75d1687322ad8167b50ab59e56ba975430179522bc1ff7
MD5 8a94c75db3a31b86e7c2fe9f96e6e724
BLAKE2b-256 ff9936af6eb09ad61a44c54b3a54c1392984c7637764962ecf93ce1fbcd45416

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.0.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb8298b0d96b3cbaf75622121d7817dbf61cd15daf2c6f2b7fc5ff3c61d15e9e
MD5 bc3c6d1ee85dd504ce28e73ad3e8615b
BLAKE2b-256 e03bc6d8a00be51153350299841dd14650754e576c7c092234955e719809ec97

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