Speech Recognition in Python using CMU Sphinx

CMU Sphinx also known as sphinx, is an open-source toolkit for Speech Recognition. Talking about pocketsphinx, it is a part of CMU Sphinx which is used to recognize speech.

Now you might be thinking when we already have Google API, why use Sphinx?.

When you wish to work online, you can use Google API with Speech recognition which is more accurate, easy to install and use, but when you want to work offline(without the use of the internet) you can go with pocketsphinx.

Speech Recognition in Python using CMU Sphinx

You can visit the previous tutorial to get an idea about the use of Google API in speech recognition. Here’s the link¬†¬†Speech to text conversion in Python

In this tutorial, we will be learning about the use of pocketsphinx for Speech recognition.

Let’s go!!


Open your terminal and write pip install pocketsphinx

Sometimes, you might get an error due to the previous versions.

Make sure you have the latest version of pip, setuptools, and wheel. If not, then write the following commands one by one and hit enter.

python -m pip install --upgrade pip setuptools wheel


pip install --upgrade pocketsphinx

Once you have installed pocketsphinx on your machine, you are a step closer to Speech recognition without internet connection.

from pocketsphinx import LiveSpeech
for phrase in LiveSpeech():
    print("Sphinx cannot recognize")

To continuously recognize the keywords from the microphone, there is a class in pocketsphinx named as LiveSpeech which we have used in the above code.

The best part of using sphinx is it works offline and the worst part is its quality.

INPUT: How are you?
OUTPUT: how are you

I hope you understood the working of the above few lines of code.

Get voice input with microphone in Python using PyAudio and SpeechRecognition

Leave a Reply

Your email address will not be published. Required fields are marked *