我正在编写一个文本转语音程序,我的程序抛出异常(simpleTTS 语音错误)。
我该如何解决这个问题?
private void Voiced(String textToSpeech)
{
try
{
SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
Voice = new SpVoice();
Voice.Volume = 100;
if (chkSaveToWavFile.Checked)
{
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(textToSpeech, SpFlags);
SpFileStream.Close();
}
}
else
{
Voice.Speak(textToSpeech, SpFlags);
}
}
catch (Exception error)
{
MessageBox.Show("Speak error", "SimpleTTS", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}