所以,我正在使用SpeechSynthesizer
类来创建一个音频文本阅读器。当声音开始说话时,我想显示一个带有消息的表单,例如“等待,正在阅读文本”,带有按钮' Stop Reading
')。如果用户点击按钮,文本阅读应该停止。如果用户没有点击按钮,那么表单必须在阅读完整个文本后自动关闭。
我面临的问题是我不知道如何捕捉发言停止的那一刻,我不知道何时或如何关闭表格。
也许用 比较好MessageBox
,不过没关系,我会想办法的。主要问题是我不知道什么时候关闭它。我希望我说清楚了,提前谢谢你。
我还没有在表单中添加任何按钮...
private void Play_Click(object sender, EventArgs e)
{
string textToRead;
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
synthesizer.Volume = trackBarVolume.Value; // 0...100
synthesizer.Rate = trackBarSpeed.Value; // -10...10
textToRead = richTexBoxinput.Text;
richTexBoxinput.Text = "";
synthesizer.SpeakStarted += speakStarted;
synthesizer.Speak(textToRead);
}
static void speakStarted(object sender, SpeakStartedEventArgs e)
{
Form form = new Form();
Label label = new Label();
label.Text = "Please wait, the text is being read";
form.Controls.Add(label);
form.Show();
// I need to close this form after finishing the speak.
}