Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Speech API (SAPI) SpVoice A Way for a Stop function

I'm working with Speech Platform Run time of Microsoft and i'm using the SpVoice interface to make the run time speak the sentences i want.

To Stop the speech mid sentence i created my function like this

public void StopSpeak()
{
    try
    {
      Speaker.Speak("", SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
    }
    catch (COMException ex)
    {

    }
}

But when i run this while the Speech Platform is speaking i get this com error:

Exception from HRESULT: 0x80045006

I looked it up by Microsoft and it means that the wave device is busy, i now realize that i get this error every time the Speech Platform is busy speaking a sentence.

Is there a other way to stop the speech mid sentence using SpVoice or any other interface or class that comes with the Speech Platform Runtime ?

Thanks.

like image 255
P.G Wisgerhof Avatar asked Apr 19 '12 08:04

P.G Wisgerhof


1 Answers

To stop the Speech without having to deal with the exception, use the Skip method on SpVoice. Documentation here.

This should work, as it will skip int.MaxValue sentences:

public void StopSpeak()
{
    Speaker.Skip("Sentence", int.MaxValue);
}
like image 97
davisoa Avatar answered Oct 06 '22 17:10

davisoa