-1

how to avoid delay after use text to speech function in c#, how to avoid delay after SpeechSynthesizer.speak , i would like to my timer enable immediately.

SpeechSynthesizer sr = new SpeechSynthesizer();
sr.Rate = 1;
sr.Volume = 100;
sr.Speak("mytext");
timer1.enabled=true; /*how to run this line immediately, not wating for    sr.speak */
Afshin Izadi
  • 527
  • 1
  • 6
  • 13

2 Answers2

0

You need to use an asynchronous version of Speak. If this is not available, then you can create a thread to run Speak in the background.

SpeechSynthesizer sr = new SpeechSynthesizer();
sr.Rate = 1;
sr.Volume = 100;

//the following starts a background thread
Task.Factory.StartNew(
  () =>
     {
        //this anon method will be run in a background thread
        sr.Speak();
        SpeakCallBack();
     });

When defining SpeakCallBack make sure to Invoke any UI code.

Can Bud
  • 142
  • 1
  • 11
0
private async void speakSomething(string message)
{
  SpeechSynthesizer sr = new SpeechSynthesizer();
  sr.Rate = 1;
  sr.Volume = 100;
  await sr.Speak(message);
}

Then, in your main function or whichever method just now...

speakSomething("my text");
timer1.enabled=true;
Ivan Ling
  • 127
  • 2
  • 10