Skip to main content

Python interface to CMU Sphinxbase and Pocketsphinx libraries

Project description

Pocketsphinx Python

Latest Version Development Status Supported Python Versions Travis Build Status AppVeyor Build Status License

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
python -m 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())

Compatibility

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

The BSD License

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-0.1.12.tar.gz (29.1 MB view details)

Uploaded Source

Built Distributions

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

pocketsphinx-0.1.12.win-amd64-py3.6.exe (29.7 MB view details)

Uploaded Source

pocketsphinx-0.1.12.win-amd64-py3.5.exe (29.7 MB view details)

Uploaded Source

pocketsphinx-0.1.12.win-amd64-py2.7.exe (29.3 MB view details)

Uploaded Source

pocketsphinx-0.1.12.win32-py3.6.exe (29.5 MB view details)

Uploaded Source

pocketsphinx-0.1.12.win32-py3.5.exe (29.5 MB view details)

Uploaded Source

pocketsphinx-0.1.12.win32-py2.7.exe (29.2 MB view details)

Uploaded Source

pocketsphinx-0.1.12-cp36-cp36m-win_amd64.whl (29.1 MB view details)

Uploaded CPython 3.6mWindows x86-64

pocketsphinx-0.1.12-cp36-cp36m-win32.whl (29.0 MB view details)

Uploaded CPython 3.6mWindows x86

pocketsphinx-0.1.12-cp36-cp36m-macosx_10_13_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.6mmacOS 10.13+ x86-64

pocketsphinx-0.1.12-cp36-cp36m-macosx_10_12_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.6mmacOS 10.12+ x86-64

pocketsphinx-0.1.12-cp36-cp36m-macosx_10_11_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.6mmacOS 10.11+ x86-64

pocketsphinx-0.1.12-cp36-cp36m-macosx_10_10_x86_64.whl (29.1 MB view details)

Uploaded CPython 3.6mmacOS 10.10+ x86-64

pocketsphinx-0.1.12-cp35-cp35m-win_amd64.whl (29.1 MB view details)

Uploaded CPython 3.5mWindows x86-64

pocketsphinx-0.1.12-cp35-cp35m-win32.whl (29.0 MB view details)

Uploaded CPython 3.5mWindows x86

pocketsphinx-0.1.12-cp27-cp27m-win_amd64.whl (29.1 MB view details)

Uploaded CPython 2.7mWindows x86-64

pocketsphinx-0.1.12-cp27-cp27m-win32.whl (29.0 MB view details)

Uploaded CPython 2.7mWindows x86

pocketsphinx-0.1.12-cp27-cp27m-macosx_10_13_x86_64.whl (29.1 MB view details)

Uploaded CPython 2.7mmacOS 10.13+ x86-64

pocketsphinx-0.1.12-cp27-cp27m-macosx_10_12_x86_64.whl (29.1 MB view details)

Uploaded CPython 2.7mmacOS 10.12+ x86-64

pocketsphinx-0.1.12-cp27-cp27m-macosx_10_11_x86_64.whl (29.1 MB view details)

Uploaded CPython 2.7mmacOS 10.11+ x86-64

pocketsphinx-0.1.12-cp27-cp27m-macosx_10_10_x86_64.whl (29.1 MB view details)

Uploaded CPython 2.7mmacOS 10.10+ x86-64

File details

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

File metadata

  • Download URL: pocketsphinx-0.1.12.tar.gz
  • Upload date:
  • Size: 29.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pocketsphinx-0.1.12.tar.gz
