How can I play sound using ruby?

I want to build a program where I will need to play sound from a wav
file using ruby. Is this platform dependent? I will need this for
windows.

I tried the following:

ruby-sound.rb

require ‘win32/sound’
include Win32
Sound.play(‘chimes.wav’)
Sound.play(‘c:\sounds\hal9000.wav’)

but I get the following errors:

ruby ruby-sound.rb

internal:lib/rubygems/custom_require:29:in require': 126: The specified modul e could not be found. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/win32-api-1.4.6-x8 6-mingw32/lib/win32/api.so (LoadError) from <internal:lib/rubygems/custom_require>:29:inrequire’
from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/windows-api-0.4.0/lib/windows/a
pi.rb:1:in <top (required)>' from <internal:lib/rubygems/custom_require>:29:inrequire’
from internal:lib/rubygems/custom_require:29:in require' from C:/Ruby192/lib/ruby/gems/1.9.1/gems/windows-pr-1.0.9/lib/windows/so und.rb:1:in<top (required)>’
from internal:lib/rubygems/custom_require:29:in require' from <internal:lib/rubygems/custom_require>:29:inrequire’
from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/win32-sound-0.4.2/lib/win32/sou
nd.rb:1:in <top (required)>' from <internal:lib/rubygems/custom_require>:33:inrequire’
from internal:lib/rubygems/custom_require:33:in rescue in require' from <internal:lib/rubygems/custom_require>:29:inrequire’
from ruby-sound.rb:1:in `’

Ted.

Hi,

2010/10/19 Ted F. [email protected]:

Sound.play(‘chimes.wav’)
e could not be found. -
und.rb:1:in `<top (required)>’

The api.so includeded in the gem package is not a correct version.
It is not MinGW compiled version but VC++ compiled version.

You can download the correct api.so for 1.9.x installer for the time
being
at http://116.122.37.135/api.so

Copy api.so to
C:/Ruby192/lib/ruby/gems/1.9.1/gems/win32-api-1.4.6-x86-mingw32/lib/win32/

Regards,
Park H.

On 18/10/2010 23:41, Ted F. wrote:

Sound.play(‘chimes.wav’)
e could not be found. -
und.rb:1:in `<top (required)>’

Have you installed the win32-api gem?

Jim

What has suggested by Park, worked… Thank you Park.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs