I\'m running a speech recognition code on python as part of a project. I\'m facing a really odd kind of a problem When I put the speech recognition code inside a function l
Try that way:
r = sr.Recognizer()
m = sr.Microphone(device_index=2)
def loop():
with m as source:
print("say something")
audio = r.listen(source)
try:
print("you said "+r.recognize_google(audio))
except sr.UnknownValueError:
print("Could not understand")
except sr.RequestError as e:
print("errpr: {0}".format(e))
loop()
Don't create multiple Microphone() instances.