If you are like me who likes to perform all tasks on Ubuntu 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. We have run the commands and procedures mentioned in this article on a Ubuntu 18.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 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
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.
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!