In this tutorial, we’ll present three command line methods to change the default audio device in Linux: pactl, ALSA, and amixer.
2. Using pactl
The pactl command in Linux is used for managing audio playback, controlling audio devices, and handling the PulseAudio sound server. It can adjust the volume, set default audio devices, and configure properties. Additionally, it provides powerful command line control over various aspects of audio management.
In order to see a list of the available audio devices connected with the system, we can use the pactl command:
$ pactl list sinks short
We can identify the desired audio device from the list of connected audio devices. To change the default audio device, we first need to know the name or index of the desired audio device found in the list. Now let’s change the default audio device:
$ pactl set-default-sink <sink_name>
Here, we need to replace <sink_name> with the name or index of the desired audio device.
3. Using ALSA
Advanced Linux Sound Architecture (ALSA) provides a software framework and drivers for sound card support. It offers an interface between audio applications and sound hardware. Furthermore, it provides a standardized and reliable way to handle sound devices, ensuring compatibility across various hardware configurations.
In order to see the sound cards and devices connected to the system, we can use the aplay command, which is part of ALSA:
$ aplay -l
Now, we need to identify the desired sound card and audio device. We can move to the next phase as soon as we identify the card and device number from the list.
In order to change the default audio device, first, we must edit the /etc/asound.conf file using the sudo command:
$ sudo nano /etc/asound.conf
The configuration file provides a way to define default settings and configurations for audio devices. As soon as we open the file, we need to fill in the card and device number of the desired audio device:
defaults.pcm.card <card_number> defaults.pcm.device <device_number>
Here, we must replace <card_number> and <device_number> with the numbers of the desired audio device. Finally, we save the file and exit the terminal.
4. Using amixer
The amixer command in Linux is primarily used to control and adjust audio settings from the command line. It allows users to manipulate volume levels and change various audio parameters. Moreover, we can view as well as modify the settings of sound cards and devices. Hence, it provides a convenient way to manage audio controls, configure mixer settings, and customize the audio output.
First, let’s use the amixer command to see the available sound cards and controls:
$ amixer controls
Now from the list of devices, we need to identify the card and control number of the device we want to set as the default audio device. Finally, using the amixer command, we can change the default audio device and select a new one:
$ amixer -c <card_number> cset numid=<control_number> 1
We must replace <card_number> with the number of the desired sound card and <control_number> with the number of the control we identified.
In this article, we presented three command line methods to change the default audio device in Linux: pactl, ALSA, and amixer.