ALSA: Switch audio output to USB Headset

I recently purchased a USB headset.
Here’s how to get it working with ALSA, manually and automatically.


(From ALSA ArchWiki)

Load module:

# modprobe snd_usb_audio

Verify that module is loaded:

$ lsmod | grep snd_usb_audio
snd_usb_audio          93519  3 

Find corresponding card ID:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 2: P780 [Plantronics GameCom 780], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Set card ID as default audio device in ~/.asoundrc:

defaults.ctl.card 2
defaults.pcm.card 2

The manual method works fine if the headset is always plugged in.


It would be better if we could automatically change the default audio device based on whether the USB headset is plugged in or not. This can be achieved by using udev rules.

Add the following to /etc/udev/rules.d/00-local.rules:

# Set USB headset as default sound card when plugged in
KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"

# Restore default sound card when USB headset unplugged
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"

udev automatically detects changes to rules. However, you will need to unplug and replug the headset for changes to be be triggered.

Audio applications need to be restarted whenever default card changes. If anyone knows a way of switching audio devices without restarting applications (using ALSA, not Pulseaudio), please let me know.

One Comment

  1. Cian says:

    I’ve been thinking of getting one of these Plantronics GameCom 780 headsets and I’m wondering if you had any issues with them on Arch Linux? Does everything work as expected?

Leave a Reply