66

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?

  • You want to play it from the 'server' speakers or you want to play it across the network? Two very different things. – RobotHumans Mar 23 '12 at 12:17
  • Audio through jack output, not over network (initially). – user51760 Mar 23 '12 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 '13 at 22:12

11 Answers 11

56

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

  • 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 -. – Elijah Lynn Apr 6 '17 at 17:06
  • mpg321 is a good option. – Henry Feb 6 '19 at 7:08
42

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

ffplay example.mp3
  • 3
    While it does play, it also opens up a GUI window. – Elijah Lynn Apr 6 '17 at 17:01
  • 4
    -nodisp option makes it not open a GUI window. – weronika Sep 18 '17 at 12:46
  • 1
    it seems to keep running after it finishes playing the audio. – Akiva Sep 30 '17 at 15:29
  • 1
    On my system at least ffplay -loop 9999 sound.wav also seamlessly loops the audio. – Michael Sep 8 '18 at 17:45
  • 11
    This is the one I use ffplay -nodisp -autoexit sound.ogg >/dev/null 2>&1 – Paradiesstaub Jan 7 '19 at 15:20
13

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

  • mplayer --vo=null musicClip.mp4 disables the video if you want just the music. – loxaxs Jan 1 '18 at 22:42
10

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
sudo apt-get install sox libsox-fmt-all

To use play command:

play file_name.extension

Use man sox for more information

reference here

8

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.

6

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.

  • Excellent, thanks for the speaker-test.... worked great. I'll also check out mpc. – user51760 Mar 23 '12 at 15:15
2

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

  • actually it should be -Hq, not -hq... but yes. And omg why is this not the accepted answer?? – Dale Anderson Jun 1 '18 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 .
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.

0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.