Today we are going to learn speech recognisition using python
If we want to learn Python from scratch, then Python Tutorial will help you lot.
First of all we have to install pyttsx3 module
Modules:-
pip install pyttsx3 pip install speechreconitionJust write both of the line in cmd or powersell to install both modules in your system environment
Now we are going to import pyttsx3 module
pyttsx3 is a text-to-speech or speech to text conversion library in Python. Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3.
Now its time to import speech recognition module for python to recognize our voice and speech.
Now, we'll create a function that actually do something. In the user defined function we are going to tell our python about the source of the audio and the Recognizer.
def get(): r= sr.Recognizer() with sr.Microphone() as source: print("say something") audio= r.listen(source) print("Done")
In this function, r is a variable used for Recognizer that will recognize the source of the audio.
we here calling speech recognition as sr and use Microphone as source of the audio.
audio is variable used to listen the sound.
We will use google speech Recognizer for our speech. It is the best speech recognition I ever used. We will use here try and except method. So that if there is any error in sound recognition we will get that error in except block and code will run after it.
try: text= r.recognize_google(audio) print("you said: ", text) except Exception as e: print("Error")
Now our code is Complete. You can now call the function and run the program successfully.
Comments
Post a Comment