C# 生成語音文件


 //引用文件 Interop.SpeechLib.dll
private void writeWavFile(string message)
        {
            SpeechLib.SpeechVoiceSpeakFlags SpFlags;
            SpeechLib.ISpeechVoice voice = null;
            SpFlags = SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync;
            voice = new SpeechLib.SpVoice();
            string fileName = "D:/VoiceContent" + System.DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".wav";
            SpeechLib.SpeechStreamFileMode SSFM = SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite;
            SpeechLib.SpFileStream SFS = new SpeechLib.SpFileStreamClass();
            SFS.Open(fileName, SSFM, false);
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
            ////音量
            //voice.Volume = 100;
            voice.AudioOutputStream = SFS;
            voice.Speak(message, SpFlags);
            voice.WaitUntilDone(System.Threading.Timeout.Infinite);
            SFS.Close();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            writeWavFile("你好,請稍等!");
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章