Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

6 Answers

up vote 15 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
add comment

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. –  OrbWeaver 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
1  
I don't have the /dev/pcsp device. What else can I try? –  trusktr Aug 31 '13 at 5:21
add comment

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
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
add comment

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
add comment

The most standard way to play a WAV file in Linux is using the aplay command, which is part of the ALSA system.

$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
1  
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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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