Python speech recognition error - Invalid number of channels

前端 未结 2 1205
不知归路
不知归路 2020-12-21 19:19

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

相关标签:
2条回答
  • 2020-12-21 19:49

    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).

    0 讨论(0)
  • 2020-12-21 19:51

    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.

    0 讨论(0)
提交回复
热议问题