spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
980 stars 145 forks source link

Update device list by reloading portaudio dll #516

Open HaujetZhao opened 6 months ago

HaujetZhao commented 6 months ago
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
mgeier commented 6 months ago

# 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.