programming a bird -- yes!

  • Thread starter Gerard A.W. Vreeswijk
  • Start date
G

Gerard A.W. Vreeswijk

Hello all,

Hi all,

Serious (but possibly less attracting) subject title: Win32ole event loop
with MSAgent.

Thanks to Suketa Masaki for doing such a good job on giving us 'win32ole'.
It relieves us from Microsoft's RSI-stimulating clickfests.

Inspired by Rubytalk 36676, Shusaku <[email protected]>:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/36676

I decided I wanted to beef up my Agent-app with MSAgent (sorry, Unix):

http://www.microsoft.com/msagent/downloads/user.asp
(download merlin + speech engine + maybe more, depending on your
hardware)

Tried out the script below. All works fine --- as a matter of fact, I
showed one of the characters who happens to be a bird called Peedy to my
4-year old son pronouncing my son's name. He ran down to his mom and said
that a bird talked to him and knew his name :)

Anyway:
======================================================================
#!/usr/bin/ruby
require 'win32ole'

agent = WIN32OLE.new('Agent.Control.1')
agent.Connected = true
agent.Characters.Load("some random string, 'peedy' or so", "peedy.acs")

peedy = agent.Characters("some random string, 'peedy' or so")

# The way we should officialy check when we're done:
ev = WIN32OLE_EVENT.new(agent, nil)
ev.on_event("RequestComplete") { |rRequest|

# rRequest.ole_obj_help.name -> "IAgentCtlRequest"
# rRequest.ole_obj_help.typekind -> 4 ( TKIND_DISPATCH )
# rRequest.ole_obj_help.ole_type -> "Dispatch"
# rRequest.ID -> 197 ( ?? )

if rRequest.ID == $peedySpeak.ID
peedy.Hide # or exit, or move on, or ..
end

}

peedy.Show

# You can program gestures here. Nothing fancy at the moment, just
speak.

$peedySpeak = peedy.Speak <<EOF
Thanks Suketa Masaki, for giving us win32ole!
And thanks Shusaku, for giving us a link between Ruby-win32ole and
MsAgent!
EOF

# speak = peedy.ole_method("Speak") #=> WIN32OLE_METHOD
# speak.return_vtype #=> 26
# speak.return_type #=> "IAgentCtlRequest"
# speak.return_type_detail #=> ["PTR", "USERDEFINED", "IAgentCtlRequest"]


# More mundane check to see when we're done:
loop do
$stderr.puts $peedySpeak.Status
$stderr.flush
# status should become 0 or so, see
#
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msagent/pacontrol_3tws.asp
break if $peedySpeak.Status != 2
sleep 1
end

# never get here :-(

======================================================================


As you see, the WIN32OLE_EVENT-loop doesn't seem to recognize events,
which is needed to recognize that an action is over.
Also, the "Status" attribute does not work. Status could also be used to
see that an action is over. Currently, Status keeps returning 2's. This
is different from Perl's,

foreach my $animation ($c->AnimationNames)
{
my $request = $c->Play($animation);
$c->Speak($animation);
my $i = 0;
while (($request->Status == 2) || ($request->Status == 4))
{ $c->Stop($request) if $i >10; sleep(1); $i++}
}


where it *does** work (not the events, though). (Thanks, Jouke). See

http://www.cpan.org/modules/by-authors/id/J/JO/JOUKE/

Examined Suketa Masaki "ienavi.rb" example for inspiration. There must be
some "DWebBrowserEvents" event sink identifier for MSAgent as well, but
which??

Thanks.
Gerard
 
S

Shusaku

Hi, Gerard

On Mon, 14 Jul 2003 09:55:35 GMT
loop do
$stderr.puts $peedySpeak.Status
$stderr.flush
break if $peedySpeak.Status != 2
WIN32OLE_EVENT.message_loop # <== You should insert this!
sleep 1
end

Now, the loop would be terminated by 'Status == 4', although it
means "Request in progress". I think the break condition might
be 'Status == 0', which means "Request successfully completed".
 
S

Shusaku

I forgot to answer your other question.

On Mon, 14 Jul 2003 09:55:35 GMT
Examined Suketa Masaki "ienavi.rb" example for inspiration. There must be
some "DWebBrowserEvents" event sink identifier for MSAgent as well, but
which??

"_AgentEvents" is the one you are looking for.

agent = WIN32OLE.new('Agent.Control.1')
ev = WIN32OLE_EVENT.new(agent, '_AgentEvents')
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top