free speech recognition api python code example
Example: python speech recognition
import speech_recognition as sr
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
engine.setProperty('rate',180)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening.....')
r.pause_threshold = 1
r.energy_threshold = 4000
audio = r.listen(source)
try:
print('Recognising...')
query = r.recognize_google(audio, language='en-in')
print('User Said : ' , query)
except Exception as e:
print('exception : ',e)
speak("Sorry, I didn't hear that, Say that again Please")
return "None"
return query
while True:
query = takecommand()
print("The Test got in program is : "+query)