我写你读
输入一段string然后Cortana会把输入的string读出来
准备工作
添加语音
win10在设置找到安装的语音包,确然电脑上安装了语音包。要确认安装了语音包哦。
开始工作
- 创建c#控制台程序。
- 在引用中添加
添加Speed的引用,声音主要是这个输入。
- 添加命名空间
using System.Speech.Synthesis;//声音播放
- 然后拷贝下面的代码
var i = Console.ReadLine();
SpeechSynthesizer speech = new SpeechSynthesizer();
speech.Rate = 1;
speech.Volume = 100;
speech.SelectVoice("Microsoft Huihui Desktop");//设置中文
speech.Speak(i);
拷贝到Main函数中。
然后解释一下
SpeechSynthesizer speech = new SpeechSynthesizer();//一个对象,干嘛的不知道。
speech.Rate = 1;//语速
speech.Volume = 100;//声音大小
speech.SelectVoice("Microsoft Huihui Desktop");//设置读写的语音
speech.Speak(i);//读出来,
其他的东西
如何查看安装的语音?
可以在控制台查看到已经安装的语音。
speech.GetInstalledVoices();
上面就是安装的语音,如果想换语音可以更改
speech.SelectVoice("Microsoft Huihui Desktop");
修改为对应的语音名称即可。