private
void
button1_Click(
object
sender, System.EventArgs e)
... {
try
...{
SpeechLib.SpeechVoiceSpeakFlags spflags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpeechLib.SpVoice voice = new SpVoice();
voice.Speak(this.textboxtext.Text,spflags);
}
catch(Exception er)
...{
MessageBox.Show("语音读取失败","请重试!",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
... {
try
...{
SpeechLib.SpeechVoiceSpeakFlags spflags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpeechLib.SpVoice voice = new SpVoice();
voice.Speak(this.textboxtext.Text,spflags);
}
catch(Exception er)
...{
MessageBox.Show("语音读取失败","请重试!",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private
void
button2_Click(
object
sender, System.EventArgs e)
... {
try
...{
SpeechVoiceSpeakFlags spflags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpeechLib.SpVoice voice = new SpVoice();
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "all files (*.*)|*.*|wav files (*.wav)|*.wav";
sfd.Title = "保存语音文件";
sfd.FilterIndex = 2;
sfd.RestoreDirectory = true;
if (sfd.ShowDialog() == DialogResult.OK)
...{
SpeechStreamFileMode spfilemode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream spfilestream = new SpFileStream();
spfilestream.Open(sfd.FileName, spfilemode, false);
voice.AudioOutputStream = spfilestream;
voice.Speak(textboxtext.Text, spflags);
voice.WaitUntilDone(Timeout.Infinite);
spfilestream.Close();
}
}
catch(Exception er)
...{
MessageBox.Show("语音读取失败","请重试!", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
... {
try
...{
SpeechVoiceSpeakFlags spflags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpeechLib.SpVoice voice = new SpVoice();
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "all files (*.*)|*.*|wav files (*.wav)|*.wav";
sfd.Title = "保存语音文件";
sfd.FilterIndex = 2;
sfd.RestoreDirectory = true;
if (sfd.ShowDialog() == DialogResult.OK)
...{
SpeechStreamFileMode spfilemode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream spfilestream = new SpFileStream();
spfilestream.Open(sfd.FileName, spfilemode, false);
voice.AudioOutputStream = spfilestream;
voice.Speak(textboxtext.Text, spflags);
voice.WaitUntilDone(Timeout.Infinite);
spfilestream.Close();
}
}
catch(Exception er)
...{
MessageBox.Show("语音读取失败","请重试!", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}