I was trying to use Speech Recognition for my Deep Learning Chatbot to get the input from the user. Actually my Speech-Recognition function code is this:
def
The duration parameter is deprecated now. Ref StackOverflow question.
Instead use phrase_time_limit
or timeout
.
Here is the block of code using phrase_time_limit
:
import speech_recognition as sr
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source, phrase_time_limit = 5)
try:
command = r.recognize_google(audio).lower()
print("you said: " + command)
except sr.UnknownValueError:
print("Sorry, Cant understand, Please say again")
command = myCommand()
return command
This works perfectly fine.