废话少说看代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpeechLib;
using System.Windows.Forms;
using System.Collections;
namespace yincheng01@163.com
{
public class speechxp
{
private SpeechLib.SpSharedRecoContext objRecoContext;
private SpeechLib.ISpeechRecoGrammar grammar;
private SpeechLib.ISpeechGrammarRule rule = null;
private SpeechLib.ISpeechGrammarRuleState state;
private SpeechLib.ISpeechPhraseElement PhraseElem;
public System.Windows.Forms.Control cDisplay;
public speechxp(string FileName, Control cDisplay)
{
}
private void initSAPI()
{
try
{
objRecoContext = new SpeechLib.SpSharedRecoContext();
objRecoContext.AudioLevel += new _ISpeechRecoContextEvents_AudioLevelEventHandler(RecoContext_VUMeter);//设置声音事件的响应函数
objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);//设置成功识别事件的响应函数
objRecoContext.EventInterests = SpeechLib.SpeechRecoEvents.SRERecognition | SpeechLib.SpeechRecoEvents.SREAudioLevel;//设置响应事件
//create grammar interface with ID = 0
grammar = objRecoContext.CreateGrammar(1);//语法的实例
}
catch (Exception ex)
{
MessageBox.Show("Exception /n" + ex.ToString(), "Error - initSAPI");
}
}
private void SAPIGrammarFromFile(string FileName)
{
try
{
grammar.CmdLoadFromFile(FileName, SpeechLib.SpeechLoadOption.SLODynamic);
grammar.CmdSetRuleIdState(0, SpeechRuleState.SGDSActive);
}
catch
{
MessageBox.Show("载入语法文件失败 " + FileName + "/n", "Error - SAPIGrammarFromFile");
}
}
public void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult e)
{
int i;
ArrayList reco = new ArrayList();
string phrase = e.PhraseInfo.GetText(0, -1, true);
cDisplay.Text = e.PhraseInfo.GetText(0, -1, true);
foreach (SpeechLib.ISpeechPhraseElement PhraseElem in e.PhraseInfo.Elements)
{
/// listBox1.Items.Add(PhraseElem.Pronunciation);添加语音指令
}
i = e.PhraseInfo.Elements.Count;
for (int h = 0; h < i; h++)
{
}
}
public void RecoContext_VUMeter(int StreamNumber, object StreamPosition, int e)
{
int hg = e;
}
}
}
类的调用
hhh = new SpRecognition(file); 定义好的语法XML文件
hhh.BeginRec(textBox10); 关联到显示识别结果的控件
分享到:
相关推荐
c#3.0入门经典教程 c#3.0入门 c#3.0
基于windows语音识别案例
华为短信网关平台、中兴短信网关平台,根据两大主流平台提供的接入信息封装接口,里面包含有一下文件:SMGPLoginRespMessage.java,SMGPLoginMessage.java,SGIPConnection.java,CMPP30Connection.java,CMPP30...
微软官方的c#3.0规范完全版,原来发的是c#3.0的新特征版本!
C# 3.0 Design Patterns.PDF
虹软人脸识别的代码c#版本,有需要的可以下载
c#3.0中英文.相当好的学习资料
C# 3.0 完全参考手册 C# 3.0 完全参考手册
cmpp3.0 c#开发源码 测试通过
这是微软官方版的C#3.0的语言规范和教程,微软是以word的文件格式发布的,我转成了清晰版的PDF格式,还加了很详细的标签,想了解的不要错过。
本书为那些充满奥秘的设计模式提供了有效的C#3.0实现。” 如果想加速.NET应用程序的开发,你就需要本书,它是解决常见编程问题的优雅的、公认的和被证明为有效的处理方式的合集。本书条理清晰地介绍了经典的面向...
C# 3.0与.NET 3.5高级编程.rar 免积分 非扫描版
c#语音识别及朗读系统_(基于speechSDK开发)(Winform) IDE vs2015
C#3.0一些新语法!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
C#3.0 in a nutshell
C#3.0,在短短几年中,微软就对C#进行了两次大的升级,为C#加入了许多新的特性,从而使C#变得更加强大也更加现代了
C#3.0中自动属性,新的对象初始化器,新的集合初始化器,扩展方法,推断类型等属性的总节。
cmpp3.0开发接口c# 有问题 www.willvc.com.cn 能联系到我