Algorithm Hash digest
SHA256 ab83f9b4cd796f5c5aaf18a1bbdb4a2e931e0da4bc0390b210602003ff41ab45
MD5 5fe9773031fd69171f36f0313c1c1d31
BLAKE2b-256 4d542e617b6103eae745ff4304f94ac7780362e9fe0296a7431b1b0922fb1eb3

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12.win-amd64-py3.6.exe.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12.win-amd64-py3.6.exe
Algorithm Hash digest
SHA256 dbb2cc1417144e67246c44abd3c47c076275dc4e98b313816cf1e41c97836ec9
MD5 520a0ed3d627b8b724404fd395667254
BLAKE2b-256 b2e64ddc0116b5820a19266d0635895c527c0d4e004551e782bd708e68796bec

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12.win-amd64-py3.5.exe.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 557719af61457ffd1fee74b9fcf623c7f270d2b412448de4b2c472ba54025ad0
MD5 7fff420e474868f6da606ea3b8e7240e
BLAKE2b-256 156b09f275bf53c40c20d55abb3b49c9e55c2d2b8c87f137630dc9c08a6a116a

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 4c62669d446ecbc7059578a53e4c215f4479179d542e47f65c16919443b4d4d6
MD5 3d419dba6325df5980b5ca60ffcbdfed
BLAKE2b-256 c3b53d1a4ecea4dd7e1055bdddb3d4db8a675439bb6fb225066f3bed685c8abc

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12.win32-py3.6.exe.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12.win32-py3.6.exe
Algorithm Hash digest
SHA256 a2c89e9dc82180d85fd7c0ff03b6eed716bf7950c76c438566721e858a88fb7b
MD5 e1e7cfde74bb4d73e6e50579b9e80972
BLAKE2b-256 3b87c712f4d8636d45dbb057af7a9e4d3fb4f37b25106a5fa869e5e1ffed0244

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12.win32-py3.5.exe.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12.win32-py3.5.exe
Algorithm Hash digest
SHA256 0c2121e46eeab2bafcc11cb68015732cca3e2476fbfe4c78da3aec150c826699
MD5 22757072f64c005d016a9f5a056babf3
BLAKE2b-256 7e16d492cd93d2f8519eb1ddc4c1a4e634c4724df0974e6b9f01540672ecbe42

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12.win32-py2.7.exe.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12.win32-py2.7.exe
Algorithm Hash digest
SHA256 3340a87859bf6de8961d97ba3d7ee0a010ae4a9e3992562f40a65d71850606be
MD5 8cc103dac0adf12aa7f79af198c52398
BLAKE2b-256 7f1085e421a2375e466ab442d723fffa9452d8dbbd67fd17618d0d3cad8092c7

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 fcdaa66ced5167d5badce4d2030edc3e1224df295b1def9b7d0d8481344296fe
MD5 93dd59f4f812a0c473444cc6307ef1dd
BLAKE2b-256 3162080c98a207dd595c126a8c5d2d985783c76d939ae390b8fbe561b367cc6d

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 a69165b2fc3c4e0422e95eec28b086914ffcb60584042c4321fa3588eaad4d08
MD5 b32a744b837fa4697eac53d083af05f8
BLAKE2b-256 60700100f94458a20161106d3493cdf95e34b9628d639fd441c5fe406485fee0

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 8a8ab0455959fe047473378887f052a9df6e42ceae3e0fe55bf69bb4204e3547
MD5 a120771741520275084b1acf9d57aab1
BLAKE2b-256 8b940adaffd6c1f3f626d7c85b8b7a7a0363b8d99d24e76b99a80ea4f90bba2c

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp36-cp36m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 51ae1bd41f525421f1d2ee27e2139967f419dd4d61823e8a688bd74198910f0a
MD5 1fd6c9f7c016470dd6db610d23b36cf1
BLAKE2b-256 4eb1b87cdbe7987d0a75d90422945bb1149fa6bad6b395c5c09836ce1641042b

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp36-cp36m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 9c4adb24236913ff07d105651ea4dde1abaa722d8656e1bebed0d5af7e1e3f80
MD5 40d0f5502f68f1d9210282d1ed91e7cc
BLAKE2b-256 3c765a3cd989da82cbbc99fe11b1a671c69ce56c55119b5bd17e9d5d4f83e883

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp36-cp36m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 b818ca2b50ffec9a1a7bbf34d94addfe79bd6b79c7dda0ffd3ff931bcdf1a42f
MD5 1c737812f1da3f9257029a71c7544361
BLAKE2b-256 75fc8aa503c49d87e4a94c3c2a6eff4257ced9c83c9d7027881ec01f76719982

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 85082d2402850cae08f5ee00965195edccc0f81b11fcc30f10d530673194f2a4
MD5 ac14f8ab6b869991f2039004e6f5eb95
BLAKE2b-256 391661d990d409883280a5c02be0df27b6537b4f07707df2bbdebfbaac7912ba

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 5cc33486db43bf1a75a42c0c2e440d1dd95508b7b7fe9df97241ca5b2e7a0f65
MD5 cf3de727910f574b49c2296a5047d247
BLAKE2b-256 54a5cc04e848ce4b63624f99f8986794f28f5dfa8658707b05ea4020384802fd

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 c204269241296cc72027a38de39287c9cd269dee37cb1807afbd58d86874e3dc
MD5 0be59c7bd9c852981ae66a318dbdf437
BLAKE2b-256 8093235dc02556b1b8f262b9896a5fd578fc71aaa8a4eb27efac8ca6b6043520

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 2a5316557120994cce2700fd3cde39df0d15f45a89e668816dba3402e01c5323
MD5 46157721174e04bdcffe54115a78c889
BLAKE2b-256 2c46ebe7715953f102d9b6fbbf15e8ebf882ec9136e0ce20c0f04296b2b58b62

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp27-cp27m-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp27-cp27m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b04552f2b8b08d865bf845ab10dbdd0099d905a1f462934461dbe9fe747e5bfb
MD5 06f3d102fce6ccb08bd2cc36775efd69
BLAKE2b-256 efbf264efabd4e8e4baad831d93e286d8df5e8a48bc927e484b696cdd44b8ea7

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp27-cp27m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp27-cp27m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2138283824bc9fbbe36b553537414198966d395909d563700aae4e2dda22a645
MD5 e6d130ffa9411857423796c81dad5334
BLAKE2b-256 eb215dd1d47b212fa7e458c91dde1390f26d6198d5e6386836c95b51f68862d2

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp27-cp27m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp27-cp27m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 99d5ecab0c2a2e276ba1526e7a7e4717a1db9a87c8bd7657a7a3e463a439e6de
MD5 f121b6d7bb4635da962b0d1e396fd997
BLAKE2b-256 e8b56cd152c037da9d167834f4de2d764f05b0c6af94991734614820afe21175

See more details on using hashes here.

File details

Details for the file pocketsphinx-0.1.12-cp27-cp27m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for pocketsphinx-0.1.12-cp27-cp27m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 b7a8dc5d4948bf8958497bda1f46901a6cb33427884feea560c93cb19211450e
MD5 f7d4dde6737b798df1f6ca4c62edc3f4
BLAKE2b-256 7a28fa9085b526fa87eacae1f011f4c89390c2e2b0d98fef6d75ce54173f1f27

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