From: vasudevram Date: 2006-11-05T23:45:18+09:00 Subject: Re: Rakefile sound effects Harold Hausman wrote: > On 11/5/06, 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. > > > > .. 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/ > > 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 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) { /* 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 if (Windows) # Windows-specific code here else # assuming no other OS except Linux # Linux-specific code here 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vasudev Ram Dancing Bison Enterprises Software consulting and training http://www.dancingbison.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~