『QQ:1353814576』

C# 如何通过系统组件实现输入一段文字程序转换成语音朗读出来?


C# 调用System.Speech.Synthesis 实现文本朗读

之前一份工作做客户端软件语音提示功能需求有用到过

引用命名空间 using System.Speech.Synthesis;

测试环境Windows7、Windows10

部分绿色版系统(部分系统组件被人为删除)下运行报错 可能需要修复TTS语音组件模块

public class TTS 
{
    SpeechSynthesizer Speecher = new SpeechSynthesizer();
	
     //异步不阻塞播放
     public void SpeakAsync(string text){

         Speecher.Rate = -1;
         Speecher.SpeakAsync(text);
     }

     //同步阻塞朗读
     public void Speak(string text){

         Speecher.Rate = -1;
         Speecher.Speak(text);
     }
}