snake_mountain has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

My question today has to do with Win32::OLE and SAPI5 speech recognition. This is not a SAPI question but is a Perl question.

I believe that I've accomplished my task of capturing speech recognition events but am unable to convert the HASH to text. I'm able to run my code concurrently with the SAPI5 VB example and see that recognition events are occuring simutaneously.

My output looks as follows (example):

$self = "a hash which is not the problem".
$event = 7 # an event number
$streamnumber = 1 # belongs to my application
$steamposition = 185280 # an index to keep recognition objects in order
$recognition type = 0 # it's for dictation
$result = Win32::OLE=HASH(0x19ad68c) # this should be pointing to the location of the recognized word or word combinations.

My sample code:

sub OnRecognition { my($self,$event,$streamnumber,$steamposition,$recognitiontyp +e,$result) = @_; my $newresult = $self->Invoke('Dispatch',$result); # What now ??? }
Thanks much.

Replies are listed 'Best First'.
Re: Help with SAPI5 Speech Recognition HASH
by sk (Curate) on Dec 24, 2005 at 17:38 UTC
    Don't know anything about SAPIS. I guess you are trying to print out the hash or convert it to a some sort of string to view the match. For starters you can use Data::Dumper.

    The error message is telling you the $result is a hash ref so you need to treat it as hash to view the contents. Here is an example -

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $result = { 'word1' => 1, 'word2' => 1}; print Dumper ($result); # manual printing print $_, " => " , $result->{$_},$/ for (keys %$result); # note the %$

    Output

    $VAR1 = { 'word2' => 1, 'word1' => 1 }; word2 => 1 word1 => 1

    BTW check out QandASection: hashes for more information on hashes.

Re: Help with SAPI5 Speech Recognition HASH
by planetscape (Chancellor) on Dec 25, 2005 at 02:31 UTC