forked from robotstreamer/robotstreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio_util.py
32 lines (24 loc) · 1.06 KB
/
audio_util.py
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
31
import subprocess
import re
def getAudioPlayingDeviceByName(name):
return getAudioDeviceByName('aplay', name)
def getAudioRecordingDeviceByName(name):
return getAudioDeviceByName('arecord', name)
def getAudioDeviceByName(command, name):
text = subprocess.check_output([command, '-l'])
lines = text.splitlines()
for line in lines:
line = line.decode("utf-8")
if name in line:
print(line)
result = re.match("card (.*?):", line)
print(result.group(0))
print(result.group(1))
return int(result.group(1))
if __name__ == "__main__":
print("as a test, checking for Yeti mic")
print(getAudioRecordingDeviceByName("Yeti"))
print("as a test, checking for C920 mic")
print(getAudioRecordingDeviceByName("C920_1 [HD Pro Webcam C920]"))
print("as a test, checking for USB2.0 Device (the usb speaker)")
print(getAudioPlayingDeviceByName("USB2.0 Device"))