Sapi 添加语法的文章(转载)
最近在做SAPI方面的工作,比较详细的中文资料不多,遇到各种问题,本来想着做完了项目总结一下,今天看到这篇文章,对于SAPI加载识别语法方面的描述十分详细,先转过来做个备份,谢谢原文博主:djyangmaowei,原文地址:http://blog.csdn.net/djyangmaowei/article/details/5384942
应用程序可以利用SpSharedRecoContext接口创建不同的与语音识别引擎的连接。每一个连接都可以使用各自的事件并且使用不同的语音识别语法(grammars)。每一个基于SAPI语音识别的应用程序必须具有至少一个SpSharedRecoContext接口。
第一种方法: 自己定义Grammar
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;
using SpeechLib;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
private SpeechLib.ISpeechGrammarRule menuRule = null;
private SpeechLib.SpSharedRecoContext objRecoContext;
private ISpeechRecoGrammar grammar;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// 得到一个RecoContext实例.
objRecoContext = new SpeechLib.SpSharedRecoContext();
// 指派一个事件给Hypothesis Event(中间层暂定的识别,即,初级的,临时的识别).
objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
// 指派一个事件给语音识别.
objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
//创建grammer实例.
grammar = objRecoContext.CreateGrammar(0);
label1.Text = "Speak Out one of the following./r/n1. 人民 2. 马克思 3. 孙中山 4. 恩格斯/r/n5. 杨茂巍 6. 王芳 7. 世界 8. 成都";
//激活菜单命令.
menuRule = grammar.Rules.Add("MenuCommands", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic, 1);
object PropValue = "";
menuRule.InitialState.AddWordTransition(null, "人民", " ", SpeechGrammarWordType.SGLexical, "人民", 1, ref PropValue, 1.0F);
menuRule.InitialState.AddWordTransition(null, "马克思", " ", SpeechGrammarWordType.SGLexical, "马克思", 2, ref PropValue, 1.0F);
menuRule.InitialState.AddWordTransition(null, "孙中山", " ", SpeechGrammarWordType.SGLexical, "孙中山", 3, ref PropValue, 1.0F);
menuRule.InitialState.AddWordTransition(null, "恩格斯", " ", SpeechGrammarWordType.SGLexical, "恩格斯", 4, ref PropValue, 1.0F);
menuRule.InitialState.AddWordTransition(null, "杨茂巍", " ", SpeechGrammarWordType.SGLexical, "杨茂巍", 5, ref PropValue, 1.0F);
menuRule.InitialState.AddWordTransition(null, "王芳 ", " ", SpeechGrammarWordType.SGLexical, "王芳 ", 6, ref PropValue, 1.0F);
menuRule.InitialState.AddWordTransition(null, "世界", " ", SpeechGrammarWordType.SGLexical, "世界", 7, ref PropValue, 1.0F);
menuRule.InitialState.AddWordTransition(null, "成都", " ", SpeechGrammarWordType.SGLexical, "成都", 8, ref PropValue, 1.0F);
grammar.Rules.Commit();
grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
}
private void Reco_Event(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
textBox1.Text = Result.PhraseInfo.GetText(0, -1, true);
}
private void Hypo_Event(int StreamNumber, object StreamPosition, ISpeechRecoResult Result)
{
textBox2.Text = Result.PhraseInfo.GetText(0, -1, true);
}
}
}
Sapi 添加语法的文章(转载)的更多相关文章
- 【前端】向blog或网站中添加语法高亮显示代码方法总结
向blog或网站中添加语法高亮显示的代码方法总结 文章目录 预备知识 目标 第一类方法:嵌入 第二类方法:外部引用 第三类方法:忽略HTML和PHP 最近在写代码时遇到一个问题,就是如何让代码像在ID ...
- 文章转载利用border、transparent实现微风
微风效果预览 微风源码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...
- 文章转载至CSDN社区罗升阳的安卓之旅,原文地址:
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6720261 前面我们在分析Activity启动 ...
- thymeleaf 添加语法提示
thymeleaf 添加语法提示: xmlns:th="http://www.thymeleaf.org"
- wordpress添加post_type自定义文章类型
wordpress很强大,能当博客也能进行二次开发出很完善的内容管理系统满足企业运营需求,比如可以添加products产品模型.汽车模型等,如何实现呢?添加post_type自定义文章类型就可以了 p ...
- 用 highlight.js 为文章中的代码添加语法高亮
来源:http://www.ghostchina.com/adding-syntax-highlighting-to-ghost-using-highlight-js/ --------------- ...
- Perl的基本语法<总结> (转载)
前言:这篇文章是花了我很多时间.费了我很多心血才完成的,虽然连我自己都觉得无法达到尽善尽美的境界,但希望能帮助大家入门,稍微了解到Perl 到底是个什么样的东西,Perl到底有那些强大的功能,那么这篇 ...
- Eclipse 如何添加 更换字体(转载)
1. 打开eclipse-->Window-->Preferences-->General-->appearance-->Colors and Fonts, 点开后选择B ...
- Android性能优化文章转载
今天看到几篇比较好的文章就转了!(链接如下) 转载注明出处:Sunzxyong Android性能优化之Bitmap的内存优化 Android性能优化之常见的内存泄漏 Android最佳实践之Syst ...
随机推荐
- linux的库文件
静态库和动态库 在windows中静态库是以 .lib 为后缀的文件,共享库是以.dll 为后缀的文件.在linux中静态库是以 .a 为后缀的文件,共享库是以 .so为后缀的文件. 以linux下的 ...
- nginx+php部署
(1) 下载并安装nginx mkdir nginx-src && cd nginx-src wget http://nginx.org/download/nginx-1.7.3.ta ...
- 一个类有两个方法,其中一个是同步的,另一个是非同步的; 现在又两个线程A和B,请问:当线程A访问此类的同步方法时,线程B是否能访问此类的非同步方法?
一个类有两个方法,其中一个是同步的,另一个是非同步的:现在又两个线程A和B,请问:当线程A访问此类的同步方法时,线程B是否能访问此类的非同步方法? 答案:可以 验证 package com.my.te ...
- Lumia 830 win10m 启用触摸按键
用了一年半的830疑似翘屏… 按键基本失灵 每次按的时候基本都是 appbar 那里有反映… 实在懒于换手机(主要是不想花钱…) 研究下怎么启用虚拟按键,还能再战几年… 启用虚拟按键 其实简单说法就是 ...
- ArcGIS与SuperMap的使用比较(1)
用了超过6年的超图产品了,因此对超图的很多特性比较熟悉,去年开始接触ARCGIS,并用来研发了一些新产品,因此对于两个GIS平台有些感受,记录如下: 比较版本:ARCGIS10.1与SuperMap ...
- c#列举和迭代器
列举 - Enumeration 迭代器是一个值序列(集合)上的一个只读且只向前移动的游标.迭代器要么实现了IEnumerator接口,要么实现了IEnumerator<T>接口. 从技术 ...
- C# 调用系统winmm.dll 播放音乐wav mp3
using System.Runtime.InteropServices;//放wav public partial class frmMain : Form { 系统放 播放音乐 wav mp3 [ ...
- iOS10 CoreData新特性
原文地址:What's New in Core Data in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0 翻译者:肖品,原创文章转载请著名出处 ...
- PLSQL登录弹出空白框如何解决
转自:http://jingyan.baidu.com/article/066074d6760959c3c21cb0d6.html 出现登录弹出空白框这是由于win7的安全性提高了,在PLSQL ...
- C# WinForm RDLC报表不预览直接连续打印
用微软的RDLC报表直接打印不预览 直接上代码. //打印清单 System.Data.DataTable dt = print_QD(dr); ReportViewer rvDoc = new Re ...