简单的说,我想做一个倒计时的程序(+语音),但当数字如1mil出现时,需要超过1秒的时间来发音,所以我想知道如何让 "EventHandler "运行,以及如何使用它(我不需要计数的代码等,但如何创建一个EventHandler,以及当它被调用时,我需要在哪里写代码)。
我不能只用 Text.Speak("")
因为这将导致与文本打印的desync。我需要这个回调来启动一个新的Speak并与文本同步。
对不起......我不想问大家,但3小时后我投降了,请大家帮助我。
SpeechSynthesizer synth = new SpeechSynthesizer();
int counting = 0;
private void TTS() //First trigger
{
synth.SetOutputToDefaultAudioDevice();
synth.SelectVoiceByHints(VoiceGender.Female, VoiceAge.NotSet, 0);
textBox1.Text = "1";
synth.Speak("1");
counting = 1;
synth.SpeakCompleted += synth_SpeechOver;
}
//public event EventHandler<System.Speech.Synthesis.SpeakCompletedEventArgs> SpeakCompleted; deleted
public void synth_SpeechOver(object sender, EventArgs e)
{
synth.SetOutputToDefaultAudioDevice();
synth.SelectVoiceByHints(VoiceGender.Female, VoiceAge.NotSet, 0);
counting++;
synth.Speak(counting.toString());
}
void Form1_SpeakCompleted(object sender, EventArgs e)
{
}
//(Form1_SpeakCompleted is just for testing (doesnt work)
回调只适用于SpeakAsync
SpeechSynthesizer在任何一个SpeakAsync或SpeakSsmlAsync方法完成时都会引发SpeakCompleted事件。