kelvinguu / simple-speech-recognition

A complete speech recognition system you can deploy with just a few lines of Python, built on CMU Sphinx-4.
63 stars 22 forks source link

Python wrapper for CMU Sphinx-4

A complete speech recognition system configured and ready to use with just a few lines of Python:

import cmu_sphinx4

# currently, the audio must be 16 kHz 16 bit mono in MS WAV format.
audio_URL = 'http://some.site.com/audio.wav'
transcriber = cmu_sphinx4.Transcriber(audio_URL)

for line in transcriber.transcript_stream():
    print line

transcriber.close()

Usage

Processing local files

To point the transcriber to a file on your computer, just prepend file://localhost to the front of your file path, which makes it a URL:

audio_URL = 'file://localhost' + '/Users/Kelvin/audio.wav'

Processing live/never-ending audio streams

The transcriber will output text as the audio is being read in, rather than waiting to read the whole file before processing. So, you can set the audio_URL to a never-ending or live audio stream and it will still work.

(transcriber.transcript_stream() is a generator which will keep producing lines of transcribed text while the audio keeps playing.)

A note on accuracy

The word error rate (WER) of the default configuration is roughly 0.48. This is still quite high due to the particular choice of parameters.

If you have a better configuration, I would love to incorporate it (and of course credit you here). You can let me know by creating an issue. (Click 'Issues' in the sidebar on the right.)

About CMU Sphinx-4

CMU Sphinx-4 is one of the most popular open source speech recognition systems, according to Wikipedia. However, it takes some effort to set up, and doesn't work on large vocabularies without some configuration. This Python wrapper has done all that work for you, so you can immediately start converting speech to text!

Dependencies

Install

cmudict.0.7a_SPHINX_40
hub4opensrc.cd_continuous_8gau
language_model.arpaformat.DMP
wsj_noisedict
# make sure that your current working directory is the root of this repo
cd simple-speech-recognition
# run the demo
python demo_simple.py
art or should require bonino streamers and maurice greene a university 
offering and lineman bruce slicks educate all course and embrace diverse
there it'll crabs sabina university is auckland esso buying a god he use less greedy

ott still there he taught that this land snow competence vote against the
government would seem to eye to eye think there'll also sulzer chamberlain on through

IMPORTANT NOTE: cmu_sphinx4.py depends on the files in lib.