Making working from home even lazier
Working from home encourages home office optimization. During the COVID-19 period, with way more video conferences than usual, certain improvements were found necessary.
I guess everyone that’s been in a video meeting where more than one participant used a regular mic and regular speakers has experienced the wonders of audio feedback. That prompted me to acquire a comfortable gaming headset with a microphone, and I got myself a HyperX Cloud Flight wireless headset at a reasonable price.
I’m using GNOME on my Linux desktop. I find it quite efficient for my work, but the task of changing the sound output and input back and forth between my mic headset and the docking station’s line out and my web camera’s microphone requires just a bit too much point and click for one who prefers keyboard shortcuts for efficiency. To remedy this, I wrote a short bash script for toggling between the different audio components:
#!/bin/bash
# Note: Only two inputs to toggle between.
WEBCAMMIC="HP Webcam HD 4310 Analog Stereo"
HEADSETMIC="HyperX Cloud Flight Wireless Headset Mono"
# Note: Only two outputs to toggle between.
LINEOUT="USB Audio Line Out"
HEADSET="HyperX Cloud Flight Wireless Headset Digital Stereo"
# Change input
INPUTSOURCE=$(pacmd list-sources 2>&1 | egrep 'index:|device\.description' | \
egrep -B1 "($WEBCAMMIC|$HEADSETMIC)" | \
grep ' index:' | \
awk '{print $NF}' | \
sed "s/'//")
pacmd set-default-source $INPUTSOURCE
# Change output
OUTPUTSINK=$(pacmd list-sinks 2>&1 | egrep 'index:|device\.description' | \
egrep -B1 "($LINEOUT|$HEADSET)" | \
grep ' index:' | \
awk '{print $NF}' | \
sed "s/'//")
pacmd set-default-sink $OUTPUTSINK
pacmd list-sink-inputs | grep index: | awk '{print $NF}' | while read INPUT; do
pacmd move-sink-input $INPUT $OUTPUTSINK
done
In the script I’ve predefined two input sources and two output sinks (that’s the PulseAudio nomenclature) I’m toggling between. For video conferencing I switch input and output to my headset, and when the meeting is over I switch back to listening to music through my docking station’s line out connected to a speaker/subwoofer setup.
The script works by grepping through the results from various uses of the pacmd
command, a PulseAudio command line tool. The index of an active input source or output sink is prefixed with an asterisk, so the active component will show up as something like * index: 3
while the other will show up as for instance index: 7
(there are two leading spaces before “index”). For both the input and output, the script identifies the index of the two allowed components and then activates the inactive one.
Now that I had a command line script that toggles my headset in and out for video conferencing, I mapped it to the keyboard shortcut ctrl+F1
. At this point, I no longer had to use the mouse to change the sound preferences. But wait, there’s more!
To make the toggling even easier (or lazier), I acquired a USB triple foot pedal from eBay. In Linux, such foot pedals identify as programmable USB keyboards. Subsequently I programmed one of the pedals to send the key combination ctrl+F1
, which again triggered the audio toggling script.
And the remaining two pedals, you may ask? I mapped the second pedal to mute the microphone, and when pressing the third my Squeezebox player skips to the next song 🙂