c# - 如果另一条消息即将说出,如何停止 SpeakAsync?

标签 c# speech-recognition text-to-speech speech speech-to-text

我正在尝试使用 C# 作为我的代码来创建一个具有语音识别功能的网页。 请帮助我,因为我想知道当另一条消息开始说话时如何停止 SpeakAsync 来传递完整消息。

像这样的伪代码

 protected void Button1_Click(object sender, EventArgs e)
    {
        ss.SpeakAsync(CurrentStop); // it means if there is a current message it should stop before delivering the next line
        ss.SpeakAsync("Phrase and Sentence");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        ss.SpeakAsync(CurrentStop);
        ss.SpeakAsync("Phrase is a group of words without a complete thought.");
    }

请帮助我。这是我第一次使用 c# 和 system.speech

最佳答案

使用 GetCurrentlySpokenPromptSpeakAsyncCancel 方法取消当前提示:

var current = ss.GetCurrentlySpokenPrompt();

if (current != null)
    ss.SpeakAsyncCancel(current);

完整示例

var ss = new SpeechSynthesizer();

ss.SpeakAsync("This is a test.");

Thread.Sleep(300);

var current = ss.GetCurrentlySpokenPrompt();

if (current != null)
    ss.SpeakAsyncCancel(current);

ss.SpeakAsync("Goodbye.");

关于c# - 如果另一条消息即将说出,如何停止 SpeakAsync?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31493650/

相关文章:

c# - 将从接口(interface)类型获得的 MethodInfo 对象转换为 C# 中实现类型的相应 MethodInfo 对象?

macos - NSSpeechRecognizer 委托(delegate)从未调用过

ios - swift:如何在单击按钮上对所有单元格进行 TTS

android - 在 Marshmallow (Android 6) 上使用 TTS 中的声音文件因权限问题而失败

android - 在 Android 中使用录音的 SpeechRecognizer

c++ - 如何将文本更改为语音以及如何将字符插入字符数组

c# - C#语句中的逗号

c# - AjaxToolkit :ComboBox + AjaxToolkit:ModalPopupExtender -- The ComboBox dropdown list cuts off. .. 如何修复?

c# - 给定两个整数的方法返回最接近 1000 的值

java - 将视频或音频转换为文本而不播放?