How to Keep the Default Audio Devices from Changing on Ubuntu
June 23, 2020It's the year 2020 - in the top ten of our major tech challenges, we still have Linux and its audio settings.
The real reason why there’s no sound in space. pic.twitter.com/iGdpURWEj2
— That Dragon Guy (@PaintYourDragon) June 4, 2020
The Problem
More specifically, it seems to be impossible to correctly remember the settings for audio input and output devices across reboots.
This screenshot shows my desired configuration. From a couple of possible input and output devices, this is want I want to use. However, after each reboot those settings are changing and resetting - apparently at random.
A Solution
Disclaimer: I'm running Ubuntu 20.04 and the following steps work for me. As usual, your mileage may vary.
This is the Ubuntu version I am currently using and where the following steps worked.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
First, let's get a list of the available audio output devices (sinks) using the
pactl
command:
$ pactl list short sinks
1 alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1 module-alsa-card.c s16le 2ch 44100Hz IDLE
2 alsa_output.usb-FongLun_AmazonBasics_USB_Conference_Mic_201802-00.analog-stereo module-alsa-card.c s16le 2ch 44100Hz IDLE
3 alsa_output.pci-0000_02_00.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
4 alsa_output.pci-0000_00_1f.3.analog-stereo module-alsa-card.c s16le 2ch 44100Hz IDLE
Then do the same for the input devices (sources):
$ pactl list short sources
1 alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1.monitor module-alsa-card.c s16le 2ch 44100Hz IDLE
2 alsa_input.usb-Microsoft_Microsoft___LifeCam_HD-5000-02.mono-fallback module-alsa-card.c s16le 1ch 44100Hz IDLE
3 alsa_output.usb-FongLun_AmazonBasics_USB_Conference_Mic_201802-00.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz IDLE
4 alsa_input.usb-FongLun_AmazonBasics_USB_Conference_Mic_201802-00.analog-stereo module-alsa-card.c s16le 2ch 44100Hz IDLE
5 alsa_output.pci-0000_02_00.0.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz IDLE
6 alsa_output.pci-0000_00_1f.3.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz IDLE
Now, using the set-default-sink
and set-default-source
options of the pactl
command, we can set the default input and output devices. This can either be done
using the number or the device name (I recommend working with device names
however, since those numbers seem to be changing across reboots).
Example:
$ pactl set-default-source alsa_output.pci-0000_00_1f.3.analog-stereo
$ pactl set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo
When trying out this commands with different sources and sinks, the result should be immediately reflected in the Audio Settings dialog.
Making the Solution Permanent
Note that these settings are volatile and won't survive a reboot of your PC. To
make those settings persistent (well, kind of), I simply added those pactl set-default...
instructions to my ~/.bashrc
file - problem solved.
Open the .bashrc
file using nano
(or another editor of your choice).
$ cd ~
$ nano ./.bashrc
Add those instructions at the end of the file and save it.
...
pactl set-default-source alsa_output.pci-0000_00_1f.3.analog-stereo
pactl set-default-sink alsa_output.pci-0000_00_1f.3.analog-stereo