SAPI 语音识别 Grammar的设置

应用程序可以利用SpSharedRecoContext接口创建不同的与语音识别引擎的连接。每一个连接都可以使用各自的事件并且使用不同的语音识别语法(grammars)。每一个基于SAPI语音识别的应用程序必须具有至少一个SpSharedRecoContext接口。 第一种方法: 自己定义Grammar using System;using System.Collections;
摘要由CSDN通过智能技术生成

应用程序可以利用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.SRATop

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 63
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 63
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值