C#基于Microsoft Speech SDK Version 5.1 的开发

   
            //Microsoft Speech SDK Version 5.1
            #endregion
            private SpeechLib.SpSharedRecoContext objRecoContext = null;

            #region ISpeechRecoGrammar说明
            //The ISpeechRecoGrammar automation interface enables applications to manage the words and phrases for the SR engine.
            //为语音识别引擎自动管理应用程序单词和短语
            /*       
            属性
            Id Property Returns                     the Id assigned to the grammar when it was created.
            RecoContext Property                    Returns the RecoContext object that created this grammar.
            Rules Property                          Returns the collection of grammar rules in the RecoGrammar.
            State Property                          Gets and sets the operational status of the speech grammar.

            方法
            CmdLoadFromFile Method                  Loads a command and control grammar from the specified file.
            CmdLoadFromMemory Method                Loads a compiled speech grammar from memory.
            CmdLoadFromObject Method                Loads a speech grammar from a COM object.
            CmdLoadFromProprietaryGrammar Method    Loads a proprietary speech grammar.
            CmdLoadFromResource Method              Loads a command and control grammar from a Win32 resource.
            CmdSetRuleIdState Method                Activates or deactivates a rule by its rule ID.
            CmdSetRuleState Method                  Activates or deactivates a rule by its rule name.
            DictationLoad Method                    Loads a dictation topic into the grammar.
            DictationSetState Method                Sets the dictation topic state.
            DictationUnload Method                  Unloads the active dictation topic from the grammar.
            IsPronounceable Method                  Determines if a word has a pronunciation.
            Reset Method                            Clears all grammar rules and resets the grammar's language to NewLanguage.
            SetTextSelection Method                 Sets the range of text selection information in a word sequence data buffer.
            SetWordSequenceData Method              Defines a word sequence data buffer for use by the SR engine.
             */
            #endregion
            private SpeechLib.ISpeechRecoGrammar grammar = null;

            #region ISpeechGrammarRule说明
            //The ISpeechGrammarRule automation interface defines the properties and methods of a speech grammar rule
            //自动定义语音属性和方法的接口
            /*        
            属性
            Attributes Property                     Returns information about the attributes of a speech grammar rule.
            Id Property                             Specifies the ID of the speech grammar rule.
            InitialState Property                   Specifies the initial state of the speech grammar rule.
            Name Property                           Specifies the name of the speech grammar rule.

            方法
            AddResource Method                      Adds a string to a speech rule.
            AddState Method                         Adds a state to a speech rule.
            Clear Method                            Clears a rule, leaving only its initial state.
             */
            #endregion
            private SpeechLib.ISpeechGrammarRule menuRule = null;

        #endregion

        private void cmdEnable_Click(object sender, System.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);
   
   label3.Text = "Speak Out one of the follwoing./r/n1. New 2. Open 3. Close 4. Exit/r/n5. Cut 6. Copy 7. Paste 8. Delete";

   //激活菜单命令.   
   menuRule = grammar.Rules.Add("MenuCommands",SpeechRuleAttributes.SRATopLevel|SpeechRuleAttributes.SRADynamic,1);

   object      PropValue = "";
   menuRule.InitialState.AddWordTransition(null,"New"," ",SpeechGrammarWordType.SGLexical,"New", 1, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Open"," ",SpeechGrammarWordType.SGLexical,"Open", 2, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Close"," ",SpeechGrammarWordType.SGLexical,"Close",3, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Exit"," ",SpeechGrammarWordType.SGLexical,"Exit",4, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Cut"," ",SpeechGrammarWordType.SGLexical,"Cut",5, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Copy"," ",SpeechGrammarWordType.SGLexical,"Copy",6, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Paste"," ",SpeechGrammarWordType.SGLexical,"Paste",7, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Delete"," ",SpeechGrammarWordType.SGLexical,"Delete",8, ref PropValue, 1.0F );

   grammar.Rules.Commit();
   grammar.CmdSetRuleState("MenuCommands", SpeechRuleState.SGDSActive);
        }

        #region 初级和正式的语音识别事件处理

        private void Reco_Event(int StreamNumber, object StreamPosition,SpeechRecognitionType RecognitionType,ISpeechRecoResult Result)
  {
   txtReco.Text = Result.PhraseInfo.GetText(0, -1, true);
        }

        private void Hypo_Event(int StreamNumber, object StreamPosition, ISpeechRecoResult Result)
  {
   txtHyp.Text = Result.PhraseInfo.GetText(0, -1, true);

  }

        #endregion

        #region 清空控件和使关闭语音识别

        private void cmdDiable_Click(object sender, System.EventArgs e)
  {
            ClearControls(label3, objRecoContext);
        }

        #endregion

        #region 自定义函数

        /// <summary>
        /// 清空数据
        /// </summary>
        /// <param name="args">需要清空的变量及控件</param>
        public void ClearControls(params object[] args)
        {
            foreach (object obj in args)
            {
                if (obj is TextBox)
                {
                    TextBox t = (TextBox)obj;
                    t.Text = "";
                }
                if (obj is ListBox)
                {
                    ListBox l = (ListBox)obj;
                    l.Items.Clear();
                }
                if (obj is Label)
                {
                    Label l = (Label)obj;
                    l.Text = "";
                }
                if (obj is SpeechLib.SpSharedRecoContext)
                {
                    SpeechLib.SpSharedRecoContext s = (SpeechLib.SpSharedRecoContext)obj;
                    s = null;
                }
            }
        }

        #endregion
    }
}


