aBs0lut3z33r0
aBs0lut3z33r0

Reputation: 95

C# WinForm not Responsive - System.Speech - Help

Here's a code from the C# Windows Form

SpeechSynthesizer audio = new SpeechSynthesizer(); 
audio.Speak(textBox1.Text);

Problem in trying to implement the pause and stop feature.Any button or menuitem doesnt get clicked when the code reads something

public void button1_Click(object sender, EventArgs e)
    {
        //Nothing gets executed here when the code is reading
    }

i just read there is SpeakProgressEventArgs http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speakprogresseventargs%28VS.85%29.aspx

i tried synth...asyncancel... but the click event of the button doesnt get executed

Upvotes: 1

Views: 1833

Answers (2)

Hans Passant
Hans Passant

Reputation: 942040

Use the SpeakAsync() method instead. That prevents the UI from blocking on the Speak() method, it cannot respond to button clicks while it is blocked. You can use SpeakAsyncCancelAll() to stop it from nattering on.

Upvotes: 4

Asad
Asad

Reputation: 21928

you need to manage this block audio.Speak(textBox1.Text); using Threads

        Thread t = new Thread(() =>
        {
            SpeechSynthesizer audio = new SpeechSynthesizer(); 
            audio.Speak(textBox1.Text);
        });
        t.Start();

Now how to stop a running thread ? very well explained in this poster

Upvotes: 3

Related Questions