SpRecognition.cs
上传用户:cookies0
上传日期:2022-07-28
资源大小:284k
文件大小:2k
源码类别:

语音合成与识别

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using SpeechLib;
  5. using System.Windows.Forms;
  6. namespace tryreco
  7. {
  8.     class SpRecognition
  9.     {
  10.         private static SpRecognition _Instance = null;
  11.         private SpeechLib.ISpeechRecoGrammar isrg;
  12.         private SpeechLib.SpSharedRecoContextClass ssrContex = null;
  13.         private System.Windows.Forms.Control cDisplay; 
  14.         public System.Windows.Forms.TextBox textbox; 
  15.         public SpRecognition()
  16.         {
  17.             ssrContex = new SpSharedRecoContextClass();
  18.             isrg = ssrContex.CreateGrammar(1);
  19.             SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler recHandle =
  20.             new _ISpeechRecoContextEvents_RecognitionEventHandler(ContexRecognition);
  21.             ssrContex.Recognition += recHandle;
  22.         }
  23.         public void BeginRec(Control tbResult)
  24.         {
  25.             isrg.DictationSetState(SpeechRuleState.SGDSActive);
  26.             cDisplay = tbResult;
  27.             
  28.         }
  29.         public static SpRecognition instance()
  30.         {
  31.             if (_Instance == null)
  32.                 _Instance = new SpRecognition();
  33.             return _Instance;
  34.         }
  35.         public void CloseRec()
  36.         {
  37.             isrg.DictationSetState(SpeechRuleState.SGDSInactive);
  38.         }
  39.         private void ContexRecognition(int iIndex, object obj, SpeechLib.SpeechRecognitionType type, SpeechLib.ISpeechRecoResult result)
  40.         {
  41.             cDisplay.Text += result.PhraseInfo.GetText(0, -1, true);
  42.         }
  43.        
  44.       
  45.     }
  46. }