Switching audio output in pulseaudio on Linux

I have two separate audio cards on my workstation. One drives my main speakers, and the other drives my headphones. There are some GUI utilities out there to decide the “default” output, but nothing I could find that would allow me to move already-playing sounds to another device.

The handy pacmd utility can be used to control PulseAudio, the default sound server for many distributions. A peek at the man page reveals a move-sink-input subcommand which will allow one to move a specific actively playing audio stream to a different output device.

After finding this, I wrote up a simple set of aliases to work with this utility. Code below:

# The device names for my sound cards. You can find this by running "pactl list-sinks"
local headphones="'alsa_output.usb-0d8c_C-Media_USB_Audio_Device-00.analog-stereo'"
local speakers="'alsa_output.pci-0000_00_1f.3.analog-stereo'"

alias hp='pacmd list-sink-inputs | grep index | awk '\''{print $2}'\'' | while read i; do pacmd move-sink-input $i '$headphones'; done; pacmd set-default-sink '$headphones
alias sp='pacmd list-sink-inputs | grep index | awk '\''{print $2}'\'' | while read i; do pacmd move-sink-input $i '$speakers'; done; pacmd set-default-sink '$speakers

The hp alias will move all audio streams to my headphones, and the sp alias does the same for my speakers. The commands will also set the respective device as the default for all new audio streams.

Share and Enjoy:
  • StumbleUpon
  • Facebook
  • Twitter
  • Reddit
Switching audio output in pulseaudio on Linux

Leave a Reply

Your email address will not be published.