Open geoffr98 opened 2 years ago
Can you please provide valid Python code?
See https://python-sounddevice.readthedocs.io/en/0.4.4/CONTRIBUTING.html#reporting-problems
Also, if you cross-post, please provide links in both directions. I guess this is you: https://stackoverflow.com/q/71161494/, right?
Yes, This is a cross-post from https://stackoverflow.com/q/71161494/
I've reposted the question with a sample program which will run.
Thanks for the update!
Now it seems to be valid Python code and I can actually run it, that's good.
I still have the feeling that a few things are missing, for example: what is Log
?
Anyway, this is far too much code for me to read.
Since it can take days before the problem happens I cannot confirm if this code shows the problem, but it should
Several days have passed, can you now confirm it?
What is supposed to happen in case of success? What is supposed to happen in case of failure?
I have updated the code to:
remove some of the extraneous code (leftover bits I hadn't removed when posting here) `` Yes the problem has happened again. I had updated the code above so that getting the data from the buffer is a bit different as I wanted to print out more info. (just replace the code in the example above if your want to duplicate):
try:
audio_data = Audio_rec_Buffer.get(True,2) #Block for up to 2 second
except queue.Empty:
#Handle empty queue here
Log.Log2("Could not get audio data from (" + str(Mic_Device) + ")" )
Debug_counter = Debug_counter +1
try:
SDstatus = sounddevice.get_status()
Log.Log2("Sound Device Status: " + str(SDstatus))
except:
Log.Log2("Could not get Sound Device Status " )
Err_msg = PrintException()
Log.Log2("\tError: " + str(Err_msg),0)
# Since we can't get the status.. check the Mic recoding Thread.
if Audio_Recorder_Thread.is_alive():
Log.Log2("Audio Recorder is alive")
else:
Log.Log2("Audio Recorder is dead - restarting..")
Record_Audio = True
Reset_Mic = True #does sounddevice._terminate() & sounddevice._initialize()
End_Program = False
Audio_Recorder_Thread = threading.Thread(target=Audio_Recorder , args=())
Audio_Recorder_Thread.daemon = True
Audio_Recorder_Thread.start()
continue #go back to the start of the while loop.
With the above code when the problem happens the following is printed out: (The code was working for quite awhile before the error happened) ` 2022-03-17 19:57:03.512110 Could not get audio data from (None) 2022-03-17 19:57:03.513310 Could not get Sound Device Status 2022-03-17 19:57:03.514833 Error: Smart_Device.py_Exception 1050 <play()/rec()/playrec() was not called yet <class 'RuntimeError'>> 2022-03-17 19:57:03.515163 Audio Recorder is alive
`
I don't understand the Mic_Device being None - I don't change it, but wondering if it's a hint as to the problem?
This is still far too much code.
Just try to reduce it further, and you'll very likely find the problem yourself.
If not, please share the reduced code.
I have some code running on a mac which is taking the microphone data from a bluetooth microphone to do voice commands, after which a response plays back on the speaker. Every now and again my code is no longer getting data from the microphone (I don't know why), so I tried adding a reset to the sounddevice, but that seems to hang - Can anyone provide some pointers to sort out why I might have these two problems.
Here is a version of my code with as much of the extraneous parts removed as I can. (Since it can take days before the problem happens I cannot confirm if this code shows the problem, but it should).