# Rakefile sound effects

**URL:** <https://rubytalk.org/t/rakefile-sound-effects/32645>\
**Category:** ruby-talk\
**Created:** [4 November 2006 23:00 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645 "2006-11-04T23:00:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [4 November 2006 23:00 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/1 "2006-11-04T23:00:17Z")

</div>

Ruboids:

Suppose I wanted to play a WAV file each time any Rakefile tasks all  
succeed, and play another one each time any task fails.

How could one add such a feature, portably between Linux and WinXP?

The two sub-questions are therefore:

- what's Ruby's dirt-simple but portable sound library?

- how to hook into the Rakefile task stack  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to intercept its results?

Long term, I will select choice samples from "Holy Grail", such as "Ni!" and  
"Bad Zoot!" But that's the easy part...

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://www.greencheese.us/ZeekLand](http://www.greencheese.us/ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [4 November 2006 23:39 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/2 "2006-11-04T23:39:12Z")

</div>

I suppose you can check the result code/errorlevel that rake returns,  
but I haven't verified this.

> **···**
>
> On 11/5/06, Phlip \<phlipcpp@yahoo.com\> wrote:
> 
> > Ruboids:
> > 
> > Suppose I wanted to play a WAV file each time any Rakefile tasks all  
> > succeed, and play another one each time any task fails.
> > 
> > How could one add such a feature, portably between Linux and WinXP?
> > 
> > The two sub-questions are therefore:
> > 
> > - what's Ruby's dirt-simple but portable sound library?
> > 
> > - how to hook into the Rakefile task stack  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to intercept its results?
> > 
> > Long term, I will select choice samples from "Holy Grail", such as "Ni!" and  
> > "Bad Zoot!" But that's the easy part...
> > 
> > --  
> > &nbsp;&nbsp;Phlip  
> > &nbsp;&nbsp;[http://www.greencheese.us/ZeekLand](http://www.greencheese.us/ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [5 November 2006 01:03 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/3 "2006-11-05T01:03:20Z")

</div>

Phlip wrote:

> - what's Ruby's dirt-simple but portable sound library?

For dirt-simple, bundle mplayer and shellout to it. Not exactly a  
library, but probably simpler than anything more direct by far, and the  
purpose you mention wouldn't be worth more than the fastest hack I can  
come up with anyway. Depends on how many computers you need this to run on.

David Vallner

---

<div class="post-metadata">

**Author:** ![Harold\_Hausman](https://avatars.discourse-cdn.com/v4/letter/h/ac91a4/32.png) [@Harold\_Hausman](https://rubytalk.org/u/Harold_Hausman)\
**Post date:** [5 November 2006 08:53 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/4 "2006-11-05T08:53:45Z")

</div>

> Ruboids:
> 
> Suppose I wanted to play a WAV file each time any Rakefile tasks all  
> succeed, and play another one each time any task fails.

... snip

> - what's Ruby's dirt-simple but portable sound library?

For windows it definitely doesn't get any easier than win-32 sound:  
[http://raa.ruby-lang.org/project/win32-sound/](http://raa.ruby-lang.org/project/win32-sound/)

idk about Linux unfortunately,  
-Harold

> **···**
>
> On 11/5/06, Phlip \<phlipcpp@yahoo.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Phlip5](https://avatars.discourse-cdn.com/v4/letter/p/e99b99/32.png) [@Phlip5](https://rubytalk.org/u/Phlip5)\
**Post date:** [5 November 2006 17:30 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/5 "2006-11-05T17:30:16Z")

</div>

> Ruboids:

I need to light a fire under this thread.

Firstly, the current solution is outside the Rakefile. That's easy; you just  
collect the shell's return value.

I want a solution inside the Rakefile. And I want Someone Else, preferrably  
a Ruby library, to take care of the 'if' statement that detects the  
platform.

The current solution looks like this:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;got = system(command) # \<-- shells to rake

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sound = if got  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'drumloop.wav'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'jaguar.wav'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;weWin32 = RUBY\_PLATFORM.include?('mswin32')

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if weWin32  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system('"C:\\Program Files\\Windows Media Player\\mplayer2.exe"  
/play /close s:\\bin\\' + sound)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system('aplay ~/bin/' + sound)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

That sucks bigtime, for many various reasons. Windows is too awesome and  
sophisticated to provide a true command-line solution; we are calling  
'system', etc.

Now here's the fire to light under this thread - the reason I want a  
solution inside the Rakefile, and portable:

&nbsp;&nbsp;--\> Ant does this out of the box \<--

Does everyone understand the mandate \_now\_?? 😉

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://www.greencheese.us/ZeekLand](http://www.greencheese.us/ZeekLand) \<-- NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![Jonas\_Hartmann](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jonas\_Hartmann](https://rubytalk.org/u/Jonas_Hartmann)\
**Post date:** [5 November 2006 20:36 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/6 "2006-11-05T20:36:58Z")

</div>

Phlip wrote:

> Ruboids:
> 
> Suppose I wanted to play a WAV file each time any Rakefile tasks all succeed, and play another one each time any task fails.
> 
> How could one add such a feature, portably between Linux and WinXP?
> 
> The two sub-questions are therefore:
> 
> - what's Ruby's dirt-simple but portable sound library?
> 
> - how to hook into the Rakefile task stack  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to intercept its results?
> 
> Long term, I will select choice samples from "Holy Grail", such as "Ni!" and "Bad Zoot!" But that's the easy part...

maybe with bundled (parts of) sdl - but then you would need to offer dlls/sos for multiple platforms.

what about pc-speaker? any interface to that existing in ruby?

---

<div class="post-metadata">

**Author:** ![Guillaume\_Benny](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@Guillaume\_Benny](https://rubytalk.org/u/Guillaume_Benny)\
**Post date:** [5 November 2006 00:34 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/7 "2006-11-05T00:34:21Z")

</div>

Hi,

Jan Svitok wrote:

> **···**
>
> > On 11/5/06, Phlip \<phlipcpp@yahoo.com\> wrote:
> > 
> > > Ruboids:
> > > 
> > > Suppose I wanted to play a WAV file each time any Rakefile tasks all  
> > > succeed, and play another one each time any task fails.
> > > 
> > > How could one add such a feature, portably between Linux and WinXP?
> > 
> > I suppose you can check the result code/errorlevel that rake returns,  
> > but I haven't verified this.
> 
> Simple and portable:
> 
> rake && echo FINE || echo BAD
> 
> Replace echo with your command of choice... Although the command might not  
> be portable...
> 
> Guillaume

---

<div class="post-metadata">

**Author:** ![vasudevram](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@vasudevram](https://rubytalk.org/u/vasudevram)\
**Post date:** [5 November 2006 14:45 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/8 "2006-11-05T14:45:18Z")

</div>

Harold Hausman wrote:

> \> Ruboids:  
> \>  
> \> Suppose I wanted to play a WAV file each time any Rakefile tasks all  
> \> succeed, and play another one each time any task fails.  
> \>
> 
> .. snip
> 
> \>  
> \> - what's Ruby's dirt-simple but portable sound library?  
> \>
> 
> For windows it definitely doesn't get any easier than win-32 sound:  
> [http://raa.ruby-lang.org/project/win32-sound/](http://raa.ruby-lang.org/project/win32-sound/)
> 
> idk about Linux unfortunately,  
> -Harold

Hi,

For Linux, here are a couple of suggestions:

1. try 'cat'ing the WAV file to the sound device - maybe something like  
/dev/audio.  
2. Write the file's contents to the device.

Do either of the above, from your Ruby code, is what I mean.

I don't know or remember right now how to do the first - 'cat' a file,  
i.e. Linux equivalent of the DOS TYPE \<file\> command - from a Ruby  
program. In Python it would be :

import os  
os.system("your\_command\_with\_optional\_arguments\_here")

This does the equivalent of the Linux library function called system -  
a C code fragment showing how to use it:

char \*cmd = "cat filename.WAV";  
int rc;  
rc = system(cmd);  
if (rc == -1)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;/\* print error message \*/  
}

A thought: it's not always necessary or worth it to try and make the  
code portable across OS's - though a good idea in theory, sometimes the  
effort may not be worth it. If you have a quick and easy way to do it  
non-portably (i.e. using different pieces of code for Windows and  
Linux), nothing wrong with using that approach. Just IMO, of course -  
its your call, ultimately. Or, another way could be to write your own  
thin wrapper method, with nothing OS-specific in its name or arguments,  
and within that, detect the OS and call the appropriate OS-specific  
code with in the two branches of an if-else statement, like:

def play\_wav\_file  
&nbsp;&nbsp;&nbsp;&nbsp;if (Windows)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Windows-specific code here  
&nbsp;&nbsp;&nbsp;&nbsp;else # assuming no other OS except Linux  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Linux-specific code here  
&nbsp;&nbsp;&nbsp;&nbsp;end  
end

Replace the (Windows) in the if statement with some appropriate code to  
detect the OS your Ruby program is running on. Again, don't know or  
remember how to do that in Ruby right now, there surely will be some  
simple way.

HTH  
Vasudev

> **···**
>
> > On 11/5/06, Phlip \<phlipcpp@yahoo.com\> wrote:
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
> Vasudev Ram  
> Dancing Bison Enterprises  
> Software consulting and training
> 
> > **[dancingbison.com](http://ww38.dancingbison.com/)**
> >
> > Learn Python Programming
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---

<div class="post-metadata">

**Author:** ![Devin\_Mullins](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Devin\_Mullins](https://rubytalk.org/u/Devin_Mullins)\
**Post date:** [5 November 2006 18:24 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/9 "2006-11-05T18:24:43Z")

</div>

Phlip wrote:

> &nbsp;&nbsp;--\> Ant does this out of the box \<--  
> Does everyone understand the mandate \_now\_?? 😉

Er... no, but I'll try & help anyhoo.

10 seconds searching on RAA got me this:  
[http://raa.ruby-lang.org/project/ruby-audiere/](http://raa.ruby-lang.org/project/ruby-audiere/)

SourceForge seems to be down, so I couldn't find out much about audiere, but google says "For audio output, Audiere supports DirectSound or WinMM in Windows, OSS on Linux and..."

So... yeah.

Devin

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [5 November 2006 20:32 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/10 "2006-11-05T20:32:13Z")

</div>

Phlip wrote:

> I want a solution inside the Rakefile. And I want Someone Else, preferrably  
> a Ruby library, to take care of the 'if' statement that detects the  
> platform.

Unfortunately, rake doesn't seem to let you check for failure of  
dependent tasks - if a task fails, all goes pear-shaped and the process  
exits, that's it. Short of a change to Rake to use for example a  
TaskFailedError that Task#execute / Task#invoke would throw (HINT) you  
could catch and rethrow, that just isn't doable.

See below why platform sniffing isn't quite necessary if you're willing  
to depend on a cross-platform media player.

> The current solution looks like this:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;got = system(command) # \<-- shells to rake
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sound = if got  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'drumloop.wav'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'jaguar.wav'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;weWin32 = RUBY\_PLATFORM.include?('mswin32')
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if weWin32  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system('"C:\\Program Files\\Windows Media Player\\mplayer2.exe"  
> /play /close s:\\bin\\' + sound)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system('aplay ~/bin/' + sound)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> That sucks bigtime, for many various reasons. Windows is too awesome and  
> sophisticated to provide a true command-line solution; we are calling  
> 'system', etc.

Windows, in its awesomeness and sophistication, has a unified way of  
opening documents with their default handlers from the command line.

system('start s:\\bin\\#{sound}') would've worked.

Provided mplayer.exe (or any other cross-platform media player program)  
is on PATH:

If you registered mplayer as the default handler for .wav files ("ftype  
soundrec=mplayer %1"), this would work without opening an unsightly window.

Please refrain flaming at the Windows command line when it's in fact  
your ignorance of how it actually works showing. It's sad to look at and  
all. I'm not saying there isn't anything to flame about either Windows  
or its command line, but this isn't it - both Windows and Linux will  
launch a program on PATH, the only difference is that with the Linux  
directory structure, usually all software on your computer will be in  
PATH already by convention.

Of course, if mplayer.exe is on PATH on your Windows box, and also on  
your Linux box, provided you can find the .wav file you want to play  
using a pathname relative to some parameter accessible at runtime (the  
script location), you don't need any OS sniffing whatsoever. As of  
Windows XP, system() will happily accept any combination of forward or  
backward slashes in the filename whatsoever. Which means the script will  
work cross-platform. As for the system() call, I'm afraid there's very  
little you can do. To my best knowledge, there just is no in-process  
audio framework with a Ruby binding that comes with anything close to an  
installation method requiring less effort than getting the sound to play  
is worth.

> Now here's the fire to light under this thread - the reason I want a  
> solution inside the Rakefile, and portable:
> 
> &nbsp;&nbsp;--\> Ant does this out of the box \<--

java.sound being around since 2001, I'm somehow not surprised. The Ruby  
standard library having... well... no multimedia support whatsoever, I'm  
not surprised Rake doesn't.

David Vallner

---

<div class="post-metadata">

**Author:** ![Bill\_Kelly](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@Bill\_Kelly](https://rubytalk.org/u/Bill_Kelly)\
**Post date:** [5 November 2006 20:55 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/11 "2006-11-05T20:55:45Z")

</div>

> > Ruboids:
> 
> I want a solution inside the Rakefile. And I want Someone Else, preferrably a Ruby library, to take care of the 'if' statement that detects the platform.
> 
> The current solution looks like this:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;got = system(command) # \<-- shells to rake
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sound = if got  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'drumloop.wav'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'jaguar.wav'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;weWin32 = RUBY\_PLATFORM.include?('mswin32')
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if weWin32  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system('"C:\\Program Files\\Windows Media Player\\mplayer2.exe" /play /close s:\\bin\\' + sound)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system('aplay ~/bin/' + sound)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

Could play win32 sounds like this, assuming .wav files:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/55423](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/55423)

(Assuming you didn't want to have a dependency on win32-sound  
library.)

Regards,

Bill

> **···**
>
> From: "Phlip" \<phlipcpp@yahoo.com\>

---

<div class="post-metadata">

**Author:** ![David\_Vallner](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@David\_Vallner](https://rubytalk.org/u/David_Vallner)\
**Post date:** [5 November 2006 16:29 UTC](https://rubytalk.org/t/rakefile-sound-effects/32645/12 "2006-11-05T16:29:39Z")

</div>

vasudevram wrote:

> Harold Hausman wrote:
> 
> > > Ruboids:
> > > 
> > > Suppose I wanted to play a WAV file each time any Rakefile tasks all  
> > > succeed, and play another one each time any task fails.
> > 
> > .. snip
> > 
> > > - what's Ruby's dirt-simple but portable sound library?
> > 
> > For windows it definitely doesn't get any easier than win-32 sound:  
> > [http://raa.ruby-lang.org/project/win32-sound/](http://raa.ruby-lang.org/project/win32-sound/)
> > 
> > idk about Linux unfortunately,  
> > -Harold
> 
> Hi,
> 
> For Linux, here are a couple of suggestions:
> 
> 1. try 'cat'ing the WAV file to the sound device - maybe something like  
> /dev/audio.  
> 2. Write the file's contents to the device.
> 
> Do either of the above, from your Ruby code, is what I mean.

Except they won't work. /dev/dsp and /dev/audio take only very specific  
file formats, neither of which is .WAW.

I'm afraid multimedia handling is a nontrivial problem on any OS and  
generally a mess. Windows has builtin support for .WAW, Linux for raw  
PCM at 8kHz/8bit/mono (for dsp). Which means you're probably still  
dependent on some outside tool to transform your sound file into the  
desired format. And you might as well use mplayer (my criterium for  
choosing that one is that it's console-based, comes with a Win32 build,  
and is easy to bundle with an app, and Just Works)

> A thought: it's not always necessary or worth it to try and make the  
> code portable across OS's - though a good idea in theory, sometimes the  
> effort may not be worth it. If you have a quick and easy way to do it  
> non-portably (i.e. using different pieces of code for Windows and  
> Linux), nothing wrong with using that approach.

Except that you have to do OS sniffing, sniffing for presence of support  
you require (windows native .wav handling, DirectSound, OSS, ALSA), and  
heavens forbid you want to support multiple source file formats.  
Generally the problem is that per se, the OS portability is the least of  
your concerns, it's getting a framework that will handle the sound  
format / output method issueswith minimal fuss. (To wit: if you're using  
a freeware / open-source video manipulation software, odds are it's a  
frontend to ffmpeg) If that framework is nonportable, you have to go on  
and code against two. But in this specific case, since you pretty much  
have to go on and get a preexisting sound playback solution anyway, you  
might as well find one that won't double your coding effort (even if  
it's hopefully a minimal one.) The issue here isn't expending effort to  
create a cross-platform solution, it's saving it by reusing a  
cross-platform solution.

David Vallner

> **···**
>
> > > On 11/5/06, Phlip \<phlipcpp@yahoo.com\> wrote:
