Make tests more robust, use devices or card indices.

This commit is contained in:
Lars Immisch
2017-02-22 23:55:17 +01:00
parent 85ff47ad43
commit dc51fa75b5
5 changed files with 26 additions and 35 deletions
+7 -7
View File
@@ -4,7 +4,7 @@
##
## This is an example of a simple sound capture script.
##
## The script opens an ALSA pcm forsound capture. Set
## The script opens an ALSA pcm device for sound capture, sets
## various attributes of the capture, and reads in a loop,
## writing the data to standard out.
##
@@ -22,17 +22,17 @@ import getopt
import alsaaudio
def usage():
print('usage: recordtest.py [-c <card>] <file>', file=sys.stderr)
print('usage: recordtest.py [-d <device>] <file>', file=sys.stderr)
sys.exit(2)
if __name__ == '__main__':
card = 'default'
device = 'default'
opts, args = getopt.getopt(sys.argv[1:], 'c:')
opts, args = getopt.getopt(sys.argv[1:], 'd:')
for o, a in opts:
if o == '-c':
card = a
if o == '-d':
device = a
if not args:
usage()
@@ -42,7 +42,7 @@ if __name__ == '__main__':
# Open the device in nonblocking capture mode. The last argument could
# just as well have been zero for blocking mode. Then we could have
# left out the sleep call in the bottom of the loop
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, card)
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, device=device)
# Set attributes: Mono, 44100 Hz, 16 bit little endian samples
inp.setchannels(1)