If, like me, you like to do all your Ubuntu tasks from the command line, you’ll also be looking for ways to play audio files, especially mp3s, from the command line. In this article, we’ll tell you how to install and use the famous command-line program Sox to listen to mp3s in your terminal. We have run the commands and procedures mentioned in this article on an Ubuntu 20.04 LTS system.
Install the Sox Command Line Utility
Sox is easily available through the Official Ubuntu repository and can 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
This helps you in installing the latest available version of 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 Sox; you can do so by running the following command as sudo:
$ sudo apt-get install sox
The system may ask you for the password for sudo and also give you the option to continue the installation with Y/n. Type Y and then press Enter; the software will be installed on your system. However, the process may take some time depending on your internet speed.
Please note that the above installation suggests installing libsox-fmt-all manually after installing Sox. We have highlighted this suggestion in the previous screenshot. With this library package you can play all song formats on Sox. Please use the following command as sudo to install this package:
$ sudo apt-get install libsox-fmt-all
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
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
You can quit the player while the song is playing by using the Ctrl+C 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
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!