[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Playing Wav file in Ruby

Andy Korth

9/22/2007 2:19:00 AM

Greetings,
I'm interesting in writing a small ruby script that will play a wav
file. I'm using
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]

I haven't found anything other than what seems to be a windows only
solution:
http://rubyonwindows.blogspot.com/2007/05/adding-sound-to-your-ruby...

I've tried invoking applications that would play a sound through the
system command, but none of them have worked very well.

Here's my code thus far:

Dir.glob("*.{WAV,wav}") do |sound|
puts "Playing #{sound}, (n)ext or return to replay"
case readline.strip
when '':
system("playsound " + sound)
redo
when 'n'
next
when 'q'
exit
else
redo
end
end

Thank you very much for your time,
Andy
--
Posted via http://www.ruby-....

5 Answers

tommylil@gmail.com

9/22/2007 5:43:00 AM

0

On Sep 22, 4:18 am, Andy Korth <andy.ko...@gmail.com> wrote:
> I've tried invoking applications that would play a sound through the
> system command, but none of them have worked very well.

You do get it to play that way, right? I ran into the same situation a
few weeks ago, ending up doing the very same thing u did, calling an
external app. Simply using `playsound #{file}` will do. But if there
is any libraries making it possible to do it natively from Ruby
(without having to start writing one ourselves), I would love to hear
about it.

Tommy

Konrad Meyer

9/22/2007 6:07:00 AM

0

Quoth tommylil@gmail.com:
> On Sep 22, 4:18 am, Andy Korth <andy.ko...@gmail.com> wrote:
> > I've tried invoking applications that would play a sound through the
> > system command, but none of them have worked very well.
>
> You do get it to play that way, right? I ran into the same situation a
> few weeks ago, ending up doing the very same thing u did, calling an
> external app. Simply using `playsound #{file}` will do. But if there
> is any libraries making it possible to do it natively from Ruby
> (without having to start writing one ourselves), I would love to hear
> about it.
>
> Tommy

Any of the game libraries / SDL bindings ought to do the trick (that's as
close to native as you'll find). `playsound' isn't a program on my system,
so it wouldn't work for me. Find a command on your system (sorry I don't
know MacOSX at all) to play it, and that'll be fine for small scripts.

HTH,
--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertil...

Andy Korth

9/22/2007 6:38:00 AM

0

tommylil@gmail.com wrote:
> On Sep 22, 4:18 am, Andy Korth <andy.ko...@gmail.com> wrote:
>> I've tried invoking applications that would play a sound through the
>> system command, but none of them have worked very well.
>
> You do get it to play that way, right? I ran into the same situation a
> few weeks ago, ending up doing the very same thing u did, calling an
> external app. Simply using `playsound #{file}` will do. But if there
> is any libraries making it possible to do it natively from Ruby
> (without having to start writing one ourselves), I would love to hear
> about it.
>
> Tommy

Ah yes, sorry for lack of clarification. Playsound is part of SDL, but
it opens an application, puts it in the dock, plays the sound and exits.
It's very awkward for running inside a script. I suspect I will have to
look into SDL bindings... very overkill perhaps.

Thanks Konrad and Tommy for the quick replies.

-Andy
--
Posted via http://www.ruby-....

tommylil@gmail.com

9/22/2007 6:46:00 AM

0

On Sep 22, 8:38 am, Andy Korth <andy.ko...@gmail.com> wrote:
> tommy...@gmail.com wrote:
> > On Sep 22, 4:18 am, Andy Korth <andy.ko...@gmail.com> wrote:
> >> I've tried invoking applications that would play a sound through the
> >> system command, but none of them have worked very well.
>
> > You do get it to play that way, right? I ran into the same situation a
> > few weeks ago, ending up doing the very same thing u did, calling an
> > external app. Simply using `playsound #{file}` will do. But if there
> > is any libraries making it possible to do it natively from Ruby
> > (without having to start writing one ourselves), I would love to hear
> > about it.
>
> > Tommy
>
> Ah yes, sorry for lack of clarification. Playsound is part of SDL, but
> it opens an application, puts it in the dock, plays the sound and exits.
> It's very awkward for running inside a script. I suspect I will have to
> look into SDL bindings... very overkill perhaps.
>
> Thanks Konrad and Tommy for the quick replies.
>
> -Andy
> --
> Posted viahttp://www.ruby-....

I got a plain commandline version of playsound running on my Mac, that
won't open up any apps in the dock.. Have a look here:
http://steike.com/code/... (think this is it). And Konrad,
sorry for being fuzzy.

T

Andy Korth

9/22/2007 4:27:00 PM

0

tommylil@gmail.com wrote:
>
> I got a plain commandline version of playsound running on my Mac, that
> won't open up any apps in the dock..
>
> T

Well, that's pretty much perfect! Thanks. It's a completely different
program with the same name. It responds much faster than the SDL
playsound command.

Thanks a lot!

-Andy
--
Posted via http://www.ruby-....