您的位置:首页 > 编程语言 > C#

C#使用System.Speech制作语音提示功能

2018-03-29 12:11 676 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