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. 1.Sed | Awk | Grep | Find

    1.Sed | Awk | Grep | Find 可以参考的文档链接 CentOS7 查看 当前机器 已经启动的端口的Shell命令: netstat -lntup | awk -F' ' {'pr ...

  2. Spark环境搭建

    转载:https://blog.csdn.net/songhaifengshuaige/article/details/79480491

  3. LR常用函数

    web_set_max_html_param_len()--常用函数 设置可检索并保存为参数的任何HTML字符串的最大长度. intweb_set_max_html_param_len(const c ...

  4. IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 Industry Track Call for Papers

    IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...

  5. python 二叉树实现带括号的四则运算

    #!/usr/bin/python #* encoding=utf-8 s = "20-5*(0+1)*5^(6-2^2)" c = 0 top = [0,s[c],0] op = ...

  6. SpringCloud-day06-Ribbon负载均衡

    6.3.Ribbon负载均衡 为了实现真正的负载均衡,我们需要集群3个服务提供给者,而在这之前我们只有一个服务提供者1001,那么我们新建模块microservice-station-provider ...

  7. dubbo协议报文格式

  8. 【java】多个对象的序列化和反序列化

    当我们需要序列化多个对象的时候,可以采用集合把多个对象放到集合中,然后序列化整个集合. 而我们要反序列化的时候,就使用集合接收反序列化后的对象 如: List<Student> stude ...

  9. checkbox、radio控件和文字不对齐

    一般使用html控件的时候  单选按钮和复选框的控件和文字不对齐 给input控件加上   style="vertical-align: middle; margin-top: -2px; ...

  10. leetcode 动态规划类型题

    1,Triangle int mininumTotal(vector<vector<int>>& triangle) { ; i >= ; --i) { ; j ...