Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

python - OSError: [Errno -9985] Device unavailable. with sr.Microphone() as source in two different threads

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!

question from:https://stackoverflow.com/questions/65871634/oserror-errno-9985-device-unavailable-with-sr-microphone-as-source-in-two

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...