Skip to main content

Raspberry Pi Zero USB Audio on Raspbian Jessie (method 1)

I'm surprised how much of a pain it is to get a USB audio controller set up without a GUI.  I'm trying to use the RPi Zero, which doesn't have any audio hardware - not even a pin-based PWN situation.  Anything has to be done with extra hardware - either USB or custom analog with an ADC (analog-digital converter).

Note that extra static on the line seems to be related to the bitrate and frequency of the recording. If one has a lot of static, try another. The static on playback and when nothing is playing seems to be from the line - it's on a USB hub that also runs the powerful TP-Link wifi adapter.  Since USB is already directly connected to the RPi's GND, there isn't really anything else that can be done about the static.  Hence, custom hardware as the alternative.

There is more than one way to skin a cat; this is the first method, which I think I prefer.  The other method is here.

Overall, setting up audio on Linux and Raspbian is an overly complex process that is definitely not user-friendly.  I'm a user, and this was not a positive experience to sort out.

ID your sound card devices

Figure out what the card, device and subdevice numbers are.  This command makes it pretty straightforward.
cat /proc/asound/modules

Change default sound card to USB audio

ALSA configuration file has moved (source) - edit to reflect a new default device setting.  You want the default sound card to be the same number as your USB card (as found above).  Open the following file:
sudo nano /usr/share/alsa/alsa.conf
Look for the following two lines, and change the trailing 0's to match the number of your USB sound card.
defaults.ctl.card 1 # was 0
defaults.pcm.card 1 # was 0
Note: This is the same file previously located at
For some reason it was moved, and it's unfortunate that many of the tutorials dealing with USB audio are old enough to still refer to the old file location.

Allow USB audio to be set as default

Close that file.  There is another file which overrides the /etc/modprobe.d/ files and sets all USB cards with a negative (never default) index. (source - not sure about the overwriting thing, though, as the /etc/-based file doesn't exist.) Open it and comment out the relevant line.
sudo nano /lib/modprobe.d/aliases.conf
Comment out (put a # in front of) this line:
options snd-usb-audio index=-2
The file does say it doesn't need to be modified, but that's to prevent "unusual" cards from being set as default - which is exactly what we want.

Set USB as the default audio device

Open the user-specific alsa config file, back it up, and replace the contents.  (source and source)
cp ~/.asoundrc ~/.asoundrc.bak
sudo nano ~/.asoundrc
Replace everything in the file with the following. (alternative: use the existing format, and change the 0's to 1's)
pcm.!default plughw:Device
ctl.!default plughw:Device

pcm.!default {
    type hw
    card 1

ctl.!default {
    type hw
    card 1
The backup is located at ~/.asoundrc.bak.  If you're curious about that weird plughw string, run
aplay -L
to see a few examples of it. (this is a more complete version of the aplay -l command used above)

Test the results

A command to run a built-in sound file that tests the left and right channels. Disclaimer: it doesn't work for me.  I had to create a very custom file with specific formats in order to get a result.  (TODO later)
aplay /usr/share/sounds/alsa/Front_Center.wav

What didn't work

Tracking failures, for later.

Changing hardware defaults in aliases.conf

(source) Open and edit:
sudo nano /lib/modprobe.d/aliases.conf
Change and edit these lines.  One exists already, the second should be added directly below it.
options snd-usb-audio index=0
options snd_bcm2835 index=1
That way, all the problems are short-circuited from the beginning.

What happened: made the change, rebooted and ran aplay -l to see what was up: the USB device wasn't even listed.  Apparently, that lower-level adjustment was not pleasing to the ALSA gods.  A better magic is required.


I'm going to leave these here once I'm done as a permanent record in case anything goes wrong in the future.  They're good sources.

Extra Stuff

Other ways to check what audio devices are available

You can also use this to see what USB devices are connected:
After running the following command, look for the entry that refers to your USB audio device.
aplay -l
In my case, the entry showed card 1, device 0, and only one subdevice, numbered 0 as the USB audio device I wanted.  See below for my output.  (This is a RPi Zero with a USB audio device connected)
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: EarMicrophone [USB Ear-Microphone], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
And this one gives a more complete version than the lowercase option.

aplay -L


Popular posts from this blog

A Homemade Beowulf Cluster: Part 1, Hardware Assembly

A beowulf cluster lets me tie miscellaneous computers together and use their cpus like one large processor...I think.  Never done this before, still working on the details.

I'm building this with random laptops: generally i5s, and I think one's a Core Duo - it's half decent thing from 2011.  Might even throw in an RPi2 for good measure.

Make sure you read through this before starting.  You want to know what you're getting into.  Watch out, though - this is a long post.
Notes Since we're working on multiple computers here, not everything is going to be cut-and-paste.  I will make sure that it's as clear as possible, however.  There won't be any hand-waving or assumptions of prior knowledge.

I'm doing this with Linux Mint 18 on my primary laptop.
Primary Sources Setting up the cluster: src 1,  src 2, src 3 Hardware IngredientsSince the benefit of this tool is sharing computations between computers, you need a way to route that information.  Hence, an …

Installing Kaldi and Kaldi-Gstreamer-server on Ubuntu 16.04

Notes on the process of installing Kaldi and Kaldi-GStreamer-server on Ubuntu 16.04 LTS.  These were modified somewhat, since this is retroactively documented for my own benefit.
Kaldi is a state-of-the-art speech transcription engine, geared towards researchers and people who already know what they're doing.  I'm just trying to set it up.

Decide where to put Kaldi and make that your new working directory.
mkdir ~/tools/ cd tools Clone Kaldi from github.
git clone into this new location.
cd ./kaldi-master/tools Check for any dependencies.  There were a few things I needed to add to my Ubuntu installation; don't remember what they were.  Do whatever this output instructs.
extras/ Now comes the actual installation.
make cd ../src ./configure --shared make depend make Run this next to install the online extensions.
make ext Note: if you have more than one core in your machine, you can run make -j 4 to do make in parall…

A Homemade Beowulf Cluster: Part 2, Machine Configuration

This section starts with a set of machines all tied together with an ethernet switch and running Ubuntu Server 16.04.1.  If the switch is plugged into the local network router, then the machines can be ssh'd into.

This should be picking up right where Part 1 left off. src.  So.
Enabling Scripted, Sudo Remote Access The first step in the configuration process is to modify the root-owned host files on each machine.  I'm not doing that by hand, and I've already spent way too long trying to find a way to edit root-owned files through ssh automatically.

It's not possible without "security risks".  Since this is a local cluster, and my threat model doesn't include -- or care about -- people hacking in to the machines or me messing things up, I'm going the old fashioned way.  I also don't care about wiping my cluster accidentally, since I'm documenting the exact process I used to achieve it (and I'm making backups of any data I create).

Log into…