Win32::SAPI4 question (Win32 events and Perl)

M

Michael Edmonson

I've been playing around with the Win32::SAPI4 module, which provides
access to a slightly crufty version of Microsoft's speech API. I've
been able to get a simple speech example working, though I've been
unable to figure out how how events such as "SpeakingStarted" and
"SpeakingDone" are accessed. These are mentioned in the "vb.chm"
documentation (Microsoft Speech SDK/document/vb.chm, under Voice Text
Control, Events), which says only:

Events
The Voice Text control can receive the following events:

SpeakingDone()
Occurs when speaking is finished and no text remains in the
playback queue.

SpeakingStarted()
Occurs when speaking has started.

I was wondering if anyone has any idea how these events, or Win32
events in general, may be accessed via Perl. Is Win32::Event involved?
Or are they supposed to be implemented and registered somehow as
callback subs? Or something else?

Here is some code that speaks a string (that part works, anyway),
trying to receive notification when playback is finished:

#!/usr/bin/perl -w
# speech demo

use strict;
use Win32::SAPI4;
use Win32::Event;

my $vt = new Win32::SAPI4::VoiceText();

$vt->Select($vt->find("Gender=1"));

my $text = "this is only a test";

$vt->Speak($text);

sub SpeakingDone {
# ???
die "speakingdone";
}

sub SpeakingStarted {
# ???
die "speakingstarted";
}

my $ev = new Win32::Event(0,0,"SpeakingDone");
$ev->wait(5000);
# seems to block the speech from starting for 5 seconds
# rather than being signaled when it ends

print "done\n";

Unfortunately, neither callback sub is ever invoked, and the
Win32::Event code just seems to get in the way. I know I can just loop
while testing the "IsSpeaking" property, which is okay, but I'm actually
mostly concerned about events because interacting with them seems
unavoidable when using the Voice Dictation control.

Any advice at all would be appreciated. The Win32::SAPI4 and
Win32::Event docs are woefully brief, and Google has been surprisingly
coy about coughing up Win32 event-related Perl code.

Michael
 

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top