I'm trying to build a simple python program that will capture audio from 2 different audio inputs and then play audio from 1 of them. I bought 2 USB sound cards so I could do this.

I started with an even simpler program just to capture and play audio from one of the sound cards:

#!/usr/bin/evn python

import alsaaudio, sys
import time

channels = 1
sample_size = 1
frame_size = channels * sample_size
frame_rate = 44100
byte_rate = frame_rate * frame_size
period_size = 1024

inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL)

out = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL)

def main():
  while True:
    l, data = inp.read()
    if l:

if __name__ == '__main__':
  print("something is happening")

Originally, this worked great, but when I added a 2nd USB and pointed the output to that via 'hw:1,0' in the out = line, the sound quality nosedived to pretty much just a solid beeping/humming/staticking noise that my ears are still recovering from.

I went down some rabbit holes trying to troubleshoot this, and things have gotten worse. Now even the original program from just 1 USB outputs terrible audio. I know it's not a problem with the sound card because it's happening on either USB device and NOT when I play a local file on the RPi. I also know it's not a problem with my Aux cables.

Some of the things I've done on the way down the rabbit hole:

  • blacklisted RPi's native bcm2835 sound card
  • set aliases for the 2 USB sound cards in ./asoundrc
  • deleted Pulse Audio

But I think the most likely culprit is that when changing the ~/.asoundrc file, I deleted a default slave term that I can't remember. Right now my .asoundrc file only has the alias declarations for both USB cards... nothing else. I don't understand the master vs. slave stuff very well, so I'm not sure if a formatting error there can cause these kinds of audio problems. I'm hoping they can, since it seems like it would be an easy fix.

  • I have a feeling this is what I need to be doing with my .asoundrc file: gist.github.com/Solonarv/d28e8b50c8597778dd1e - though I'm not sure how to implement it to my program. Adding to my .asoundrc file as is and running comes up with an error that "int is not defined for inp." Apr 17, 2017 at 7:11
  • What's connected to the inputs of your USB devices while you're capturing audio?
    – goobering
    Apr 17, 2017 at 7:51
  • Does the RPi's crappy USB controller even have enough bandwidth to handle three USB audio streams at the same time?
    – CL.
    Apr 17, 2017 at 8:07
  • @goobering - I've been using either a phone or laptop playing music through an aux cord. Apr 17, 2017 at 14:49
  • @CL - it had enough to handle 2 streams well at one point at least. The fact that there was a sudden drop-off in quality tells me something else is wrong though. Apr 17, 2017 at 14:51

1 Answer 1


Take 5V to your multiple USB sound cards from an USB splitter connected to your RPI. It probably need the same point of ground.

I guess it can work. I moved the USB connector from adapter to RPI USB port. The humming 50Hz sound disappeared totally. This works for 5V powered audio. Some countries use 60Hz power supply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.