-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwait_devices_init.py
More file actions
30 lines (21 loc) · 909 Bytes
/
wait_devices_init.py
File metadata and controls
30 lines (21 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Blocks until the sounddevice module is able to pick up all of the attached usb sound cards as seen by lsusb
"""
import subprocess
def num_sound_devices():
"""
Use an external call to sounddevice to get the number of devices detected by the library.
It's important to do this rather than just sounddevice.query_devices(),
:return:
"""
return str(subprocess.check_output(["python3", "-m", "sounddevice"])).count("USB Audio Device")
def wait_for_usb_sound_devices_to_be_initialized():
"""
Calling this function will block until the number of USB sound soundcard devices detected by lsusb matches
the number initialized by the sound device backend.
:return:
"""
while num_sound_devices() != str(subprocess.check_output(["lsusb"])).count("C-Media Electronics"):
pass
if __name__ == "__main__":
wait_for_usb_sound_devices_to_be_initialized()