使用SAPI 5.4可以进行异步文本语音转换吗? [英] Is asynchronous text-to-speech voicing with SAPI 5.4 possible?

查看:82
本文介绍了使用SAPI 5.4可以进行异步文本语音转换吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我希望允许用户每当按下按钮时就基于文本框的上下文接收异步(可能重叠)的文本到语音输出.我正在尝试通过SAPI 5.4(Interop.SpeechLib.dll)执行此操作.我认识到System.Speech或其他现代"功能会更好,但这是我目前的限制.这是我的函数的简化版本:

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?)
}

使用SVSFlagsAsync DOES可以执行后续代码,但是实际的语音总是同步输出(没有重叠,并且在语音实例之间存在短暂的停顿).我尝试将此函数作为异步任务以及在单独的线程中调用,但此行为仍然存在.这仅仅是SpVoice的局限性吗?

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?

推荐答案

您可以通过使用 Speak 调用上的 SVSFPurgeBeforeSpeak 标志来取消任何当前正在运行的TTS请求,例如这个:

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);

这篇关于使用SAPI 5.4可以进行异步文本语音转换吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