Shortcut to switch between Analog Stereo output & HDMI audio output
Solution 1:
With pulseaudio we are able to select the output sink from the command line:
pacmd set-default-sink "SINKNAME"
This command can be used in a launcher, script or even assigned to a keyboard shortcut for fast switching between different sinks. Please replace "SINKNAME" by the name or number of your desired sink. A list of known sinks with their associated numbers and names is given by the command:
pacmd list-sinks
Note: Changing the output sink through the command line interface can only take effect if stream target device reading is disabled. This can be done by editing the corresponing line in /etc/pulse/default.pa
to:
load-module module-stream-restore restore_device=false
Alternatively we could run pulseaudio to simultaneously output sound to the internal audio device, and to the hdmi-device by running paprefs with the option to add a virtual output device:
Solution 2:
I found this very annoying myself and wrote a script to toggle the output:
#!/bin/bash
CURRENT_PROFILE=$(pacmd list-cards | grep "active profile" | cut -d ' ' -f 3-)
if [ "$CURRENT_PROFILE" = "<output:hdmi-stereo+input:analog-stereo>" ] ; then
pacmd set-card-profile 0 "output:analog-stereo+input:analog-stereo"
else
pacmd set-card-profile 0 "output:hdmi-stereo+input:analog-stereo"
fi
And then bound an unused key on my keyboard to execute it (see this).