# Problem with win32ole, sapi5

**URL:** <https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545>\
**Category:** Ruby\
**Created:** [March 8, 2006, 7:44am UTC](https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545 "2006-03-08T07:44:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 8, 2006, 7:44am UTC](https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545/1 "2006-03-08T07:44:24Z")

</div>

Hi all,

Ruby 1.8.4 (both installer and hand built)  
win32-sapi 0.1.3

Why does my attempt to set the voice fail?

C:\eclipse\workspace\win32-sapi\>c:\ruby184\bin\irb  
irb(main):001:0\> require ‘win32/sapi5’  
=\> true  
irb(main):002:0\> include Win32  
=\> Object  
irb(main):003:0\> v = SpVoice.new  
=\> #Win32::SpVoice:0x2bffe70  
irb(main):004:0\> hash = {}  
=\> {}  
irb(main):005:0\> v.getvoices.each{ |voice|  
hash[File.basename(voice.Id)] = voice }  
=\> nil  
irb(main):006:0\> hash  
=\> {“MSMary”=\>#WIN32OLE:0x2bf1c20, “MSSam”=\>#WIN32OLE:0x2bf1ce0,  
“SampleTTSVoice”=\>#WIN32OLE:0x2bf1b90, “MSMike”=\>  
#WIN32OLE:0x2bf1cb0}  
irb(main):007:0\> v.voice = hash[“MSMary”]  
WIN32OLERuntimeError:  
OLE error code:0 in   
  
HRESULT error code:0x80020003  
Member not found.  
from (irb):8:in `method\_missing’  
from (irb):8

I also tried v.setproperty(“voice”,hash[“MSMary”]) but got the same  
result.

Any ideas?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [June 12, 2006, 9:04pm UTC](https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545/2 "2006-06-12T21:04:58Z")

</div>

Hi,

Does anyone have any input on this old post? I’m having the same  
problem, but I can’t find any response to the post anywhere. Basically  
it seems that win32ole doesn’t discover that SpVoiceInstance.Voice is  
both a gettable and settable property:

irb(main):053:0\> Win32::SpVoice.new.ole\_get\_methods  
=\> [Status, Voice, AudioOutput, AudioOutputStream, Rate, Volume,  
AllowAudioOutpu  
tFormatChangesOnNextSet, EventInterests, Priority, AlertBoundary,  
SynchronousSpe  
akTimeout]  
irb(main):054:0\> Win32::SpVoice.new.ole\_put\_methods  
=\> [Rate, Volume, AllowAudioOutputFormatChangesOnNextSet,  
EventInterests, Priori  
ty, AlertBoundary, SynchronousSpeakTimeout]  
irb(main):055:0\>

Is this a bug? The following is valid VB source code:

Set V.Voice = V.GetVoices().Item(List1.ListIndex)

So I’d expect something like this to work:

require ‘win32/sapi5’  
v = Win32::SpVoice.new  
v[‘Voice’] = v.GetVoices.Item(1)

But it doesn’t. I’ve tried all possible variants I can think of from the  
documentation:

v.Voice = …  
v.voice = …  
v.Voice(…)  
v.voice(…)  
v[‘voice’] = …  
v[‘Voice’] = …  
v.setproperty(‘voice’, …)  
v.setproperty(‘Voice’, …)

Basically I’d really love to get this to work properly. This weeks Ruby  
Quiz inspired me to give a go at a “personal trainer” for my treadmill  
sessions here at home. For now I’ve settled for a tiny VB .NET command  
line app that sets the voice I want, and takes text as an argument. I’d  
really love to have an all Ruby solution for this though.

Regards,  
Helge E.

Daniel B. wrote:

> Hi all,
> 
> Ruby 1.8.4 (both installer and hand built)  
> win32-sapi 0.1.3
> 
> Why does my attempt to set the voice fail?
> 
> C:\eclipse\workspace\win32-sapi\>c:\ruby184\bin\irb  
> irb(main):001:0\> require ‘win32/sapi5’  
> =\> true  
> irb(main):002:0\> include Win32  
> =\> Object  
> irb(main):003:0\> v = SpVoice.new  
> =\> #Win32::SpVoice:0x2bffe70  
> irb(main):004:0\> hash = {}  
> =\> {}  
> irb(main):005:0\> v.getvoices.each{ |voice|  
> hash[File.basename(voice.Id)] = voice }  
> =\> nil  
> irb(main):006:0\> hash  
> =\> {“MSMary”=\>#WIN32OLE:0x2bf1c20, “MSSam”=\>#WIN32OLE:0x2bf1ce0,  
> “SampleTTSVoice”=\>#WIN32OLE:0x2bf1b90, “MSMike”=\>  
> #WIN32OLE:0x2bf1cb0}  
> irb(main):007:0\> v.voice = hash[“MSMary”]  
> WIN32OLERuntimeError:  
> OLE error code:0 in   
>   
> HRESULT error code:0x80020003  
> Member not found.  
> from (irb):8:in `method\_missing’  
> from (irb):8
> 
> I also tried v.setproperty(“voice”,hash[“MSMary”]) but got the same  
> result.
> 
> Any ideas?
> 
> Thanks,
> 
> Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [June 13, 2006, 12:26am UTC](https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545/3 "2006-06-13T00:26:02Z")

</div>

Helge E. wrote:

> Hi,
> 
> Does anyone have any input on this old post? I’m having the same  
> problem, but I can’t find any response to the post anywhere. Basically  
> it seems that win32ole doesn’t discover that SpVoiceInstance.Voice is  
> both a gettable and settable property

I think it’s a bug in win32ole. I recommend submitting a report on the  
RubyForge bug tracker for Ruby.

- Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [June 16, 2006, 5:29pm UTC](https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545/4 "2006-06-16T17:29:35Z")

</div>

Hello,  
In message “Re: Problem with win32ole, sapi5”  
on 06/06/13, Masaki S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > irb(main):055:0\>
> > 
> > Is this a bug? The following is valid VB source code:
> > 
> > Set V.Voice = V.GetVoices().Item(List1.ListIndex)
> 
> Sorry, this is a bug of Win32OLE.  
> But please give me some time to fix it.

I have fixed it in Ruby 1.8.4 latest CVS snapshot.  
The following script works fine.

require ‘win32/sapi5’  
v = Win32::SpVoice.new  
v.voice = v.getvoices.item(2)

Regards,  
Masaki S.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [June 16, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545/5 "2006-06-16T17:36:02Z")

</div>

Masaki S. wrote:

> > > irb(main):054:0\> Win32::SpVoice.new.ole\_put\_methods
> 
> I have fixed it in Ruby 1.8.4 latest CVS snapshot.  
> The following script works fine.
> 
> require ‘win32/sapi5’  
> v = Win32::SpVoice.new  
> v.voice = v.getvoices.item(2)
> 
> Regards,  
> Masaki S.

Excellent! I have at least one blind user who will be very happy to  
hear it. 🙂

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [June 13, 2006, 3:25pm UTC](https://www.ruby-forum.com/t/problem-with-win32ole-sapi5/54545/6 "2006-06-13T15:25:26Z")

</div>

Hello, Sorry for being too late to reply.

In message “Re: Problem with win32ole, sapi5”  
on 06/06/13, Helge E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> akTimeout]  
> irb(main):054:0\> Win32::SpVoice.new.ole\_put\_methods  
> =\> [Rate, Volume, AllowAudioOutputFormatChangesOnNextSet,  
> EventInterests, Priori  
> ty, AlertBoundary, SynchronousSpeakTimeout]  
> irb(main):055:0\>
> 
> Is this a bug? The following is valid VB source code:
> 
> Set V.Voice = V.GetVoices().Item(List1.ListIndex)

Sorry, this is a bug of Win32OLE.  
But please give me some time to fix it.

Regards,  
Masaki S.
