python-sounddevice icon indicating copy to clipboard operation
python-sounddevice copied to clipboard

Update device list by reloading portaudio dll

Open HaujetZhao opened this issue 2 years ago • 1 comments

import sounddevice as sd

print(sd.query_device)

# some device info listed
# then plug some new device

sd._terminate()
sd._initialize()
print(sd.query_device)

# device info list unchanged

sd._terminate()
sd._ffi.dlclose(sd._lib)
sd._lib = sd._ffi.dlopen(sd._libname)
sd._initialize()
print(sd.query_device)

# device info list updated, it works fine


# is it possible to close the dll when sd._terminate()
# and reopen the dll when sd._initialize()
# so that the device_list can be updated by re initialize sounddevice

HaujetZhao avatar Dec 29 '23 08:12 HaujetZhao



# is it possible to close the dll when sd._terminate()
# and reopen the dll when sd._initialize()

Yes, I guess it would be possible, but the idea is that those two functions wrap the PortAudio functions Pa_Terminate() and Pa_Initialize(), respectively.

If additional functionality is desired, additional functions should be created.

But if the sequence of statements you mentioned is working for you, feel free to just use them in your code.


Related: #125, #343, #382.

mgeier avatar Dec 30 '23 15:12 mgeier