Event Handler in Powershell

by mk.maddin at 2013-05-12 04:53:08

Hi,

I am trying to do some voice recognition via Powershell. - Just to play a bit.
I have already found some information about this with help of google. But the most source code is in C#.

My Problem is the following. In C# the event handler is attached like the following:
[code2=csharp]speechRecognitionEngine.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized);[/code2]

How can I do this in Powershell?
I’ve tried to do the following:
[code2=powershell]$handler = [System.EventHandler[System.Speech.Recognition.SpeechDetectedEventArgs]](engine_SpeechRecognized)
$speechRecognitionEngine.SpeechRecognized += $handler[/code2]

But this doesn’t work. It tells me "Property ‘SpeechRecognized’ cannot be found on this object; Make sure it exists and is settable."
For additional Information:
- $SpeechRecognitionEngine is a object of type System.Speech.Recognition.SpeechRecognitionEngine
- engine_SpeechRecognized is a function doing something ( in easiest way to write-host “SpeechRecognzed” ).

I know about Add-Type command and that I can use C# Code within powershell with it. But that is not what I want.

Thank you for your help

mk.maddin