提高语音合成的性能

时间:2013-09-16 14:21:07

标签: c# text-to-speech speech-synthesis

我在winform中有100个按钮。每个按钮执行类似的动作,即演讲自己的号码。说按钮60将发言60,按钮100将发言100。

我使用了这些代码:

SpeechSynthesizer synthesizer = new SpeechSynthesizer();
         ...............

 private void Form1_Load(object sender, EventArgs e)
    {

        seme_comboBox.SelectedIndex = 0;
        dpt_comboBox.SelectedIndex = 0;


        foreach (var button in Controls.OfType<Button>()) 
        {
            button.Click += button_Click;
        }


    }

然后

    private void button_Click(object sender, EventArgs e)
    {
        Button button = (Button)sender;
        string text = button.Name.Substring("button".Length);

        synthesizer.Speak(text);
    }

但是,如果我按顺序点击两个按钮,则至少需要2或3秒才能切换另一个按钮和语音。 而且它的声音也不够响亮。 所以我需要在很短的时间内提高按钮动作的性能。而且我还想增加语音的声音。 我怎样才能做到这一点???

1 个答案:

答案 0 :(得分:2)

听起来,SpeechSynthesizer正在阻止UI线程。

您可以尝试使用SpeakAsync()代替(来自http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.speakasync.aspx

请注意,您可能想要也可能不想要取消全部(注释)的行:

private void button_Click(object sender, EventArgs e)
{
    Button button = (Button)sender;
    string text = button.Name.Substring("button".Length);
    synthesizer.SpeakAsyncCancelAll(); // cancel anything that's playing
    synthesizer.SpeakAsync(text);
}

如果没有,你可以在另一个线程中运行sythesizer。

您可以使用.Volume属性控制音量:

synthesizer.Volume = 100; // maximum volume (range 0-100)
相关问题