Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make an alarm system backed by a Ubuntu (no graphical interface) box, which plays various announcement and alarm audio tracks (.mp3 or .wav) via the command line.

For example:

$ root> audioplay ./hello.wav

The audio should come from the PC audio jack. I might also wrap it with another socket listener. (e.g. Ruby Sinatra)

Any ideas how I can do this?

share|improve this question

migrated from stackoverflow.com Apr 28 '11 at 16:55

This question came from our site for professional and enthusiast programmers.

3  
So what is your question? – Quentin Apr 27 '11 at 13:01
1  
Just in case you're looking for example files: /usr/share/sounds is a good place to look for them. – Martin Thoma Sep 16 '14 at 11:37
up vote 32 down vote accepted

mpg123 is a command-line utility which plays mp3 files. You can install it in Ubuntu with:

sudo apt-get install mpg123
share|improve this answer

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.

share|improve this answer
    
it also supports ogg files (and probably others). – lepe Jun 3 '15 at 6:12

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)

(In Fedora it is part of the alsa-utils, and in Ubuntu the package likely has the same name.)

This does not require any additional packages like sox or mplayer or vlc, just ALSA.

share|improve this answer
5  
Thanks for the tip! I added this alias to my shell config: alias beep="aplay --quiet /usr/share/sounds/pop.wav" . That way I can get a notification when long running commands finish. For example: compile && run && beep – Jesse Hallett Dec 6 '12 at 1:35
1  
Yes, Jesse! I do exactly the same with compiling (long file conversions, etc). I use sounds from here: "Opilki sounds" (they are under the Creatve Commons license) forgive me this minor advertisement, i'm not related to the project in any way :) – Maxim Dec 7 '12 at 7:39
    
Dead easy and already installed everywhere. +1 – Pitto Jul 26 '13 at 9:08
    
Remember that you can't play an MP3 with aplay. You'll just get static. – starbeamrainbowlabs 2 days ago

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 
share|improve this answer
1  
cvlc too slow to boot up? and need to run by a non-root user? – c2h2 May 9 '11 at 3:24
    
cvlc --play-and-exit done.mp3 if you don't want to ctrl-c it. – Michael Cole Nov 5 '15 at 20:23

You can simply pipe your sound data to the pc speaker device:

cat rawsound | /dev/pcsp
share|improve this answer
    
I very much doubt that is going to work with MP3 files. – user89061 Jul 9 '11 at 12:11
1  
It won't work with mp3 encoded sound of course, but it will work with raw wav data – troelskn Jul 18 '11 at 8:05
2  
I don't have the /dev/pcsp device. What else can I try? – trusktr Aug 31 '13 at 5:21
    
I get "cat: rawsound: Datei oder Verzeichnis nicht gefunden" – Timo Apr 8 '15 at 7:04

mplayer is another player which can play pretty much any audio/video format from command line. to install it in ubuntu just execute this command:

sudo apt-get install mplayer

you can then play the file using this syntax:

mplayer [path to file]

good luck!

share|improve this answer

You must log in to answer this question.

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