forked from letsRobot/letsrobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_util.py
More file actions
26 lines (21 loc) · 749 Bytes
/
audio_util.py
File metadata and controls
26 lines (21 loc) · 749 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
import subprocess
import re
import logging
log = logging.getLogger('LR.audio_util')
def getAudioDeviceByName(name, command):
text = subprocess.check_output(command)
log.debug("devices : %s", text)
lines = text.splitlines()
for line in lines:
if name in line:
log.info("Found Audio Device : %s", line)
result = re.match("card (.*?):", line.decode('utf8'))
return int(result.group(1))
else:
log.error("Unable to find Audio Device : %s", name)
# get microphone device number
def getMicByName(name):
return(getAudioDeviceByName(name, ['arecord', '-l']))
# get speaker device number:w
def getSpeakerByName(name):
return(getAudioDeviceByName(name, ["aplay", "-l"]))