用C#播放声音文件

为了系统人性话,更加智能,有时候需要一些声音辅助系统
下面这个例子可以播放指定音频文件,而且还可以读字符串:

/// <summary>

        /// 播放声音文件

        /// </summary>

        /// <param name="FileName">文件全名</param>

        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();

        }
posted @ 2009-05-18 23:50  龙仪  阅读(364)  评论(0编辑  收藏  举报