使用C#进行语音识别(Speech-to-Text)

        本文大体的介绍怎样通过使用C#和Speech SDK5.1来进行语音识别,通过微软提供的Speech SDK你也可以使用其他的语言进行语音识别的开发,目前最新的Release版本是5.1。

介绍 

        声音的交流是我们平时最常见的交流方式,但是在人与计算机之间似乎就不那么一样的常见了,我想原因是如果一个应用程序仅仅用声音来控制的话,呵呵,那要是人撒谎计算机就惨了。虽然使用声音来作为应用程序的录入不是什么新东西了,但是目前采用语音录入的应用程序还不是那么的常见,换句话说,语音的开发仍然有很大的潜力和空间。

语音识别引擎       

        语音识别引擎有两种不同的识别引擎,一种叫Shared识别引擎,另外一种叫做Inpro识别引擎,相信大家通过名字也能大概猜到了他们的不同了吧!Shared识别引擎能够被多个应用程序共享使用,通常这个语音引擎用于多个应用程序需要语音输入的时候。虽然Inpro识别引擎不像Shared引擎那样被多个Application共享但是在一个大型的在独立的服务器上运行的语音系统中我们推荐使用它。

        语音识别引擎通过使用事件的方式和应用程序产生交互,在许多的事件中最重要的是recognition event 和 hypothesis event,这两个事件在语音识别引擎在recognition或者hypothesis识别到时触发。 下面的代码说明了怎样去签名这些事件:

// 得到一个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,"Paste"," ",SpeechGrammarWordType.SGLexical,"Paste",1, ref PropValue, 1.0F );
   menuRule.InitialState.AddWordTransition(null,"Delete"," ",SpeechGrammarWordType.SGLexical,"Delete",2, ref PropValue, 1.0F );

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

下面显示了主要的运行窗口

使用C#进行语音识别(Speech-to-Text)_第1张图片

                示例下载(文件提取码: 1176475894201735)

摘要:这篇文章对使用Speech SDK 5.1语音识别作了简单的介绍。

       

       

        

 

 

 

你可能感兴趣的:(使用C#进行语音识别(Speech-to-Text))