如果另一条消息要说出来,如何停止SpeakAsync?

时间:2015-07-18 17:24:06

标签: 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

1 个答案:

答案 0 :(得分:1)

使用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.");