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 语音播报填坑详解(解决串行播报中断问题) 在来聊这类需求的解决方案之前,咱们还是先来聊一聊这类需求的真实使用场景:语音播报.语音播报需求运用最为广泛的应该是收银对账了,就类似于支付宝.微信 ...
随机推荐
- 服务器还原阿里云Mysql数据库
https://www.percona.com/doc/percona-xtrabackup/2.3/installation/yum_repo.html
- C++的ch1&ch2的整理
C++:带泪的C,意指学C语言的时候没有好好学,在学习此门课时会流下不学无术的泪水(仅对于我个人). 计算机程序语言的发展:机器语言[计算机可以识别的二进制指令]——>汇编语言[将机器指令转化为 ...
- 关于Eclipse for Python
学习Python一段时间,一直用Python的IDE进行开发,过程蛮顺利,但是,基于Visual Studio的使用经验,就希望尝试一种更友好的,更方便管理项目的IDE,分别尝试了PyCharm和Ec ...
- list.sort和内置方法sorted的区别
1.list.sort会直接修改list,不会把原来的列表复制一份,直接修改list,所以list.sort的返回值为None; 2.sorted(list)的返回值就修改之后的list,原来的lis ...
- c++ 使用模板按类型统计stl多维容器中元素的数量
struct ItemCounter{template<typename T1, typename T2, typename = typename std::enable_if<!std: ...
- 第一周pta作业1总结
查找整数 本题要求从输入的N个整数中查找给定的X.如果找到,输出X的位置(从0开始数):如果没有找到,输出"Not Found". 输入格式: 输入在第一行中给出两个正整数N(≤2 ...
- js----点击事件三种方法
在javascript中,可以为某个元素指定事件,指定的方式有以下三种: 1.在html中,使用onclick属性 2.在javascript中,使用onclick属性 (1)注意函数名没有双引号. ...
- 复杂JSON对象的查询与合并
一个表里存放了全国各地地区.省.市.县区的数据,为了提高加载速度我保存成了本地的JSON文件 结构大致如下: [{ "text": "中华人民共和国", &qu ...
- PhoenixFD插件流体模拟——UI布局【Export】详解
Liquid Export 流体导出 本文主要讲解Export折叠栏中的内容.原文地址:https://docs.chaosgroup.com/display/PHX3MAX/Liquid+Expor ...
- cnpm install -g live-server 安装服务
cnpm install -g live-server 指令会在浏览器自动打开页面