c#实现语音阅读以及文本转语音文件是基于c#的一个类库(SpeechSynthesizer )实现的
1.添加引用:
使用该类必须要添加引用using System.Speech.Synthesis
直接是无法添加引用的,先对项目进行添加引用
2.语音朗读
SpeechSynthesizer synth = new SpeechSynthesizer();
美式发音,但只能读英文:synth.SelectVoice(“Microsoft Anna”);
能读中英文:synth.SelectVoice(“Microsoft Lili”);
synth.Speak(str);
3.语音识别
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
using System;
using System.Speech.Synthesis; //用于语音朗读
using System.Speech.Recognition;//用于识别语音
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("请输入中英文:");
string s = Console.ReadLine();
SpeechSynthesizer synth = new SpeechSynthesizer();
//选择不同的发音
//synth.SelectVoice("Microsoft Anna");//美式发音,但只能读英文
synth.SelectVoice("Microsoft Lili");//能读中英文
synth.Speak(s);
}
//语音识别
//SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
}
}
}