Developer & Programmer

Hey!, My name isZaiyan Khan

I'm a Designer & Developer

Download Resume

Speech Recognition in 10 Just Lines of Code Using Python

Python is a wonderful language, isn’t it? Apart from the ease of programming, it also offers you a bunch of advanced libraries and methods using which you can easily develop your speech recognition module.

In this tutorial, I’ll teach you how easily you can add speech recognition feature in your python program in less than 10 lines of code.

Step 1. Download the following libraries

  1. Speech_Recognition – pip install SpeechRecognition
  2. pyAudio – pip install pyaudio

Step 2.  Create a python file “speech.py” and paste the below code

import speech_recognition as srec
rec = srec.Recognizer()
with srec.Microphone() as source:
print("Speak");
audio = rec.listen(source)
print("Done")
try:
print("Speech : "+rec.recognize_google(audio));
except:
pass;

The script doesn’t even need 10 lines of code, in fact, just 4 lines of code are actually used for recognition and print statement is used to print the text.

Step 3. Run the script and woohoo, you have your Speech Recognition module in python.

Demo

As you can see in the screenshot, I spoke “Hi how are you doing” and that’s what the script returned as text.

  • Share this :

Leave a comment