SoundHelper
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Speech.Synthesis; namespace xiaoy.Comm { public class SoundHelper { /// <summary> /// 默认音量[0,100] /// </summary> public static int DefaultVolume = 100; /// <summary> /// 默认音速[-10,10] /// </summary> public static int DefaultRate = 1; /// <summary> /// 播报语音 使用默认语速音量 /// </summary> /// <param name="msg">播报内容</param> public static void Speek(string msg) { Speek(msg, DefaultRate, DefaultVolume); } /// <summary> /// 播报语音 /// </summary> /// <param name="msg">播报内容</param> /// <param name="rate">语速,[-10,10] </param> /// <param name="volume">音量,[0,100]</param> public static void Speek(string msg, int rate, int volume) { SpeechSynthesizer voice = new SpeechSynthesizer(); //创建语音实例 voice.Rate = rate; //设置语速,[-10,10] voice.Volume = volume; //设置音量,[0,100] voice.Speak(msg); //播放指定的字符串,异步朗读 } } }
-----------------------------------------------------------------

浙公网安备 33010602011771号