原文链接: http://blog.csdn.net/yincheng01/article/details/4545698

转载于:https://my.oschina.net/junwong/blog/48104

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Microsoft Speech SDK是微软公司开发的语音识别和语音合成软件开发工具包。它提供了一系列API和工具,使开发人员能够轻松地将语音识别和语音合成功能集成到他们的应用程序中。该SDK支持多种语言和操作系统,包括Windows、Android和iOS等。它可以用于开发各种语音应用程序,如语音助手、语音识别输入、语音控制等。 ### 回答2: Microsoft Speech SDKMicrosoft 公司开发的一套语音技术开发工具包,主要用于帮助开发者添加语音识别、语音合成、音频输入及输出等功能。作为一套强大而全面的语音技术开发工具包,它可以极大地便捷开发者构建语音应用程序,例如语音识别软件、语音助手、语音导航、语音翻译、语音评测等。 在语音识别方面,Microsoft Speech SDK 支持多种语言和语音模型,包括英语、中文、法语、西班牙语等。开发者可以通过简单的 API 调用实现对语音的识别,并可以通过调整配置文件来优化识别效果。在语音合成方面,Microsoft Speech SDK 同样支持多种语言,可以实现将文本转换成语音的功能。 作为一套全面的语音技术开发工具包,Microsoft Speech SDK 不仅支持语音识别和语音合成,还支持音频输入和输出,例如录音和播放音频,可以支持麦克风、音频文件等多种方式。同时,在语音评测方面,也提供了多种评测模型和算法,可以对说话人的语音进行分析,判断语音的准确性、流畅度等方面。 总之,Microsoft Speech SDK 是一套极为强大和全面的语音技术开发工具包,可以帮助开发者轻松地构建语音应用,减少了开发者在语音处理方面的复杂度和工作量,提高了语音应用程序开发的效率和可靠性。 ### 回答3: Microsoft Speech SDKMicrosoft提供的一套用于语音识别和合成的开发工具包,可帮助开发人员将语音技术集成到应用程序中,使应用程序具有语音识别和合成的功能。虽然Microsoft Speech SDK已被微软官方宣布停止维护和更新,但是它仍然是很多语音开发人员的首选工具之一。 Microsoft Speech SDK提供了各种API和库,可以支持多种编程语言和平台,例如,C++, C#, VB.NET,甚至还支持早期版本的ASP.NET。开发人员可以选择多种语言模型和语音引擎,以适应不同的语音应用场景。此外,SDK还提供了一些测试工具和示例代码,供开发人员参考和学习。 使用Microsoft Speech SDK可以实现自然语言的语音识别和语音合成技术,从而能够更好地实现人机交互,提高应用程序的易用性和用户体验。比如,通过语音识别技术,用户可以直接使用语音来操作程序,而无需使用鼠标和键盘,这大大提高了操作的效率。而通过语音合成技术,应用程序可以将文字转换为语音输出,从而帮助听障人士更好地使用应用程序。 除此之外,Microsoft Speech SDK在语音转录和实时语音转录等领域也有广泛的应用。例如,语音转录可以将语音直接转换为文本,应用于语音翻译、语音输入等场景。实时语音转录可以将多个说话者的语音同时转换为文本,应用于多人会议记录等场景。 总之,Microsoft Speech SDK是一套优秀的语音开发工具包,可以大大简化语音应用程序的开发过程,提高应用程序的交互性和可用性,使开发者能够更好地实现创新的语音应用程序。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值