Play MP3 or WAV file via the Linux command line
mpg123 is a command-line utility which plays mp3 files. You can install it in Ubuntu with:
sudo apt-get install mpg123
The play
command from the sox
package will play any file format supported by sox
using the default audio device, e.g
$ play something.mp3
$ play something.wav
You may need to install extra packages to gain support for all formats, for example on Ubuntu 11.04 the MP3 support is not available until you install libsox-fmt-mp3
.
The most standard way to play a WAV file in Linux is using the aplay
command, which is part of the ALSA
system.
aplay [flags] [filename [filename]] ...
aplay a.wav
Links: (Wikipedia) (aplay man page)
(Both in Fedora and in Ubuntu/Mint it is part of the alsa-utils
package)
This does not require any additional packages to your Linux installation like sox or mplayer or vlc, just the basic ALSA which is a part of any system nowadays.
Install vlc
by using:
sudo apt-get install vlc vlc-plugin-pulse mozilla-plugin-vlc
Make sure that you have all repositories open. Also run the following before you install:
sudo apt-get update
VLC has a command-line operation method invoked by cvlc
. The next part would be to write a .sh
that will call the command. I am no good at writing bash scripts. The end-result would be something like:
cvlc xyz.mp3
cvlc --play-and-exit done.mp3
You can simply pipe your sound data to the pc speaker device:
cat rawsound | /dev/pcsp