I got voice recognition working. I'm not sure why the way I called the sink function made it work but I'm more about results right now. This small example had me rolling on the floor laughing.
<?php
$voice = new COM("SAPI.SpVoice");
print "Hit control+c to end.\n";
print "Friend: Hello friend!\n";
$voice->Speak("Hello friend!");
class listen
{
function Recognition($StreamNumber, $StreamPosition, $RecognitionType, $ISpeechRecoResult)
{
$phrase = $ISpeechRecoResult->PhraseInfo;
$text = $phrase->GetText();
print "\nYou:$text\n";
global $voice;
$say = array('oh', 'nice', 'humm', 'interesting', 'you dont say', 'uh huh', 'right', 'what', 'ha ha', 'you have got to be joking', 'right back at you buddy');
$idx = rand(0, count($say)-1);
print "Friend: " . $say[$idx] . "\n";
$voice->Speak($say[$idx]);
}
}
$recog = new COM("SAPI.SpSharedRecognizer");
$context = $recog->CreateRecoContext();
$listen = new listen(); if (!com_event_sink($context, $listen, "RecognizerStateChange"))
{
print "Unable to sink events\n";
exit;
}
$grammar = $context->CreateGrammar();
$i = $grammar->DictationLoad();
$s = $grammar->DictationSetState(1); while(true)
{
if(!com_message_pump(1000))
{
print ".";
}
}
?>