Greetings,

Ive been a member some years but never posted until now. I'm an admitted terrible Perl coder. So please be gentle.

I've read the MS SAPI documentation and have tested the python version with success but still haven't got a Perl version to work. Being weak with Oops, I blindly hacked what I think is on the right track. I blended two non-functional code solutions to this problem, one from the Python Cokbook and the other from Jorke Visser of pvoice. I've sent Jorke a copy at his request but never heard back.

Could some Monk take mercy on this lost soul and help me interpret these events? I believe event 7 points to a set of probable word or phrase matches.

Thanks.

#!/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(@_); } if ($Event == 8) { \&OnRecognition(@_); } } sub OnRecognition { print("Inside = @_\n"); my($self, $Event, $StreamNumber, $StreamPosition, $RecognitionType +, $Result) = @_; my $newResult = $self->Invoke('Dispatch', $Result); # print "\$newResult = $newResult\n\n}"; }

20070730 Janitored by Corion: Fixed code tags, as per Writeup Formatting Tips


In reply to Re^2: Speech Recognition with SAPI5 by snake_mountain
in thread Speech Recognition with SAPI5 by johnnywang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.