All Projects → bambocher → Pocketsphinx Python

bambocher / Pocketsphinx Python

Licence: other
Python interface to CMU Sphinxbase and Pocketsphinx libraries

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pocketsphinx Python

Annyang
💬 Speech recognition for your site
Stars: ✭ 6,216 (+1985.91%)
Mutual labels:  speech-recognition, speech, voice
Speech Emotion Analyzer
The neural network model is capable of detecting five different male/female emotions from audio speeches. (Deep Learning, NLP, Python)
Stars: ✭ 633 (+112.42%)
Mutual labels:  speech-recognition, speech, voice
anycontrol
Voice control for your websites and applications
Stars: ✭ 53 (-82.21%)
Mutual labels:  voice, speech, speech-recognition
spokestack-android
Extensible Android mobile voice framework: wakeword, ASR, NLU, and TTS. Easily add voice to any Android app!
Stars: ✭ 52 (-82.55%)
Mutual labels:  voice, speech, speech-recognition
opensource-voice-tools
A repo listing known open source voice tools, ordered by where they sit in the voice stack
Stars: ✭ 21 (-92.95%)
Mutual labels:  voice, speech, speech-recognition
kaldi ag training
Docker image and scripts for training finetuned or completely personal Kaldi speech models. Particularly for use with kaldi-active-grammar.
Stars: ✭ 14 (-95.3%)
Mutual labels:  speech, speech-recognition
Phomeme
Simple sentence mixing tool (work in progress)
Stars: ✭ 18 (-93.96%)
Mutual labels:  voice, speech
voice-based-email-for-blind
Emailing System for visually impaired persons
Stars: ✭ 35 (-88.26%)
Mutual labels:  voice, speech
VAD-LTSD
Efficient voice activity detection algorithm using long-term speech information
Stars: ✭ 37 (-87.58%)
Mutual labels:  voice, speech
picovoice
The end-to-end platform for building voice products at scale
Stars: ✭ 316 (+6.04%)
Mutual labels:  voice, speech-recognition
react-client
An React client library for Speechly API
Stars: ✭ 71 (-76.17%)
Mutual labels:  voice, speech-recognition
Alan Sdk Android
Alan AI Android SDK adds a voice assistant or chatbot to your app. Supports Java, Kotlin.
Stars: ✭ 278 (-6.71%)
Mutual labels:  speech-recognition, voice
api
Speechly public API definitions and generated code
Stars: ✭ 15 (-94.97%)
Mutual labels:  voice, speech-recognition
simple-obs-stt
Speech-to-text and keyboard input captions for OBS.
Stars: ✭ 89 (-70.13%)
Mutual labels:  speech, speech-recognition
VoiceDictation
迅飞 语音听写 WebAPI - 把语音(≤60秒)转换成对应的文字信息,让机器能够“听懂”人类语言,相当于给机器安装上“耳朵”,使其具备“能听”的功能。
Stars: ✭ 36 (-87.92%)
Mutual labels:  voice, speech-recognition
KeenASR-Android-PoC
A proof-of-concept app using KeenASR SDK on Android. WE ARE HIRING: https://keenresearch.com/careers.html
Stars: ✭ 21 (-92.95%)
Mutual labels:  speech, speech-recognition
deepspeech.mxnet
A MXNet implementation of Baidu's DeepSpeech architecture
Stars: ✭ 82 (-72.48%)
Mutual labels:  speech, speech-recognition
UniSpeech
UniSpeech - Large Scale Self-Supervised Learning for Speech
Stars: ✭ 224 (-24.83%)
Mutual labels:  speech, speech-recognition
speech to text
how to use the Google Cloud Speech API to transcribe audio/video files.
Stars: ✭ 35 (-88.26%)
Mutual labels:  speech, speech-recognition
SignDetect
This application is developed to help speechless people interact with others with ease. It detects voice and converts the input speech into a sign language based video.
Stars: ✭ 21 (-92.95%)
Mutual labels:  voice, speech

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)

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>     |
# ----------------------------

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 libasound2-dev

Mac OS X requirements:

brew reinstall swig python

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].