首先要添加 dotNetSpeech.dll 文件的引用
实例化 spVoice voice=new dotNetSpeech.spVoice();
spVoice 方法的 可以控制 文本朗读过程中的各个环节...
//朗读
private void buttonSynthesis_Click(object sender, System.EventArgs e)
{
try
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice Voice = new SpVoice();
Voice.Speak(this.textBoxText.Text, SpFlags);
}
catch(Exception er)
{
MessageBox.Show("An Error Occured!","SpeechApp", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//生成声音文件(Wav)
private void buttonTTStoWave_Click(object sender, System.EventArgs e)
{
try
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice Voice = new SpVoice();
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
sfd.Title = "Save to a wave file";
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(txtSpeakText.Text, SpFlags);
Voice.WaitUntilDone(Timeout.Infinite);
SpFileStream.Close();
}
}
catch(Exception er)
{
MessageBox.Show("An Error Occured!","SpeechApp", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}