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
Is access to the channel exclusive? Can only one thread hold access to the microphone? Your problem might be that you are trying to access the microphone multiple times concurrently (multiple loop calls) rather than just access it once (outside of loop).
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.