Pocketsphinx is a part of the CMU Sphinx Open Source Toolkit For Speech Recognition.
This package provides a python interface to CMU Sphinxbase and Pocketsphinx libraries created with SWIG and Setuptools.
Supported platforms
Windows
Linux
Mac OS X
Installation
# Make sure we have up-to-date versions of pip, setuptools and wheel:
$ pip install --upgrade pip setuptools wheel
$ pip install --upgrade pocketsphinx
More binary distributions for manual installation are available here.
Usage
LiveSpeech
It’s an iterator class for continuous recognition or keyword search from a microphone.
from pocketsphinx import LiveSpeech
for phrase in LiveSpeech(): print(phrase)
An example of a keyword search:
from pocketsphinx import LiveSpeech
speech = LiveSpeech(lm=False, 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
model_path = get_model_path()
speech = LiveSpeech(
verbose=False,
sampling_rate=16000,
buffer_size=2048,
no_search=False,
full_utt=False,
hmm=os.path.join(model_path, 'en-us'),
lm=os.path.join(model_path, 'en-us.lm.bin'),
dic=os.path.join(model_path, 'cmudict-en-us.dict')
)
for phrase in speech:
print(phrase)
AudioFile
It’s an iterator class for continuous recognition or keyword search from a file.
from pocketsphinx import AudioFile
for phrase in AudioFile(): print(phrase) # => "go forward ten meters"
An example of a keyword search:
from pocketsphinx import AudioFile
audio = AudioFile(lm=False, 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, get_data_path
model_path = get_model_path()
data_path = get_data_path()
config = {
'verbose': False,
'audio_file': os.path.join(data_path, 'goforward.raw'),
'buffer_size': 2048,
'no_search': False,
'full_utt': False,
'hmm': os.path.join(model_path, 'en-us'),
'lm': os.path.join(model_path, 'en-us.lm.bin'),
'dict': os.path.join(model_path, 'cmudict-en-us.dict')
}
audio = AudioFile(**config)
for phrase in audio:
print(phrase)
Pocketsphinx
It’s a simple and flexible proxy class to pocketsphinx.Decode.
from pocketsphinx import Pocketsphinx
print(Pocketsphinx().decode()) # => "go forward ten meters"
A more comprehensive example:
from __future__ import print_function
import os
from pocketsphinx import Pocketsphinx, get_model_path, get_data_path
model_path = get_model_path()
data_path = get_data_path()
config = {
'hmm': os.path.join(model_path, 'en-us'),
'lm': os.path.join(model_path, 'en-us.lm.bin'),
'dict': os.path.join(model_path, 'cmudict-en-us.dict')
}
ps = Pocketsphinx(**config)
ps.decode(
audio_file=os.path.join(data_path, 'goforward.raw'),
buffer_size=2048,
no_search=False,
full_utt=False
)
print(ps.segments()) # => ['<s>', '<sil>', 'go', 'forward', 'ten', 'meters', '</s>']
print('Detailed segments:', *ps.segments(detailed=True), sep='\n') # => [
# word, prob, start_frame, end_frame
# ('<s>', 0, 0, 24)
# ('<sil>', -3778, 25, 45)
# ('go', -27, 46, 63)
# ('forward', -38, 64, 116)
# ('ten', -14105, 117, 152)
# ('meters', -2152, 153, 211)
# ('</s>', 0, 212, 260)
# ]
print(ps.hypothesis()) # => go forward ten meters
print(ps.probability()) # => -32079
print(ps.score()) # => -7066
print(ps.confidence()) # => 0.04042641466841839
print(*ps.best(count=10), sep='\n') # => [
# ('go forward ten meters', -28034)
# ('go for word ten meters', -28570)
# ('go forward and majors', -28670)
# ('go forward and meters', -28681)
# ('go forward and readers', -28685)
# ('go forward ten readers', -28688)
# ('go forward ten leaders', -28695)
# ('go forward can meters', -28695)
# ('go forward and leaders', -28706)
# ('go for work ten meters', -28722)
# ]
Default config
If you don’t pass any argument while creating an instance of the Pocketsphinx, AudioFile or LiveSpeech class, it will use next default values:
verbose = False
logfn = /dev/null or nul
audio_file = site-packages/pocketsphinx/data/goforward.raw
audio_device = None
sampling_rate = 16000
buffer_size = 2048
no_search = False
full_utt = False
hmm = site-packages/pocketsphinx/model/en-us
lm = site-packages/pocketsphinx/model/en-us.lm.bin
dict = site-packages/pocketsphinx/model/cmudict-en-us.dict
Any other option must be passed into the config as is, without using symbol -.
If you want to disable default language model or dictionary, you can change the value of the corresponding options to False:
lm = False
dict = False
Verbose
Send output to stdout:
from pocketsphinx import Pocketsphinx
ps = Pocketsphinx(verbose=True)
ps.decode()
print(ps.hypothesis())
Send output to file:
from pocketsphinx import Pocketsphinx
ps = Pocketsphinx(verbose=True, logfn='pocketsphinx.log')
ps.decode()
print(ps.hypothesis())
Сompatibility
Parent classes are still available:
import os
from pocketsphinx import DefaultConfig, Decoder, get_model_path, get_data_path
model_path = get_model_path()
data_path = get_data_path()
# Create a decoder with a certain model
config = DefaultConfig()
config.set_string('-hmm', os.path.join(model_path, 'en-us'))
config.set_string('-lm', os.path.join(model_path, 'en-us.lm.bin'))
config.set_string('-dict', os.path.join(model_path, 'cmudict-en-us.dict'))
decoder = Decoder(config)
# Decode streaming data
buf = bytearray(1024)
with open(os.path.join(data_path, 'goforward.raw'), 'rb') as f:
decoder.start_utt()
while f.readinto(buf):
decoder.process_raw(buf, False, False)
decoder.end_utt()
print('Best hypothesis segments:', [seg.word for seg in decoder.seg()])
Install development version
Install requirements
Windows requirements:
Ubuntu requirements:
$ sudo apt-get install -qq python python-dev python-pip build-essential swig git libpulse-dev
Install with pip
$ pip install https://github.com/bambocher/pocketsphinx-python/archive/master.zip
Install with distutils
$ git clone --recursive https://github.com/bambocher/pocketsphinx-python
$ cd pocketsphinx-python
$ python setup.py install
Projects using pocketsphinx-python
SpeechRecognition - Library for performing speech recognition, with support for several engines and APIs, online and offline.
License
Metadata
Release files for pocketsphinx 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distributions (sdists)
| File | Size | Uploaded | |
|---|---|---|---|
| pocketsphinx-0.1.3.zip | 29.3 MB | Details | |
| pocketsphinx-0.1.3.tar.gz | 29.1 MB | Details | |
| pocketsphinx-0.1.3.tar.bz2 | 29.4 MB | Details |
Built distributions (wheels)
Total release size: 732.7 MB
Release files / pocketsphinx-0.1.3.zip
| Download URL | pocketsphinx-0.1.3.zip |
|---|---|
| Size | 29.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42c82f117009a7355f281932a5fe6bee1f68a432631712241c60d207ef267931
|
|
BLAKE2b-256 checksum How to use checksums |
0fdbd830b477f97fdce5bf575dbf8abc090208e0b3e5956b533adb0f56c8f973
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.tar.gz
| Download URL | pocketsphinx-0.1.3.tar.gz |
|---|---|
| Size | 29.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac125aadefc85ab78706a4d18ae66c3dcf89eb9e2a0cbd88c7a6086df420346d
|
|
BLAKE2b-256 checksum How to use checksums |
a04e70c500da7558d2a8e67fd8cfd33f5a4b90faf7163d7e4023fa989a89902a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.tar.bz2
| Download URL | pocketsphinx-0.1.3.tar.bz2 |
|---|---|
| Size | 29.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6bfa8e9a08026c46061364f59e9af8b0f4049142d4f155d9f07229d9b2d8281
|
|
BLAKE2b-256 checksum How to use checksums |
935fa968e5d53d25e32deb78c3e169fd8612ecf53cc76e32cb40e19be35696af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win-amd64-py3.5.msi
| Download URL | pocketsphinx-0.1.3.win-amd64-py3.5.msi |
|---|---|
| Size | 29.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f5ec0f812c3e346efd8143427fe1064b3fdc10038396caae0aca7afcba782e1
|
|
BLAKE2b-256 checksum How to use checksums |
15bd5f52cfe904674e1de24aaf75c2e2f43c880b2466a7e9f6b23ca1eaad0820
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win-amd64-py3.5.exe
| Download URL | pocketsphinx-0.1.3.win-amd64-py3.5.exe |
|---|---|
| Size | 29.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4dc0af673eb6d0523237ea66f2f72f9be38021c3e702e07d67718afd02220cac
|
|
BLAKE2b-256 checksum How to use checksums |
278c2a53866b00df6df028d7399da2c5fa14a1971f0945f4e8df9ab8b9ee0243
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win-amd64-py2.7.msi
| Download URL | pocketsphinx-0.1.3.win-amd64-py2.7.msi |
|---|---|
| Size | 29.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
da40cac571b9f2113bd0446b7fcb9a0e6d5e190e283d16864680fa83d45e2383
|
|
BLAKE2b-256 checksum How to use checksums |
e384a5bf08cf35db31bc6a774724c2244b2a6435a6b8504f77ae637c85f07621
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win-amd64-py2.7.exe
| Download URL | pocketsphinx-0.1.3.win-amd64-py2.7.exe |
|---|---|
| Size | 29.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e05e0ed601916e78d4854b23ce3699cd287208d63143b0c38bc060dbe4ccbcec
|
|
BLAKE2b-256 checksum How to use checksums |
afe2d360a05a459f7a3fdefaf052e2900697bce04cdd93857473d2a9aa7e7107
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win32-py3.5.msi
| Download URL | pocketsphinx-0.1.3.win32-py3.5.msi |
|---|---|
| Size | 29.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a57ab9c122540cd8b2d6a9658cbfa05197eb013120a9b91b11a49f96ce4f2a8c
|
|
BLAKE2b-256 checksum How to use checksums |
3500c26bb7a96b1f6126e3d2e8a140acf6c4fe80d34e42cc217e74f097e2271d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win32-py3.5.exe
| Download URL | pocketsphinx-0.1.3.win32-py3.5.exe |
|---|---|
| Size | 29.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6701ef8b107605771b52d60a592b65bae093cf533c3c070bd2ddb2807c609fde
|
|
BLAKE2b-256 checksum How to use checksums |
49e723d56e95b1271341211efb923c0aaf89b8424821e3637e44938c4de2ee65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win32-py2.7.msi
| Download URL | pocketsphinx-0.1.3.win32-py2.7.msi |
|---|---|
| Size | 29.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a65ea9e5c9218b529de7d5560d302bc95aa21741fd9564896fdf362e2cd0e82d
|
|
BLAKE2b-256 checksum How to use checksums |
977059d6dbcb027d5a58f808688ace273d0a7c1d0bbec9bfa9f1d59fcde22f8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3.win32-py2.7.exe
| Download URL | pocketsphinx-0.1.3.win32-py2.7.exe |
|---|---|
| Size | 29.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba144654675157c3c5ab890c86cfefbd495790e1ad9f8be97f64738bb0e7e785
|
|
BLAKE2b-256 checksum How to use checksums |
b5442ff32fc9039e8977b3bc03f4a0032d1687d6acf82357245fbc22c6d0a193
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py3.5-win-amd64.egg
| Download URL | pocketsphinx-0.1.3-py3.5-win-amd64.egg |
|---|---|
| Size | 29.2 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
9a254518c4ff7f57aec7bdc86792d391622768bbc348bb0e0ebb1cbcf55184da
|
|
BLAKE2b-256 checksum How to use checksums |
270794fb9090db6be0ef189009e3e3ed566097fd8a9f57973bc4485110e5d234
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py3.5-win32.egg
| Download URL | pocketsphinx-0.1.3-py3.5-win32.egg |
|---|---|
| Size | 29.0 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
9cb4b05b16b805c3460a323304b907f3a3609bb3e969ed09e361273f6ed16681
|
|
BLAKE2b-256 checksum How to use checksums |
df5fff3366170ea0f4cf3d65da6acb74505bcb9547dce9b20feadc16647e8aa6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py3.5-macosx-10.6-intel.egg
| Download URL | pocketsphinx-0.1.3-py3.5-macosx-10.6-intel.egg |
|---|---|
| Size | 29.6 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
21d0cfdeb78910b22562504c7d9a53868f64b9040888cc193c03198a849e5dae
|
|
BLAKE2b-256 checksum How to use checksums |
9bae142ec16d4b95aed25546bede07c7b1ac7c90c62026a1ae07f3a1b6d8e93f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py3.5-linux-x86_64.egg
| Download URL | pocketsphinx-0.1.3-py3.5-linux-x86_64.egg |
|---|---|
| Size | 30.1 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
c1951834ebc1c0bad31bb0bbb8337921e6333b63be1582f6fe2c14132cfba162
|
|
BLAKE2b-256 checksum How to use checksums |
58eb4fa5d423b3c708919ab9f08b2a42d445d088fcdbf1149c5f28589c148f1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py2.7-win-amd64.egg
| Download URL | pocketsphinx-0.1.3-py2.7-win-amd64.egg |
|---|---|
| Size | 29.1 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
7fc0d6de2c64448ff9370249723b9319c75ad2f524f0d57e30f80bf521fa26f1
|
|
BLAKE2b-256 checksum How to use checksums |
99049dd10675be3661a852ba4b114ca382240393806fd0aa50d63d528896cee3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py2.7-win32.egg
| Download URL | pocketsphinx-0.1.3-py2.7-win32.egg |
|---|---|
| Size | 29.0 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
019d2a2971f19aac3e319f2536fd1ff13b14ed9c7fbf9bc3440cb07fe261e5a4
|
|
BLAKE2b-256 checksum How to use checksums |
755101299d79ec354a0287a4fb3f1341be6bdf7dffb55448b1b3852bdc615a90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py2.7-macosx-10.6-intel.egg
| Download URL | pocketsphinx-0.1.3-py2.7-macosx-10.6-intel.egg |
|---|---|
| Size | 29.6 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
cb3a4c5427de4975269f9d6fec975fc958431e3382f31921830fda08a8b795a6
|
|
BLAKE2b-256 checksum How to use checksums |
7904912784a4e4bf23751203e05cb31aaf20de529bbc56e1636b51b92c77a862
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-py2.7-linux-x86_64.egg
| Download URL | pocketsphinx-0.1.3-py2.7-linux-x86_64.egg |
|---|---|
| Size | 29.1 MB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
9cee94eb0e861f7bba0bd9081176cd48bb49909fabb01330c2d1d1c1b336e7b1
|
|
BLAKE2b-256 checksum How to use checksums |
e1e8448fb4ab687ecad1be8708d152eb7ed69455be7740fc5899255be2228b52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-cp35-cp35m-win_amd64.whl
| Download URL | pocketsphinx-0.1.3-cp35-cp35m-win_amd64.whl |
|---|---|
| Size | 29.1 MB |
| Tags | CPython 3.5 CPython 3.5 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
59f6de8ec032dccf059e0c5c9f1a21df553b9cfb6f4d5ebcfe580634c849f376
|
|
BLAKE2b-256 checksum How to use checksums |
228cb3b20eb831d9277865c3d43feef1c6fe6b74a7723b6b1331ebccb1dc3a27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-cp35-cp35m-win32.whl
| Download URL | pocketsphinx-0.1.3-cp35-cp35m-win32.whl |
|---|---|
| Size | 29.0 MB |
| Tags | CPython 3.5 CPython 3.5 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
919503baba39604d6f1b8017a8fc239c41f77c7646748a0cc077001579a0bade
|
|
BLAKE2b-256 checksum How to use checksums |
f8001dfc90ece3f912bb78478b47a7fd0ce81ca8dd16149c9b6164fee2a712eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-cp35-cp35m-macosx_10_6_intel.whl
| Download URL | pocketsphinx-0.1.3-cp35-cp35m-macosx_10_6_intel.whl |
|---|---|
| Size | 29.6 MB |
| Tags | CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
9f932d7a6e2ec04ea8f0b019537fa0c92e702a226a02007223c55a46606c9568
|
|
BLAKE2b-256 checksum How to use checksums |
7cc1d209cfd1f99f1875343ab3215242f28e5f4a98c3d9604bf9b328b5ec7a3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-cp27-cp27m-win_amd64.whl
| Download URL | pocketsphinx-0.1.3-cp27-cp27m-win_amd64.whl |
|---|---|
| Size | 29.1 MB |
| Tags | CPython 2.7 CPython 2.7 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2b06fea365b55a40a0e51510b1b62a1575f264a38516ad20b940c133d569f6ef
|
|
BLAKE2b-256 checksum How to use checksums |
b23de37b6dfd325c9822556624a7bb5c15579fb90347c3b62239859ca686b726
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-cp27-cp27m-win32.whl
| Download URL | pocketsphinx-0.1.3-cp27-cp27m-win32.whl |
|---|---|
| Size | 29.0 MB |
| Tags | CPython 2.7 CPython 2.7 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
ccdc5fb5591649cd0edcdde541bc813b5f74bf5dd04872b937e551732eaa6847
|
|
BLAKE2b-256 checksum How to use checksums |
7ca7a6926f840fd56c979133676363ee534f6a9aefda3998bdc64247729c00a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pocketsphinx-0.1.3-cp27-cp27m-macosx_10_6_intel.whl
| Download URL | pocketsphinx-0.1.3-cp27-cp27m-macosx_10_6_intel.whl |
|---|---|
| Size | 29.6 MB |
| Tags | CPython 2.7 CPython 2.7 pymalloc macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
fdbf33d926aece1c56fc7772fe7763f371eb8b0029ed85b498558aba15a8eb21
|
|
BLAKE2b-256 checksum How to use checksums |
b3728c4bbaa3db8ce600c16f7ca4eebaebbbe7539612d66dc34e901b4c1d0216
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |