Ejemplo n.º 1
0
 public void PlaySound(string FileName)
 {//要加载COM组件:Microsoft speech object Library
     if (!System.IO.File.Exists(FileName))
     {
         return;
     }
     SpeechLib.SpVoiceClass      pp   = new SpeechLib.SpVoiceClass();
     SpeechLib.SpFileStreamClass spFs = new SpeechLib.SpFileStreamClass();
     spFs.Open(FileName, SpeechLib.SpeechStreamFileMode.SSFMOpenForRead, true);
     SpeechLib.ISpeechBaseStream Istream = spFs as SpeechLib.ISpeechBaseStream;
     pp.SpeakStream(Istream, SpeechLib.SpeechVoiceSpeakFlags.SVSFIsFilename);
     spFs.Close();
 }
Ejemplo n.º 2
0
        public static void NewRead(string content)
        {
            string       wavPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ring.wav";//要读的音频文件地址
            SpVoiceClass pp      = new SpeechLib.SpVoiceClass();

            SpeechLib.SpFileStreamClass spFs = new SpFileStreamClass();
            spFs.Open(wavPath, SpeechLib.SpeechStreamFileMode.SSFMOpenForRead, true);
            SpeechLib.ISpeechBaseStream Istream = spFs as SpeechLib.ISpeechBaseStream;
            //SoundPlayer soundPlayer = new SoundPlayer();
            //soundPlayer.SoundLocation = wavPath;
            //soundPlayer.Load();
            //soundPlayer.Play();
            SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice spVoice = new SpVoice(); //声源

            spVoice.Rate   = -5;             //速度
            spVoice.Volume = 100;
            //播放
            spVoice.SpeakStream(Istream, spFlags);
            spVoice.WaitUntilDone(-1);
            spVoice.Speak(content, spFlags);
            spFs.Close();
            //生成文件
            //try
            //{
            //    SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
            //    SpFileStream SpFileStream = new SpFileStream();
            //    SpFileStream.Open(@"C:\Users\EMEWE\Desktop\Test.wav", SpFileMode, false);
            //    spVoice.AudioOutputStream = SpFileStream;//设定voice的输出为Stream
            //    spVoice.Speak(txtContent.Text.Trim(), spFlags);
            //    spVoice.WaitUntilDone(Timeout.Infinite);//Using System.Threading;
            //    SpFileStream.Close();
            //    MessageBox.Show("生成成功!");
            //}
            //catch { MessageBox.Show("生成失败!"); }
        }