1. 第一步,需要三个dll
using System.Speech.Synthesis;
using System.Speech.Recognition;
using SpeechLib;
SpeechLib的导入有点不太好找,参考下图(图片排版不太好)
2.准备个测试demo
///获取计算机本身自带的语言系统
public static List<string> GetInstalledVoiceIdList()
{
List<string> resultList = new List<string>();
try
{
SpVoice voice = new SpVoice();
ISpeechObjectTokens ss = voice.GetVoices(string.Empty, string.Empty);
if (ss != null && ss.Count > 0)
{
for (int i = 0; i < ss.Count; i++)
{
resultList.Add(ss.Item(i).Id);
}
}
}
catch (Exception)
{
}
return resultList;
}
//指定语言Speak方法中第二个参数,指定语言,从上段代码中获取到中文系统的index 是3,所以将传递3进行阅读
voice.Speak(txt.Text, GetInstalledVoiceIdList()[3]);