C#朗读语音

     最近有个需求,需要在C#程序发生异常时候,朗读文字,C#提供了.net framework可以提供简单的语音朗读功能。

引入依赖

using System.Media;
using System.Speech.Synthesis;
using System.Runtime.InteropServices;

//报警音量
SystemSounds.Exclamation.Play();
//设置阅读
SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
//音量
speechSynthesizer.Volume = 100;
//倍速
speechSynthesizer.Rate = 2;
//阅读
speechSynthesizer.SpeakAsync(message)