static class Program
{
static SpeechSynthesizer speech = new SpeechSynthesizer();
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
speak("欢迎使用本系统");
Application.Run(new Form1());
}
/// <summary>
/// 语音播报
/// </summary>
/// <param name="msg"></param>
public static void speak(string msg)
{
speech.SpeakAsyncCancelAll();//停止没有播放完成的语音
speech.SpeakAsync(msg);//播放语音
}
}
c# 语音播报(两行代码实现) 如需在.net core 下使用需去nuget 下安装System.Speech包
于 2022-07-08 16:46:39 首次发布