spatialaudio / python-sounddevice

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

Continuously getting default device causes problems #361

Closed lucatatas closed 2 years ago

lucatatas commented 2 years ago

Hi, I am trying to get the name of the current default output device by using: sd.query_devices()[sd.default.device[1]]["name"] This works just fine, so I was trying to do something like this: while True: print(sd.query_devices()[sd.default.device[1]]["name"]) time.sleep(5) Unfortunately this does not work like it's intended. Rather than constantly printing the current default output device, this always outputs the output device which was the default device at the startup of the script. When I change my default device in the windows settings and then restart the script, it also prints the new default device, so it does detect changes of the default device, but sadly not when I try to get the default device constantly by utilizing a while loop for example. I hope I made clear, what my issue is.

Thanks in advance!

lucatatas commented 2 years ago

Good news! I have actually solved the problem by myself after reading some other issues: Apparently, you have to re-initialize the library, when you want to get the default device constantly, so I added the following: sd._terminate() sd._initialize() before my print statement, this works just fine.