C# 使用System.Speech 进行语音播报和识别
C# 使用System.Speech 进行语音播报和识别
using System.Speech.Synthesis;
using System.Speech.Recognition; //语音识别
SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine();
SpeechSynthesizer speech = new SpeechSynthesizer(); //**************************使用System.Speech 制作文字转换成声音的程序*******************************
//rate: 范围为:-10~10;
//volume: 范围为:0~100;
//speektext: 待转换声音的文字
public void SpeechVideo_Read(int rate, int volume, string speektext) //读
{
speech.Rate = rate;
speech.Volume = volume;
speech.SpeakAsync(speektext);
} public void SpeechVideo_Record(int rate, int volume, string recordtext) //录音
{
SpeechSynthesizer speech = new SpeechSynthesizer();
speech.Rate = rate;
speech.Volume = volume;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "文本文件(*.wav)|*.wav|所有文件(*.*)|*.*";
//设置默认文件类型显示顺序
sfd.FilterIndex = ;
//保存对话框是否记忆上次打开的目录
sfd.RestoreDirectory = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
string localfilepath = sfd.FileName.ToString();
speech.SetOutputToWaveFile(localfilepath);
speech.Speak(recordtext);
speech.SetOutputToDefaultAudioDevice();
MessageBox.Show("完成录音!", "提示");
}
} public void SpeechVideo_Pause() //暂停
{
speech.Pause();
} public void SpeechVideo_Contine() //暂停后继续
{
speech.Resume();
}
//**************************************结束******************************************************** //*****************************************使用System.Speech 制作语音识别程序***********************
//rate: 范围为:-10~10;
//volume: 范围为:0~100;
//speektext: 待转换声音的文字
public void recEngine_Speech_RecordCheck() //读
{
Choices preCmd = new Choices();
preCmd.Add(new string[] { "name", "age" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(preCmd);
Grammar gr = new Grammar(gb);
recEngine.LoadGrammarAsync(gr);
recEngine.SetInputToDefaultAudioDevice();
recEngine.RecognizeAsync(RecognizeMode.Multiple);
recEngine.SpeechRecognized += recEngine_SpeechRecognized;
} public void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
switch (e.Result.Text)
{
case "name":
MessageBox.Show("wangjin");
break;
case "age":
MessageBox.Show("");
break;
}
} //**************************************结束****************************************************//
C# 使用System.Speech 进行语音播报和识别的更多相关文章
- asp.net引用System.Speech实现语音提示
using System; using System.Speech.Synthesis; namespace testvoice { class Program { static void Main( ...
- C# 使用微软自带的Speech进行语音输出
1.在VS中使用微软自带的Speech进行语音播报,首先需要添加引用: 2.具体实现逻辑代码如下:
- jQuery.speech实现文本转语音播报功能
先放一个实例的地址https://github.com/wenco/speech jQuery.speech是用jQuery写的扩展插件,主要是用来语音播报. 接口调用百度翻译的接口,所以存在url参 ...
- Speech语音播报
System.Speech 这个命名空间,报可以阅读文字和播放音频. 环境 W10 VS2017 CMMT 1.添加程序集引用 System.Speech 2.实例化播音类,并且播放一个文本 Spe ...
- SpeechLib 语音播报
SpeechLib这的dll专门用来播放语音,能够识别英语.简体和繁体.并且可以播放声音文件,支持WAV格式,但不支持MP3.在报警场合下已经够用了. 基本播放语音及文件.支持异步. using Sy ...
- Android 简单的语音播报
不解释快上车 Main.class package com.example.myapp; import android.app.AlertDialog;import android.os.Bundle ...
- System.Speech.Synthesis 添加暂停、继续功能
为了方便调用暂停.继续的方法.要将speech的功能写成一个类.直接附上代码: using System; using System.Collections.Generic; using System ...
- 【C#】语音识别 - System.Speech
一个有趣的东西,今后可能用得上. C#语音识别:在命名空间 System.Speech下SpeechSynthesizer可以将文字转换成语音 贴出代码: public partial class F ...
- iOS10 语音播报填坑详解(解决串行播报中断问题)
iOS10 语音播报填坑详解(解决串行播报中断问题) 在来聊这类需求的解决方案之前,咱们还是先来聊一聊这类需求的真实使用场景:语音播报.语音播报需求运用最为广泛的应该是收银对账了,就类似于支付宝.微信 ...
随机推荐
- Monkey测试简介
1.Monkey测试简介monkey是安卓命令行工具,它向系统发送伪随机的用户事件,例如:按键的输入.触摸屏的输入.手势输入等操作来对设备上的程序进行压力测试,检测程序多久的时间会发生异常.因此,mo ...
- cobbler登录web界面时出现“Internal Server Error”
当进行cobbler配置后,并进行web登录时,出现错误: 先查看其日志位置 #cat /etc/httpd/conf.d/ssl.conf 在其中位置发现其错误的日志位置为/etc/httpd/lo ...
- python学习 生成随机函数 random模块的用法
random模块是用于生成随机数 常用函数 函数 含义 random() 生成一个[0,1.0)之间的随机浮点数 uniform(a,b) 生成一个a到b之间的随机浮点数 randint(a,b) 生 ...
- logstash 切分tomcat日志
以下配置是logstash切分tomcat catalina.out日志. http://grok.qiexun.net/ 分割时先用这个网站测试下语句对不对,能不能按需切割日志. input { ...
- linux下打压缩解压
tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...
- MAC vim安装gruvbox主题
gruvbox是一款优秀的vim配色方案,但是却不是vim自带的配色方案,这里记录一下安装过程. gruvbox官网:https://github.com/morhetz/gruvbox gruvbo ...
- easyui-textbox多行文本中输入内容,有回车操作时将文本拼接<br/>
<input class="easyui-textbox" name="versionText" id="versionText" d ...
- ajax原生实现
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- MVC过滤器使用方法
先介绍下什么是过滤器:ASP.NET MVC中的灭一个请求,都会分配给相应的控制器和对应的行为方法去处理,而在这些处理的前前后后如果想再加一些额外的逻辑处理,这时就用到了过滤器. MVC支持的过滤器有 ...
- Codeforces Round #436 C. Bus
题意:一辆车在一条路上行驶,给你路的总长度a,油箱的容量b,加油站在距离起点的距离f,以及需要走多少遍这条路k(注意:不是往返) 问你最少加多少次油能走完. Examples Input 6 9 2 ...