110

I have installed Ubuntu 11.10 server.. so command line only.

I need to be able to play audio (.mp3 & .wav) files via the command line!

I've installed the MPD & Audacious packages... and copied some files to a location specified in the .conf file.

But what do I do to acutally play the .mp3 files??

Also, how can I confirm the AUDIO is working correctly?

Jorge Castro
  • 73,717
user51760
  • 1,201

12 Answers12

97

If you already have ffmpeg installed (you should have ffmpeg installed default with ubuntu), try:

ffplay example.mp3

or (without text output, window opening and looping):

ffplay -v 0 -nodisp -autoexit example.mp3

or reading from stdin, piped from a command:

cat example.mp3 | ffplay -v 0 -nodisp -autoexit -
Volker Siegel
  • 13,295
user1933565
  • 1,176
77

For wav you can use aplay. For mp3 you can use mpg123.

psusi
  • 38,031
20

I usually just do mplayer foo.mp3 to play audio from the command line.

mlevin
  • 361
18

The play command from the sox package will play any file format supported by sox

To install sox open terminal and run:

sudo apt-get install sox libsox-fmt-all

To use play command:

play file_name.extension

Use man sox for more information

reference here

x5657
  • 185
Ravan
  • 9,567
13

Not sure if your server will support it, but VLC also has a command line version that can play (with the right packages) MP3 files:

nvlc file.mp3

The 'n' in front of 'vlc' invokes the ncurses interface which is for the command line. This allows you to play multiple files, pause and control the files being played.

And additionally you can use nvlc --random /path/to/your/music/folder to play random songs from a Music folder.

Or use cvlc instead of nvlc, for even minimal interaction.

Pablo Bianchi
  • 17,371
8

You can test the sound quite simply: speaker-test -c6 (where -c6 indicates I want to test 6 channels for a 5.1 setup)

But for playing music, mpd is just a server.

It needs a frontend to tell it to do things. Check out mpc for a fairly basic command line player. There are of course many, many clients (including graphical ones you can connect over the network) so you can play around with those.

Oli
  • 299,380
7

ffplay has -loglevel quiet, so no need to redirect output to the platform-specific /dev/null. So, building on others' answers,

ffplay -nodisp -autoexit -loglevel quiet filename.{wav,mp3,ogg,...}

Try ffplay -formats, see https://www.ffmpeg.org/ffplay.html.

3

You told you have audacious installed. You can play audio file in command line by audacious -Hq file.

jarno
  • 6,175
2

mpv is a descendant of mplayer, which mlevin mentions. Many of the old command line switches still work, but some of the keyboard shortcuts have changed.

It also has the ability to "play" folders (by queuing all media files contained within).

mpv --vo=null -shuffle .
xiota
  • 5,038
2

If someone finds this answer looking how to play audio in a script, we ended up using a Python package called playsound:

https://github.com/TaylorSMarks/playsound

Playsound is implemented in pure Python and works in almost any Linux, OSx and Windows. No external command required. At it supports MP3 and HTTPS URIs too!

How to use it?

sudo pip3 install playsound
python3 -c 'from playsound import playsound; playsound("https://your.domain/sound.mp3")'

Or, again, if scripting or coding in Python, incorporate it in your code.

Havok
  • 190
2

Just discovered this terminal dedicated music player:

Install package "moc" and launch mocp for a cool visual terminal music player (with no risk of making pop-ups of cover art, etc, like `mplayer1 does)

CPBL
  • 848
1

Using smplayer to play audio .m4a files

cd ~/Music/Songs_m4a
smplayer .

This is SMPlayer v. 0.8.6 running on Linux.

NOTE: No interface displayed. It just play all the audio files in the folder.