Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...