文字转语音错误

时间:2012-04-28 03:38:14

标签: c# speech-synthesis

我正在编写一个文本转语音程序,我的程序抛出一个异常(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);
    }
}

0 个答案:

没有答案