Closed arkadiy-telegin closed 1 year ago
I've been trying to replicate the issue and it's just not happening. What I am getting are some random ALSA errors declaring the device busy.
Could you elaborate on what your environment is? OS version, audio API, that sort of thing.
Bloody hell that took some work. Okay, I think I've got it. Essentially, the issue comes down to ALSA and the behavior of its "default" audio device.
If nothing else is playing, it will work correctly the first time you try to play back audio. On subsequent runs, the audio device used for the playback becomes unavailable (I noticed this by listing all audio devices every time).
Normally, if you don't specify a deviceID, sounddevice (the library I use for the playback) will just pick the default output device, which in this case is the ALSA "default" device.
The problem arises when the REAL audio device is marked as busy by ALSA. It seems like the "default" device picks whatever other audio device isn't marked as busy, resulting in the second playback technically working (and seemingly being on the same device as the first one) but outputting to another device (likely one that is disconnected, hence the lack of audio).
I'll do some digging and try to figure out how to fix this.
Thanks! Really appreciate it!
Some debugging later, it appears I was (partially) correct. That does seem to be the issue, but the generate_play_audio function has no issues with it, even down to playing two simultaneous audios.
I believe the issue comes down to the fact that the stream function uses sounddevice's RawOutputStream, whereas the non-streaming one uses OutputStream. I'll see if I can't switch to the latter for the stream as well, but I don't think so.
I am genuinely at a loss. I'm going to try and isolate the issue down into a minimum reproducible code sample, then I'll probably make an issue on the sounddevice repo.
I believe I've actually figured out what the issue is. I still think it's related to sounddevice, but not in the way I initially thought. I'll do some more testing tomorrow and write up what the bug was if I actually manage to figure out a fix.
Turns out this was all actually a race condition that had gone completely undetected as it never happens on windows.
The thread that pulls sound data from the queue was actually running BEFORE the queue ever got filled, and triggering an error. This only happens on linux for some reason, maybe some difference in the thread scheduling? Who knows.
Bug is now fixed in release 0.8.1
Big thanks! It's working now!
For some reason streaming (
generate_and_stream_audio
) doesn't work on my Linux machine. I get no sound at all. I installed all the dependencies mentioned in the README.Here is the debug trace: