废话少说,看代码精解,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Globalization;
using System.Windows.Forms;
namespace yincheng01@163.com
{
public class yuyin
{
public SpeechRecognitionEngine recognizer = null;
public DictationGrammar dictationGrammar = null;
public System.Windows.Forms.Control cDisplay;
public yuyin(string[] fg)//创建关键词语列表
{
CultureInfo myCIintl = new CultureInfo("zh-CN", false);
foreach (RecognizerInfo config in SpeechRecognitionEngine.InstalledRecognizers())//获取所有语音引擎
{
if (config.Culture.Equals(myCIintl) && config.Id == "MS-2052-80-DESK")//选择中文
{
recognizer = new SpeechRecognitionEngine(config);
break;
}
}
if (recognizer != null)
{
InitializeSpeechRecognitionEngine(fg);
dictationGrammar = new DictationGrammar();
}
else
{
MessageBox.Show("创建语音识别失败");
}
}
private void InitializeSpeechRecognitionEngine(string[] fg)
{
recognizer.SetInputToDefaultAudioDevice();
Grammar customGrammar = CreateCustomGrammar(fg);
recognizer.UnloadAllGrammars();
recognizer.LoadGrammar(customGrammar);
recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
recognizer.SpeechHypothesized += new EventHandler<SpeechHypothesizedEventArgs>(recognizer_SpeechHypothesized);
}
public void BeginRec(Control tbResult)//关联窗口控件
{
TurnSpeechRecognitionOn();
TurnDictationOn();
cDisplay = tbResult;
}
public void over()
{
TurnSpeechRecognitionOff();
}
public virtual Grammar CreateCustomGrammar(string[] fg)
{
GrammarBuilder grammarBuilder = new GrammarBuilder();
grammarBuilder.Append(new Choices(fg));
return new Grammar(grammarBuilder);
}
private void TurnSpeechRecognitionOn()
{
if (recognizer != null)
{
recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
else
{
MessageBox.Show("创建语音识别失败");
}
}
private void TurnSpeechRecognitionOff()
{
if (recognizer != null)
{
recognizer.RecognizeAsyncStop();
TurnDictationOff();
}
else
{
MessageBox.Show("创建语音识别失败");
}
}
private void recognizer_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
{
}
private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string text = e.Result.Text;
cDisplay.Text = text;
}
private void TurnDictationOn()
{
if (recognizer != null)
{
recognizer.LoadGrammar(dictationGrammar);
}
else
{
MessageBox.Show("创建语音识别失败");
}
}
private void TurnDictationOff()
{
if (dictationGrammar != null)
{
recognizer.UnloadGrammar(dictationGrammar);
}
else
{
MessageBox.Show("创建语音识别失败");
}
}
}
}
类的调用
string[] fg = {“东方”,“西方”,“南方”,“北方” };
qqq = new yuyin(fg);
qqq.BeginRec(textBox10); 显示识别的信息的控件
需要源码的请留下EMAIL
分享到:
相关推荐
c#3.0入门经典教程 c#3.0入门 c#3.0
基于windows语音识别案例
微软官方的c#3.0规范完全版,原来发的是c#3.0的新特征版本!
C# 3.0 Design Patterns.PDF
C# 3.0与.NET 3.5高级编程.rar 免积分 非扫描版
C# 3.0 完全参考手册 C# 3.0 完全参考手册
c#3.0中英文.相当好的学习资料
虹软人脸识别的代码c#版本,有需要的可以下载
这是微软官方版的C#3.0的语言规范和教程,微软是以word的文件格式发布的,我转成了清晰版的PDF格式,还加了很详细的标签,想了解的不要错过。
本书为那些充满奥秘的设计模式提供了有效的C#3.0实现。” 如果想加速.NET应用程序的开发,你就需要本书,它是解决常见编程问题的优雅的、公认的和被证明为有效的处理方式的合集。本书条理清晰地介绍了经典的面向...
C# 开发的离线语音识别,语音转文字,可以识别短语音,指定识别库,程序已测试运行成功,识别速度快,需要的可以自行修改使用
C#3.0,在短短几年中,微软就对C#进行了两次大的升级,为C#加入了许多新的特性,从而使C#变得更加强大也更加现代了
C#3.0一些新语法!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
C#3.0 in a nutshell
cmpp3.0 c#开发源码 测试通过
源码描述: 一、菜单功能 1、实现C# 调用科大讯飞语音识别和语音合成API 2、实现基本的语音识别和语音播报 二、注意事项 1、开发环境为Visual Studio 2012,无数据库,使用.net 4.0开发。
精通C#3.0与.net3.5高级编程 实例下载
C#3.0中自动属性,新的对象初始化器,新的集合初始化器,扩展方法,推断类型等属性的总节。