我是编程新手。提前道歉
我正在使用Speak功能。当第一个表单隐藏,第二个表单打开时。说话功能仍然有效。我想停止这个功能。我该怎么做
//Second Form
private void button1_Click(object sender, EventArgs e)
{
Form2.Show();
this.Hide();
}
//Speak Button
private void button2_Click(object sender, EventArgs e)
{
sSynth.Dispose();
if (textBox1.Text != "") //if text area is not empty
{
sSynth = new SpeechSynthesizer();
sSynth.SpeakAsync(textBox1.Text);
sSynth.SpeakCompleted+=new
EventHandler<SpeakCompletedEventArgs(reader_SpeakCompleted);
}
}
private void reader_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
}
答案 0 :(得分:0)
要取消所有背景异步语音,您应该从第一个表单中调用一个非常好的取消方法:
sSynth.SpeakAsyncCancelAll ();
取消所有排队的异步语音合成操作
...或取消特定的提示使用此提示:
sSynth.SpeakAsyncCancel (_prompt);
...其中_prompt
是您之前sSynth.SpeakAsync(...)
的返回值,应该如下所示:
_prompt = sSynth.SpeakAsync(something);