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?

link|improve this question

57% accept rate
3  
So what is your question? – David Dorward Apr 27 '11 at 13:01
feedback

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

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

4 Answers

up vote 1 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
link|improve this answer
feedback

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
link|improve this answer
cvlc too slow to boot up? and need to run by a non-root user? – c2h2 May 9 '11 at 3:24
feedback

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

cat rawsound | /dev/pcsp
link|improve this answer
I very much doubt that is going to work with MP3 files. – OrbWeaver Jul 9 '11 at 12:11
It won't work with mp3 encoded sound of course, but it will work with raw wav data – user10508 Jul 18 '11 at 8:05
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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