How to Play MP3 Files from Debian 10 Command Line

If you are like me who likes to perform all tasks on Debian through the command line, you would also be on a lookout for how to play audio, especially mp3, through it. In this article, we will explain how you can install and use the famous Sox command-line utility in order to listen to mp3s in your Terminal.

Why the Command Line?

If you are a Terminal-savvy person, you wouldn’t want to leave the comfort of the command line and go somewhere else to do any of your daily technical activities. There is always a way to do almost all of our stuff right inside the Terminal. So, why should listening to music be any different! Using the Terminal makes certain tasks more efficient, and even faster. The command-line tools do not use too many resources and thus form great alternatives to the widely used graphical applications, especially if you are stuck up with older hardware.

We have run the commands and procedures mentioned in this article on a Debian 10 Buster system.

Install the Sox Command Line Utility

Sox is easily available through the Official Debian repository and can be installed through the command line using the apt-get command.

Open your Terminal application through the system Application Launcher Search as follows:

Debian Terminal

The Application Launcher can be accessed through the Super/Windows key.

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

$ sudo apt-get update

Update 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 Debian.

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

$ sudo apt-get install sox

Install sox player

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 be installed on your system. The process may, however, take some time depending on your Internet speed.

Please note that the above installation suggests you to install the libsox-fmt-all manually after installing Sox. We have highlighted this suggestion in the previous screenshot. This library package lets you play all song formats on Sox. Please use the following command as sudo in order to install this package:

$ sudo apt-get install libsox-fmt-all

Install additional library for sox

Enter Y when prompted with a y/n option and the package will be installed and configured with Sox.

You can check the version number of the application, and also verify that it is indeed installed on your system, through the following command:

$ sox --version

Check SoX version

Playing mp3 files through SoX

Playing mp3 files through Sox is pretty simple. In order to play a single mp3, use the following command syntax:

$ play ~/path/to/file/filename.mp3

For example, in order to play the file SampleAudio_1.mp3 from my Music folder, I would run the following command:

$ play ~/Music/SampleAudio_1.mp3

Play MP3 File with SoX Player

You can quit the player while the song is playing by using the Ctrl+A shortcut. You can also play songs located in a specific folder by using the cd command to switch to that folder and then use the play command as follows:

$ play filename.mp3

Sox also lets you play all mp3 files located in a single folder, one by one, through the following command syntax:

$ play ~/path/to/files/*.mp3

For example, the following command plays all mp3s in your Music folder:

$ play ~/Music/*.mp3

Play music list

You can use the Ctrl+C shortcut to switch to the next track. In order to exit the player, use Ctrl+CC.

Remove Sox

If you want to remove this command line music player from your system, run the following commands as sudo in your Terminal.

$ sudo apt-get remove sox
$ sudo apt-get remove libsox-fmt-all

This was all about the basic usage of Sox. You can use the help command to learn all else that you can do with Sox!