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("你好,请稍等!");
        }

你可能感兴趣的:(转载资料,c#)