c# 文字朗读 播放声音

 win10系统测试通过

 

 第一种方法,最简单

  private static  dynamic _comTts;
        Type type = Type.GetTypeFromProgID("SAPI.SpVoice");
        private void Read(string text)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    _comTts = Activator.CreateInstance(type);
                    _comTts.Speak(text);
                }
                catch{}
            });

        }

  第二种方法

要引用 using System.Speech.Synthesis;

            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SetOutputToDefaultAudioDevice();
            synth.Speak("欢迎使用");

 

posted @ 2020-03-29 20:19  simadi  阅读(790)  评论(0编辑  收藏  举报