Folks,
This Perl grasshopper finally went back and looked over my code and SAPI5 documentation.
In three hours I was able to hack the following. It is a (crappy) but functional Windoze SAPI5 speech recognition script. It will do for today. Have fun!
If using Vista, be sure and plug in a mic before starting voice recognition, otherwise it will not start.
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE qw( EVENTS );
use Win32::SAPI5;
use constant SGDSActive => 1;
use constant SREAllEvents => 393215;
use constant SpSharedRecoContext => "{47206204-5ECA-11D2-960F-00C04F8E
+E628}";
my $speaker = Win32::SAPI5::SpVoice->new()
or die " \$^E => $^E\nLastError => ".Win32::OLE->LastErro
+r() ;
$speaker->speak("Hello");
my $context = Win32::OLE->new(SpSharedRecoContext) || die "Can't star
+t OLE: ".Win32::OLE->LastError;
$context->SetProperty('EventInterests', SREAllEvents);
Win32::OLE->WithEvents( $context, \&ProcessEvents, "{7B8FCB42-0E9D-4F
+00-A048-7B04D6179D3D}" ); ## Works
my $grammar = $context->CreateGrammar(1);
$grammar->DictationLoad();
$grammar->DictationSetState(SGDSActive);
while( 1 ) {
Win32::OLE->SpinMessageLoop();
Win32::Sleep( 10 );
}
sub ProcessEvents {
my( $Obj, $Event, @Args ) = @_;
if ($Event == 7) {
\&OnRecognition(@_);
}
}
sub OnRecognition {
my($self, $Event, $StreamNumber, $StreamPosition, $RecognitionType
+, $Result) = @_;
my $newResult = $self->Invoke('Dispatch', $Result);
print $Result->PhraseInfo->GetText() . "\n";;
}
|