I need to change the audio device used on a python script. I'm using alsaaudio, and according to this http://pyalsaaudio.sourceforge.net/libalsaaudio.html this is achieved just by entering the card name when creating the PCM device. When I type on Python
import alsaaudio
alsaaudio.cards()
I get
[u'Intel', u'Q9000']
but creating the PCM object as
alsaaudio.PCM(aa.PCM_CAPTURE, aa.PCM_NORMAL, 'Q9000')
it returns
Unknown PCM default:CARD=Q9000
I've tried to modify the .asoundrc for having the configuration I want as default, but while it works with aplay and arecord on Python the default audio device is still the same.
On ~/.asoundrc I put
pcm.quicktimeWebCam
{
type hw
card Q9000
}
pcm.internal
{
type hw
card Intel
}
pcm.!default
{
type asym
playback.pcm
{
type plug
slave.pcm "internal"
}
capture.pcm
{
type plug
slave.pcm "quicktimeWebCam"
}
}
ALSA devices are represented by "hw:x,y", where x is the device and y is the subdevice (if any). It is expecting the card to be specified in the form of "hw:x,y", and not the human readable name.
card_info = {}
for device_number, card_name in enumerate(alsaaudio.cards()):
card_info[card_name] = "hw:%s,0" % device_number
device = alsaaudio.PCM(card=card_info["Q9000"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With