我如何让 C# 中的 EventHandler(SpeakCompleted) 工作? (System.Speech)
How do i get the EventHandler(SpeakCompleted) in C# to work? (System.Speech)
简单地说,我想制作一个倒计时的程序(+语音),但是当像 1mil 这样的数字出现时,这需要超过 1 秒的时间才能发音,所以我想知道如何获得 "EventHandler" 到 运行 以及我如何使用它(我不需要用于计数等的代码,但是如何创建 EventHandler 以及当它被调用时我需要在哪里编写代码)
我不能只使用 Text.Speak("")
因为这会导致与打印的文本不同步。我需要那个回调来开始新的 Speak 并将其与 Text 同步。
对不起...我不想问别人但是 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
The SpeechSynthesizer raises the SpeakCompleted event at the completion of any of the SpeakAsync or SpeakSsmlAsync methods.
简单地说,我想制作一个倒计时的程序(+语音),但是当像 1mil 这样的数字出现时,这需要超过 1 秒的时间才能发音,所以我想知道如何获得 "EventHandler" 到 运行 以及我如何使用它(我不需要用于计数等的代码,但是如何创建 EventHandler 以及当它被调用时我需要在哪里编写代码)
我不能只使用 Text.Speak("")
因为这会导致与打印的文本不同步。我需要那个回调来开始新的 Speak 并将其与 Text 同步。
对不起...我不想问别人但是 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
The SpeechSynthesizer raises the SpeakCompleted event at the completion of any of the SpeakAsync or SpeakSsmlAsync methods.