Too much time is spent for speech recognition. The recognition takes over 15 minutes to run.
How can I make the speech recognition faster? Here's my code:
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
print("Recognizing...")
query= r.recognize_google(audio,language= 'en-in')
print(f"user said: {query}\n")
except Exception as e:
speak("Miss stark couldn't recognize what you said, speak once more.")
print("Miss stark couldn't recognize what you said, speak once more.")
query=None
return query
You can use this code more frequently using these lines added to your.
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
r.pause_threshold = 1
r.adjust_for_ambient_noise(source)
print("Listening...")
audio = r.listen(source)
try:
print("Recognizing...")
query= r.recognize_google(audio,language= 'en-in')
print(f"user said: {query}\n")
except Exception as e:
speak("Miss stark couldn't recognize what you said, speak once more.")
print("Miss stark couldn't recognize what you said, speak once more.")
return None
return query
And if this not works check your internet connection speed, because SpeechRecognition works through internet connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With