capture output sound linux alsa python

Work in progress!!!
Not sure about all the details yet, working on it.
Without using pulseaudio etc.. I wanted to capture the output of my soundcard in python.
I used modprobe snd-aloop
and added the following to my .asoundrc :

pcm.mixin {
type dsnoop
ipc_key 5978293 # must be unique for all dmix plugins!!!!
ipc_key_add_uid yes
slave {
pcm "hw:4,1"
channels 2
period_size 220
#buffer_size 4096
#rate 44100
periods 0
period_time 0
bindings {
0 0
0 1

ctl.mixin {
type hw
card 4

That pcm hw:4.1 I got from using cat /etc/asound/cards

in python I use now

self.inp = alsaaudio.PCM(type=alsaaudio.PCM_CAPTURE,mode=alsaaudio.PCM_NORMAL,card="plug:mixin")

It is important to set the self.inp.setperiodsize to the same value as in the asoundrc file etc..

This article was very useful!!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s