100

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
  • 71,754
user51760
  • 1,101

12 Answers12

85

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,065
  • 5
  • 49
  • 65
user1933565
  • 1,064
  • 8
  • 4
74

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

psusi
  • 37,551
  • 1
    Perfect, works great with sudo pip install gTTS (Google Text to Speech/https://github.com/pndurette/gTTS) then gtts-cli "The good of mankind far outweighs the bad" | mpg123 -. – Elijah Lynn Apr 06 '17 at 17:06
  • 1
    mpg321 is a good option. – Henry Feb 06 '19 at 07:08
18

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

mlevin
  • 341
15

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
  • 145
  • 5
Ravan
  • 9,379
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
  • 15,657
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
  • 293,335
5

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.

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
  • 4,849
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
  • 788
  • 1
  • 9
  • 21
  • Great option, when it works. I get it to work on my main machine, but not on the machine with the music collection from which I want it to work :| ... aplay plays wav files fine, but mocp claims it cannot open the ALSA device ... neither can cmus. Very frustrating. – 0xC0000022L Jan 20 '24 at 21:22
2

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

jarno
  • 5,600
1

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
  • 180
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.

user178267
  • 11
  • 2