Skip to main content

Official Python bindings for PocketSphinx

Project description

PocketSphinx 5.1.0

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

Uploaded CPython 3.13Windows x86-64

pocketsphinx-5.1.0-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.0-cp313-cp313-musllinux_1_2_aarch64.whl (29.1 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

pocketsphinx-5.1.0-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.0-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.0-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.0-cp311-cp311-win_amd64.whl (29.1 MB view details)

Uploaded CPython 3.11Windows x86-64

pocketsphinx-5.1.0-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.0-cp311-cp311-musllinux_1_2_aarch64.whl (29.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

pocketsphinx-5.1.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: pocketsphinx-5.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 982778456a9c7658294c2c8998acf66daeb4e4ca5e1f342afd71de2c36b519ab
MD5 d219220c1acc01e5f69dfe8f75cda1df
BLAKE2b-256 67ddd58951dce63d91c373b83fa41bbbbb885817623d8264fba85255cb7bc656

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0.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.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4c3e375d969fcd71fd3505be18cd1c0ebbd738e1ae26f5f08a12c2a090b327be
MD5 e45b366ed78603f4859e77178778d8d9
BLAKE2b-256 0d11316d8e92b0b65a5f5d6b0129de3f1ca112028de279c1dd003b53fb659e0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8b0f28ddbeb43f7b358111e2024ad1bcb373b406e7724b0f6f364eea51756ff4
MD5 f45ce96e0f243abefa4d03abc03c2bc4
BLAKE2b-256 98264ea95f337302fb40bc4aa2e9217c910bce0280ac2aef9c9c81a144bbe507

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 797bf6fd78ec810518b7ac1977df87c6447779f14e7d8050c124aa00cb3043db
MD5 1cc550c817a0e40226b8cff20913a1b7
BLAKE2b-256 d43e9772238fb18ddd1b45fd95fd52038cf7cb77ebd90cfdf4cc6a0a65e2bdca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ceadf95f88738255fbb28c13261c847e7fde3e400315cb4cf8848c379aa45a4a
MD5 73521ec31e4e2c549e7b663f4168e190
BLAKE2b-256 c162f492a6bcae78ea2012d13211a27c658f32637ea96dbf2ce43763ad0df264

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cbea5730adeddf6aef36dea8b692d3b0143d1a253f5b0a2cb079f54c743f3d62
MD5 226897ee4237a87c18a81baa530571d6
BLAKE2b-256 a84fe141b3c550b2e595f503481a220972a6afa32e2d01544ee238de534da242

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 c8496406185f7560875452ba7f6671f6319b33dfb90b18d7c31e4c5891bf384e
MD5 b84187d4b7beebcf0f417fdf3e38cbea
BLAKE2b-256 de7be61c5c21ce82217e6df509fe20ff09de788f8ba3fe0e0fae61768867aa2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5988ab4fb48c97261dc240a68e569c649b50ef1b47267e0ea8341bebf7c3aa6d
MD5 9be1d1e820f55cd48ef4de386fe03f6f
BLAKE2b-256 6ea8ce3a7839469f75144824f2d790cc4df4e315784cd079bee0236d562ec791

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0cb223cc016b8603e6b1365c64f981e7974692977e468596219f89ca6a246ad0
MD5 2130bc58e6069034651701f3845b860f
BLAKE2b-256 0bc2d2a6f8edd242d756702a85071c05bb50903eeaa35d04096abfc6960442fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 04ff18262a7051e6d28554c01cfcc2a0221f530ad4b35adc93fc2e65c02dc5a4
MD5 f6f6b617f6b6032e7e2c77cd673374aa
BLAKE2b-256 4777b3c5408ef6f2e8ebf984e6e8d419584040a916523d5e567d3d389362ba98

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-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.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 96cc792023a10b1673f1b465ad0de5f9b3444be66d626172bcd315775ee81556
MD5 fbca3bef49af3e84fada5a2dcefdd5b9
BLAKE2b-256 b4e17be7ae47683123b0d086ab91877d1eda703a59a185a73a2ba01fd2a4f84a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 82fc8fdf1c4ab2bec2bb0bc4a2c37930a1ddb1655064fcd005826890497e3b25
MD5 9651b760a5c7f97291ef1b9661ab62ab
BLAKE2b-256 348317b9861caae4afbe254b4a7ba0d72ffa5a14b4c67d906799c73826eed07a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pocketsphinx-5.1.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b31cdb9bf2010969949ce6fa66440db347bc95234db72822771aeb02c312e20f
MD5 a20f09bb763375beccbe9f5d9b45c8e8
BLAKE2b-256 b1e7f5a45a423acbb8327d4ed1527a201c013589edbe962d992b5ad2237d8ab8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocketsphinx-5.1.0-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