C# WinForm 没有响应 - System.Speech - 帮助

发布于 2024-08-22 02:57:47 字数 739 浏览 5 评论 0原文

这是来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莳間冲淡了誓言ζ 2024-08-29 02:57:47

请改用 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.

追星践月 2024-08-29 02:57:47

您需要使用 线程

        Thread t = new Thread(() =>
        {
            SpeechSynthesizer audio = new SpeechSynthesizer(); 
            audio.Speak(textBox1.Text);
        });
        t.Start();

现在如何停止正在运行的线程?这张海报很好地解释了

you need to manage this block audio.Speak(textBox1.Text); using Threads

        Thread t = new Thread(() =>
        {
            SpeechSynthesizer audio = new SpeechSynthesizer(); 
            audio.Speak(textBox1.Text);
        });
        t.Start();

Now how to stop a running thread ? very well explained in this poster

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文