Is asynchronous text-to-speech voicing with SAPI 5.4 possible?

别说谁变了你拦得住时间么 提交于 2019-12-11 17:53:34

问题


I have a form and I want to allow the user to receive asynchronous (possibly overlapping) text-to-speech output based on the context of a text box whenever a button is pressed. I'm trying to do this via SAPI 5.4 (Interop.SpeechLib.dll). I recognize that System.Speech or other more "modern" functionality would work much better, but this is my current constraint. Here is a simplified version of my function:

private void VoiceText(string myText)
{
    SpVoice voice = new SpVoice(); // Create new SPVoice instance
    voice.Volume = 100; // Set the volume level of the text-to-speech voice
    voice.Rate = -2; // Set the rate at which text is spoken by the text-to-speech engine
    voice.Speak(text, SpeechVoiceSpeakFlags.SVSFlagsAsync); // Voice text (asynchronously?)
}

Using SVSFlagsAsync DOES allow subsequent code to execute, however the actual voicing always outputs synchronously (no overlapping, and there are brief pauses between voicing instances). I've tried calling this function as an async Task as well as in a separate thread, and still this behavior remains. Is this simply a limitation of SpVoice?


回答1:


You can cancel any currently running TTS request by using the SVSFPurgeBeforeSpeak flag on your Speak call, like this:

voice.Speak(text, SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);


来源:https://stackoverflow.com/questions/54737945/is-asynchronous-text-to-speech-voicing-with-sapi-5-4-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!