How can I play sound using ruby?

Discussion in 'Ruby' started by Ted Flethuseo, Oct 18, 2010.

  1. 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')

    http://rubyonwindows.blogspot.com/2007/05/adding-sound-to-your-ruby-apps.html

    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:in `require'
    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:in `require'
    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:in `require'
    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:in `require'
    from <internal:lib/rubygems/custom_require>:33:in `rescue in
    require'
    from <internal:lib/rubygems/custom_require>:29:in `require'
    from ruby-sound.rb:1:in `<main>'


    Ted.

    --
    Posted via http://www.ruby-forum.com/.
     
    Ted Flethuseo, Oct 18, 2010
    #1
    1. Advertising

  2. Ted Flethuseo

    Heesob Park Guest

    Hi,

    2010/10/19 Ted Flethuseo <>:
    > 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')
    >
    > http://rubyonwindows.blogspot.com/2007/05/adding-sound-to-your-ruby-apps.=

    html
    >
    > 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. =C2=A0 -
    > C:/Ruby192/lib/ruby/gems/1.9.1/gems/win32-api-1.4.6-x8
    > 6-mingw32/lib/win32/api.so (LoadError)
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:29=

    :in `require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from
    > C:/Ruby192/lib/ruby/gems/1.9.1/gems/windows-api-0.4.0/lib/windows/a
    > pi.rb:1:in `<top (required)>'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:29=

    :in `require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:29=

    :in `require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from
    > C:/Ruby192/lib/ruby/gems/1.9.1/gems/windows-pr-1.0.9/lib/windows/so
    > und.rb:1:in `<top (required)>'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:29=

    :in `require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:29=

    :in `require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from
    > C:/Ruby192/lib/ruby/gems/1.9.1/gems/win32-sound-0.4.2/lib/win32/sou
    > nd.rb:1:in `<top (required)>'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:33=

    :in `require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:33=

    :in `rescue in
    > require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from <internal:lib/rubygems/custom_require>:29=

    :in `require'
    > =C2=A0 =C2=A0 =C2=A0 =C2=A0from ruby-sound.rb:1:in `<main>'
    >

    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-ming=
    w32/lib/win32/


    Regards,
    Park Heesob
     
    Heesob Park, Oct 19, 2010
    #2
    1. Advertising

  3. [Note: parts of this message were removed to make it a legal post.]

    On 18/10/2010 23:41, Ted Flethuseo wrote:
    > 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')
    >
    > http://rubyonwindows.blogspot.com/2007/05/adding-sound-to-your-ruby-apps.html
    >
    > 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:in `require'
    > 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:in `require'
    > 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:in `require'
    > 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:in `require'
    > from<internal:lib/rubygems/custom_require>:33:in `rescue in
    > require'
    > from<internal:lib/rubygems/custom_require>:29:in `require'
    > from ruby-sound.rb:1:in `<main>'
    >
    >
    > Ted.
    >
    >
    >
    >
    >
    > No virus found in this incoming message.
    > Checked by AVG - www.avg.com
    > Version: 9.0.862 / Virus Database: 271.1.1/3212 - Release Date: 10/22/10 07:34:00
    >
    >

    Have you installed the win32-api gem?

    Jim
     
    Jim McKerchar, Oct 22, 2010
    #3
  4. Ted Flethuseo, Oct 23, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. YeeCN

    How to beep or play any sound?

    YeeCN, May 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    546
    Guest
    May 13, 2004
  2. Lord2702

    How to play sound

    Lord2702, Oct 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    583
    =?Utf-8?B?c3Jpbmk=?=
    Oct 4, 2004
  3. edgarv
    Replies:
    0
    Views:
    142
    edgarv
    Oct 10, 2005
  4. NuitLongue
    Replies:
    2
    Views:
    115
    James Britt
    Dec 4, 2005
  5. Larry L
    Replies:
    5
    Views:
    104
    Larry L
    Oct 12, 2004
Loading...

Share This Page