C# WinForm 没有响应 - System.Speech - 帮助
这是来自 C# Windows 窗体的代码
SpeechSynthesizer audio = new SpeechSynthesizer();
audio.Speak(textBox1.Text);
- 这将读取文本框中的任何内容
尝试实现暂停和停止功能时出现问题。当代码读取
public void button1_Click(object sender, EventArgs e)
{
//Nothing gets executed here when the code is reading
}
我刚刚读取的 内容时,不会单击任何按钮或菜单项有 SpeakProgressEventArgs http://msdn。 microsoft.com/en-us/library/system.speech.synthesis.speakprogresseventargs%28VS.85%29.aspx
我尝试了synth...asyncancel...但是按钮的单击事件没有被处决
Here's a code from the C# Windows Form
SpeechSynthesizer audio = new SpeechSynthesizer();
audio.Speak(textBox1.Text);
- This will read anything that is in the textbox
Problem in trying to implement the pause and stop feature.Any button or menuitem doesnt get clicked when the code reads something
public void button1_Click(object sender, EventArgs e)
{
//Nothing gets executed here when the code is reading
}
i just read there is SpeakProgressEventArgs
http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speakprogresseventargs%28VS.85%29.aspx
i tried synth...asyncancel... but the click event of the button doesnt get executed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请改用 SpeakAsync() 方法。这可以防止 UI 阻塞 Speak() 方法,在阻塞时它无法响应按钮单击。您可以使用 SpeakAsyncCancelAll() 来阻止它继续喋喋不休。
Use the SpeakAsync() method instead. That prevents the UI from blocking on the Speak() method, it cannot respond to button clicks while it is blocked. You can use SpeakAsyncCancelAll() to stop it from nattering on.
您需要使用 线程
现在如何停止正在运行的线程?这张海报很好地解释了
点。
you need to manage this block
audio.Speak(textBox1.Text);
using ThreadsNow how to stop a running thread ? very well explained in this poster
point.