Control Audio volume through the Ubuntu Command Line

A Terminal-savvy person will find a way to perform any action while staying in the comfort zone of the command line. We mostly control system volumes through the Ubuntu GUI but there are certain situations where you want to do it from the command line. ALSA or the Advanced Linux Sound Architecture provides audio support for most Linux distros. There are high chances that your Ubuntu is currently using the same architecture to run and manage audio on your system.

In this article, we will explain how you can install the ALSA utility package if it is already not installed on your Ubuntu. We will also explain how you can control the audio properties of your sound cards through:

  • Alsamixer-The graphical interface for ALSA
  • Amixer-The command-based utility for ALSA

We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system.

Install ALSA

The Alsa-utils package contains both the Alsamixer and Amixer utilities. This package is available in the official Ubuntu repositories and can easily be installed through the command line using the apt-get command.

Open your Terminal application either through the system Application Launcher Search or through the Ctrl+Alt+T shortcut.

The next step is to update your system’s repository index through the following command:

$ sudo apt-get update

Update Ubuntu Packages

This helps you in installing the latest available version of a software from the Internet. Please note that only an authorized user can add, remove and configure software on Ubuntu.

Now you are ready to install Alsa-utils; you can do so by running the following command as sudo:

$ sudo apt-get install alsa-utils

Install Alsa utils

The system might ask you the password for sudo and also provide you with a Y/n option to continue the installation. Enter Y and then hit enter; the software will then be installed on your system. The process may, however, take some time depending on your Internet speed.

Using Alsamixer-the graphical interface for Alsa

Alsamixer provides you with a graphical representation of the sound cards installed on your system and lets you easily view and control the properties of these cards. Alsamixer comes as part of the Ncurses interface so that you can stay within the Terminal while working on your sound card volume.

You can launch this graphical interface by running the following command in your Terminal:

$ alsamixer

The Alsamixer will display the properties of your default sound card as follows:

Alsa Mixer

If you are not able to see all the properties as shown in the above screen shot, either expand your Terminal window or use the left and right arrow keys to view the properties that are not visible.

The Alsamixer Views

When you open the Alsamixer interface, you see it in the Payback view. This means that you can only control options related to sound playback from this view. These are the other two views you can switch to:

Capture view

In order to view properties only related to sound capturing, you can switch to the capture view by pressing F4 while the Alsamixer is open. This is how the Capture view looks like:

Alsa mixer capture view

‘All’ view

In order to view properties related to both sound capturing and playback, you can switch to the ‘All’ view by pressing F5 while the Alsamixer is open. This is how the All view looks like:

The All view

Playback view

In order to switch back to the Playback view press the F3 button.

Sound Card Selection

The Alsamixer utility displays the properties of the card that is saved as “default”. In order to view/edit properties of another sound card installed on your system, you can use the F6 control while Alsamixer is open.

Select soundcard in Alsa Mixer

The Sound Card menu, as shown above, appears when you press F6. You can move up and down the menu and then hit Enter in order to select another card. You can also manually enter the name of a card if it does not appear in the list by selecting the “enter device name” menu option.

You can quit this menu by hitting Esc.

Controlling Sound Properties

The most important part about using Alsamixer is to be able to turn up and turn down the volume of a certain property.

  • You can move left and right to select the property whose volume you want to turn up, down, or mute.
  • When you have selected a property, use the up and down keys in order to turn the volume up and down respectively.
  • In order to mute a property/control, press the m key when that property is selected
  • For information on all that you can do through the Alsamixer, hit the F1 control. This will display the help as follows:

Controlling Sound Properties

You can use the Esc key in order to quit this help window.

Using Amixer-Control sound properties through commands

Amixer is a command based approach to managing properties of your sound cards. It provides a set of commands that you can use in order to turn the volume up, down, and even mute volume of a specified property of the specified card.

Use the following command in order to see all that you can do with Amixer:

$ amixer --help

Alsamixer help

Your amixer command looks mostly like this:

$ amixer -c [card-number] set [control] [value]

In all your amixer commands, you need to specify three things:

  • The sound card (card number) whose property you want to manage
  • The property/control whose volume you want to manage
  • The volume value in percentage, or decibels that you want to set, increase or decrease. You can also specify if you want to mute a property of a sound card.

The scontrols command lets you view the list of controls you can manage:

$ amixer scontrols

sncontrols command

Examples

1. The following command will set the volume on the Master control/property of the first sound card to 100%

$ amixer -c 0 set Master 100%

2. The following command will set the volume on the Speaker control/property of the second sound card to 30%

$ amixer -c 1 set Speaker 50%

3. The following command will set the volume on the Speaker control/property of the second sound card to 3db

$ amixer -c 1 set Speaker 3db

4. The following command will increase the volume on the Speaker control/property of the second sound card by 2db

$ amixer -c 1 set Speaker 2db+

5. Use the following commands to mute and unmute a property.

$ amixer -c 0 set Mic mute

Or,

$ amixer -c 0 set Mic unmute

This was all about installing and using the ALSA utilities so that you can control sound properties and volume right from your Ubuntu Terminal.