Hi everyone, here is the code:
--------------------------------------------
Add-Type -AssemblyName System.Speech
$talker = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$talker.add_SpeakCompleted({
Write-Host "End"
})
$talker.SpeakAsync("Hello!")
--------------------------------------------
This one should say "Hello". The problem is that that I get message that PowerShell stopped working. I tried to put a brake point in the event , but it looks that it doesn't get into it. It is possible to prevent this problem by using "Speak" method instead, but SpeakCompleted in that case is never fired, but SpeakProgress are fired. If you would change the event in the code with any other it will crash too.
In some cases it does work as I want, let's say this:
--------------------------------------
$talker = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$buttonSpeak.add_Click({
$talker.add_SpeakCompleted({
Write-Host "End"
})
$talker.SpeakAsync("Hello!")
})
------------------------------------------
In this case the code works perfectly, but you every time I add event handler, that's not good.
I have another code that uses SpeakAsync and SpeakCompelted event and fully works as I want.
Anyone could enlighten me what I am doing wrong?
Thanks in advance,
David |