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 进行语音播报和识别的更多相关文章

  1. asp.net引用System.Speech实现语音提示

    using System; using System.Speech.Synthesis; namespace testvoice { class Program { static void Main( ...

  2. C# 使用微软自带的Speech进行语音输出

    1.在VS中使用微软自带的Speech进行语音播报,首先需要添加引用: 2.具体实现逻辑代码如下:

  3. jQuery.speech实现文本转语音播报功能

    先放一个实例的地址https://github.com/wenco/speech jQuery.speech是用jQuery写的扩展插件,主要是用来语音播报. 接口调用百度翻译的接口,所以存在url参 ...

  4. Speech语音播报

    System.Speech 这个命名空间,报可以阅读文字和播放音频. 环境  W10 VS2017 CMMT 1.添加程序集引用 System.Speech 2.实例化播音类,并且播放一个文本 Spe ...

  5. SpeechLib 语音播报

    SpeechLib这的dll专门用来播放语音,能够识别英语.简体和繁体.并且可以播放声音文件,支持WAV格式,但不支持MP3.在报警场合下已经够用了. 基本播放语音及文件.支持异步. using Sy ...

  6. Android 简单的语音播报

    不解释快上车 Main.class package com.example.myapp; import android.app.AlertDialog;import android.os.Bundle ...

  7. System.Speech.Synthesis 添加暂停、继续功能

    为了方便调用暂停.继续的方法.要将speech的功能写成一个类.直接附上代码: using System; using System.Collections.Generic; using System ...

  8. 【C#】语音识别 - System.Speech

    一个有趣的东西,今后可能用得上. C#语音识别:在命名空间 System.Speech下SpeechSynthesizer可以将文字转换成语音 贴出代码: public partial class F ...

  9. iOS10 语音播报填坑详解(解决串行播报中断问题)

    iOS10 语音播报填坑详解(解决串行播报中断问题) 在来聊这类需求的解决方案之前,咱们还是先来聊一聊这类需求的真实使用场景:语音播报.语音播报需求运用最为广泛的应该是收银对账了,就类似于支付宝.微信 ...

随机推荐

  1. Webpack 使用url-loader和file-loader打包资源文件

    在js中不仅可以通过import引入js文件,还可以引入图片.视频等资源文件,这样webpack打包时就会把所引入的资源文件也一起打包进来 打包进来的文件会返回一个字符串:即文件的路径 要做到这一点, ...

  2. 43_redux_counter应用_使用redux调试用具

    1.要在chrome中安装插件 redux-devtools_2_12_1.crx 2.在开发工具注入 npm install --save-dev redux-devtools-extension ...

  3. Neural Network Virtual Machine

    深度学习Stack 为什么提出NNVM? 深度学习框架现状 - “碎片化” 目前,深度学习应用框架呈现出高度的“碎片化(fragmentation)”倾向,这主要是由于下述两个原因: 1. 深度学习正 ...

  4. vue实例

    <!--需求: 背景图片,进度条,减和重置按钮 进度条填满红色,值为100%,点击减时,进度条依次减十,减到0时换一张背景图片,减按钮消失,点击重置按钮时,进度条重新填满红色-->效果图: ...

  5. react 路由之react-router-dom

    1安装react-router-dom npm install react-router-dom --save-dev //这里可以使用cnpm代替npm命令 1 新建router文件 //引入 re ...

  6. liteUploader上传控件的封装使用

    //原来的绑定方式 $('#' + frm_name).liteUploader({ script: url, params: { type: "image", size: siz ...

  7. cordova/ionic打包流程

    ionic android 手工打包指令手册 [工作平台要求] 安装 node.js.cordova.ionic(非必须) 等前端相关软件与组件(1)安装 Java-SDK,正确配置系统环境变量 JA ...

  8. 定时器&改变定时器的执行频率

    static System.Threading.Timer timer; static void Main(string[] args) { Console.WriteLine("Press ...

  9. 微信小程序-if条件渲染

    #index.wxml <view>今天吃啥</view> <view wx:if="{{condition==1}}"> 饺子 </vi ...

  10. Dubbo 的配置主要分为三大类

    服务发现.服务治理和性能调优:这三类配置不是独立存在的,而是贯穿在所有配置项中的,比如dubbo:service 标签中的interface 是服务发现类, timeout是性能调优类, mock 是 ...