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?

3
  • You want to play it from the 'server' speakers or you want to play it across the network? Two very different things. Mar 23, 2012 at 12:17
  • Audio through jack output, not over network (initially).
    – user51760
    Mar 23, 2012 at 15:20
  • 1
    You could try installing sox, then at the commandline it would be "play thisorthat.mp3" or "play ~/music/thisfolder/thisorthat.mp3"
    – deleted
    Jul 3, 2013 at 22:12

12 Answers 12

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 -
6
  • 7
    While it does play, it also opens up a GUI window. Apr 6, 2017 at 17:01
  • 15
    -nodisp option makes it not open a GUI window.
    – weronika
    Sep 18, 2017 at 12:46
  • 3
    it seems to keep running after it finishes playing the audio.
    – Anon
    Sep 30, 2017 at 15:29
  • 2
    On my system at least ffplay -loop 9999 sound.wav also seamlessly loops the audio.
    – Michael
    Sep 8, 2018 at 17:45
  • 27
    This is the one I use ffplay -nodisp -autoexit sound.ogg >/dev/null 2>&1 Jan 7, 2019 at 15:20
74

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

2
  • 1
    Perfect, works great with sudo pip install gTTS (Google Text to Speech/github.com/pndurette/gTTS) then gtts-cli "The good of mankind far outweighs the bad" | mpg123 -. Apr 6, 2017 at 17:06
  • 1
    mpg321 is a good option.
    – Henry
    Feb 6, 2019 at 7:08
18

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

1
  • 2
    mplayer --vo=null musicClip.mp4 disables the video if you want just the music.
    – loxaxs
    Jan 1, 2018 at 22:42
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

0
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.

0
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.

1
  • Excellent, thanks for the speaker-test.... worked great. I'll also check out mpc.
    – user51760
    Mar 23, 2012 at 15:15
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

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

1
  • actually it should be -Hq, not -hq... but yes. And omg why is this not the accepted answer?? Jun 1, 2018 at 16:55
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 .
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)

1
  • 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. Jan 20 at 21:22
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.

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .