Randomice has asked for the wisdom of the Perl Monks concerning the following question:

The object was simple (or so I thought).

Make either of my two laptops emit an alert sound, a beep, based on a script running in the background. Both machines are running Ubuntu Linux (12.04, fwiw) and currently produce sound through their on-board sound cards. The beep should be noticeable (but not loud enough to annoy those who have to share working space with the machine).

At first I tried beep from the shell. After some tinkering, it appears that machine A has a dysfunctional PC speaker. (The alsamixer shows an item called "Beep" at full gain, but it gives no joy.) Machine B, on the other hand, does not have a "Beep" item in its alsamixer UI. But it will emit a system beep however -- a way too loud one, in fact. And so far I've found no way to limit its volume.

(The alsamixer settings for the two machine are different, naturally, and the one which does make a system beep seems limited. It has "Master" and "PCM" items that can be modified. It also has "S/PDIF" and "S/PDIF Default PCM" items, for whatever reason, are unmodifiable -- stuck at zero.)

So, I turned to SDL::Mixer, or wanted to. In trying to install SDL::Mixer, it installs Alien::SDL which in turn fails trying to find an out-of-date FreeType

Fetching 'http://mirror.lihnidos.org/GNU/savannah/freetype/freetype-2.3.12.tar.gz'...
Fetch failed! HTTP response: 404 Not Found 404 Not Found at inc/My/Builder.pm line 154
Fetch failed! HTTP response: 404 Not Found at inc/My/Builder.pm line 154
Command failed:  at inc/My/Builder.pm line 154
Command failed: get: Access failed: 404 Not Found (/GNU/savannah/freetype/freetype-2.3.12.tar.gz)
 at inc/My/Builder.pm line 154
Got a '404' from 'mirror.lihnidos.org' expected '200' at inc/My/Builder.pm line 154
Fetching 'http://froggs.de/libfreetype/freetype-2.3.12.tar.gz'...
'lwp' said it fetched 'download/freetype-2.3.12.tar.gz', but it was not created at inc/My/Builder.pm line 154

Anyone able to shed some light on either of these options (preferably the SDL since this is a Perl question)? Or offer another option to play a short MP3 sound or even a beep?

Replies are listed 'Best First'.
Re: Play Alert Sound in Script
by xyzzy (Pilgrim) on Mar 29, 2013 at 06:04 UTC

    from my experience, <opinion>Ubuntu is a system greatly lacking the Unix-like spirit of simplicity/elegance that Perl shares</opinion> but if I wanted a script to trigger a sound in the simplest (and potentially least portable) way, I'd probably do something "ugly" like invoke aplay through exec or system

    from my experience with many modern computers, the PC speaker/beep not as commonly supported since X is so prevalent.

    edit: if this is for a laptop, good luck getting the "pc speaker" to work the way you would expect it to on a '90s-era tower.


    $,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
    Happy, sober, smart: pick two.
Re: Play Alert Sound in Script
by Anonymous Monk on Mar 29, 2013 at 00:36 UTC

      Hmmm... still no joy.

      sudo cpanm Audio::Audiere

      Fails (on both machines). Key problem from build.log is:

      Audiere_perl.xs:3:21: fatal error: audiere.h: No such file or directory

      Never had a problem before with mods using cpanm. This is the second. When it comes to fixing missing files.h or paths for install, I'm pretty much lost.

        Audiere_perl.xs:3:21: fatal error: audiere.h: No such file or directory

        So you need to install the prerequisite library, seem obvious

Re: Play Alert Sound in Script
by RichardK (Parson) on Mar 29, 2013 at 08:16 UTC

    I don't run ubuntu so I don't know what's installed or available, but have you tried the command line beep?

    Or Audio::Beep?