You can turn speech into text in Python. The SpeechRecognition module talks to the Google speech engine, so it works with any microphone and needs no training.
Scripting is where Python really pays off. The Python Scripting Essentials Bundle has the kind of small automation projects you would build for work.
It needs an internet connection, because the audio is sent to Google to be recognised. The example below records a short clip and prints what it heard.
This page shows how to use Python with Google’s speech engine.
Setting Up the Development Environment
Before you start, install what you need. The SpeechRecognition module works with pyenv, pipenv and virtualenv. For a global install:
pip install SpeechRecognition |
Note that that the SpeechRecognition library hinges on pyaudio. The installation methodology for pyaudio might differ based on the operating system. For example, Manjaro Linux users can find packages labeled “python-pyaudio” and “python2-pyaudio”. Always ensure that you’ve selected the appropriate package tailored for your OS.
Introduction to Speech Recognition
Try it with this and see what comes back:
python -m speech_recognition |
A Closer Look at Google’s Speech Recognition Engine
Google’s engine in a bit more detail. While this tutorial predominantly showcases its usage in English, note that the engine is proficient in handling many languages.
A one thing to know: this walkthrough employs the standard Google API key. If you’re inclined to integrate an alternate API key, modify the code accordingly:
r.recognize_google(audio, key="YOUR_GOOGLE_SPEECH_RECOGNITION_API_KEY") |
Save this as speechtest.py and run it with Python 3:
#!/usr/bin/env python3 |
Dive Deeper with Downloadable Speech Recognition Samples
The fastest way to learn this is to write it yourself. The PyChallenge exercises run in your browser, no install needed.

It works quite well for me
It doesn't run for me it just prints on the console "speak:" and doesn't do anything else
Check which microphone inputs are available and set the right input. Also try with different speech engines https://github.com/Uberi/sp...
Excellent!
How can I change the microphone settings? it doesn't seem to pick it up for me, mic is attached via USB
Make sure you have PyAudio installed. Then you can change the id of the microphone like so: Microphone(device_index=3). Change the device_index to the microphone id you need. You can list the microphones this way: