speech_recognition icon indicating copy to clipboard operation
speech_recognition copied to clipboard

with sr.Microphone() as source in two different threads.

Open nickhir opened this issue 4 years ago • 0 comments

Hello,

I am using speech_recognition version 3.8.1.

In my main thread, I have loop running that is constantly listening and processing the speech.

I have another thread running which executes the following code:


def butten_pressed():
    global r
    ### INITIALIZE GPIO
    setup()
    while True:
        if not GPIO.input(20):
            with sr.Microphone(sample_rate=44100, chunk_size=1024) as source:
                r.adjust_for_ambient_noise(source)
                print("Listening due two button press")
                audio_queue.put(r.listen(source))

As soon as I press a button on my raspberry pi the with sr.Microphone(sample_rate=44100, chunk_size=1024) as source: gets triggered. However this throws an error: OSError: [Errno -9985] Device unavailable. I assume this is because the main thread is already using my microphone, so I was wondering if it is possible, to nonetheless initialize the microphone again or if you have an idea how I could use the already in the initalized microphone from the main thread in the other thread.

Cheers!

nickhir avatar Jan 24 '21 14:01 nickhir