Skip to main content

Official Python bindings for PocketSphinx

Project description

PocketSphinx 5.1.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.1.1.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.1.1-cp313-cp313-win_amd64.whl (29.0 MB view details)

Uploaded CPython 3.13Windows x86-64

pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_x86_64.whl (29.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_aarch64.whl (29.1 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

pocketsphinx-5.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (29.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pocketsphinx-5.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (29.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pocketsphinx-5.1.1-cp313-cp313-macosx_10_13_universal2.whl (29.5 MB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

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

Uploaded CPython 3.11Windows x86-64

pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_x86_64.whl (29.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_aarch64.whl (29.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pocketsphinx-5.1.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (29.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pocketsphinx-5.1.1-cp311-cp311-macosx_10_9_universal2.whl (29.5 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

File details

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

File metadata

  • Download URL: pocketsphinx-5.1.1.tar.gz
  • Upload date:
  • Size: 34.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pocketsphinx-5.1.1.tar.gz
Algorithm Hash digest
SHA256 675778b309a22dfc9b7d37f7621976bba491d2a5f8c59696bd77fd6d07271355
MD5 726fe0e3fae63a26609ec4030c731e59
BLAKE2b-256 61e713e0e787ff467218de880310d79cba14424f13b87171ac44af0bde1e428c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1.tar.gz:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2ba7e6789a67119f581b85d156e523cd1876af5d30ebacbf7ed3cd85f61ec382
MD5 87731d9a0ceaf0f3869654432b865599
BLAKE2b-256 43d32ba1b70b1995f298bdc2430e78d40bb989fe390f685153c59513692e67bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp313-cp313-win_amd64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0ffe854397b11546a9f629472367c8b668583a5ebfefbc129a80875e0ec70bee
MD5 0606187e8c1070db0a4f124ab41c31cd
BLAKE2b-256 6af5b29391d051323e95f3408b2400f459f6e86e5b8449bfd38f80eb18bb3e63

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9328118d15c150b88885d79765e663f3c42a3601bb8c15e9ff42f44428b10d61
MD5 d5792298b96a1b546eba364dbc9f6132
BLAKE2b-256 17cc082f70632d6474052cace9c4cc4b0ce8666eb4b52553187b05d15c0e65d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp313-cp313-musllinux_1_2_aarch64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 38ff34e47b35f0caa1b58939806c4ab86c234a13536299c8c929a3cb45761941
MD5 9949e6aae47a4fa8defcb7ad37af3024
BLAKE2b-256 d132630fb5b204d354fbf408218e8c9019354d33c70d0b647eb52f8d4d0ab86e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c6741bebbec5a10d08971bd2fdc0a6c1f876ad20a27f73c598e81654612794d6
MD5 93f54c987de543e3e6c227a39ba07794
BLAKE2b-256 209f74d921c7338dbd7cd40609b0a1b5e7a5e5a2acd23aaa2f6004fb729639cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 8de78671858278dbe97bf9578ea25a70ac2162d49a3218155c874058ba4554fc
MD5 9495117b22179b9f73faee33b40cd24a
BLAKE2b-256 06e1c2820011a5a1c8931f50d9add2af4591a0f531b2d810bc0fe1bf048079ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 08e4d5cc7377932dae2e55191b34f9939d73bf2401046ca2bd03be6daf21ac3b
MD5 4bbb4eaa648a19cc9f86c99d0a9b9782
BLAKE2b-256 70f3a44c87be7e434866bf575c343fddc8f2b61065f831c747dd6af3d3702f21

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp311-cp311-win_amd64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 00fc4a43cbb2d2620557603c9d1d6a1d54998b13e1406d449a5d674a5309893c
MD5 55865e237cd561a535cd38d461c8edfa
BLAKE2b-256 93215b75e1487b98de1442ffbcb2df704beedf22905011d40c3cc1d99ebb76f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b29b014241edce4437a55b8743a3156deb0d383c919e923eac099e2fb16f8c14
MD5 16102941ec5fe130bc88887ad6f52938
BLAKE2b-256 49948d3beb892983cc44098a93ffd54241047902c347accb991669029497943f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp311-cp311-musllinux_1_2_aarch64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb8fd0fc7fb08dd8f85da21f5121f34ebf4186a5bee91ce85e2d358e69a448bf
MD5 66f75c138a1c4d6a1fd857faf927f735
BLAKE2b-256 7434d9db696560de8ea7347f630630b9f9e988093dc52ff02ea6bf1b6d41f21c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4742dc42c010caf5a2558cac910b0856d85c94e9bb0357ed4ff32f1f0d0837f9
MD5 e75d518f7123cf53dfd1c65b43c6d71b
BLAKE2b-256 9556e0da7c96e3af9b0fbca3db46a9a6c5389642ec17ff4a7fb1cde592db023b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pocketsphinx-5.1.1-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8cd1ae6f236c2d1941643d87b9136317f628878892fbcb873ab2795f715144d3
MD5 ca93b93fc9b554b783b7dcc6b50da16c
BLAKE2b-256 2acf1493946809382b0d60319fe338efb5141173ec58eb9ab5ca8c211d7cae4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.1-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: release.yml on cmusphinx/pocketsphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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