SpRecognition.cs
资源名称:speech.rar [点击查看]
上传用户:cookies0
上传日期:2022-07-28
资源大小:284k
文件大小:2k
源码类别:
语音合成与识别
开发平台:
Visual C++
- using System;
- using System.Collections.Generic;
- using System.Text;
- using SpeechLib;
- using System.Windows.Forms;
- namespace tryreco
- {
- class SpRecognition
- {
- private static SpRecognition _Instance = null;
- private SpeechLib.ISpeechRecoGrammar isrg;
- private SpeechLib.SpSharedRecoContextClass ssrContex = null;
- private System.Windows.Forms.Control cDisplay;
- public System.Windows.Forms.TextBox textbox;
- public SpRecognition()
- {
- ssrContex = new SpSharedRecoContextClass();
- isrg = ssrContex.CreateGrammar(1);
- SpeechLib._ISpeechRecoContextEvents_RecognitionEventHandler recHandle =
- new _ISpeechRecoContextEvents_RecognitionEventHandler(ContexRecognition);
- ssrContex.Recognition += recHandle;
- }
- public void BeginRec(Control tbResult)
- {
- isrg.DictationSetState(SpeechRuleState.SGDSActive);
- cDisplay = tbResult;
- }
- public static SpRecognition instance()
- {
- if (_Instance == null)
- _Instance = new SpRecognition();
- return _Instance;
- }
- public void CloseRec()
- {
- isrg.DictationSetState(SpeechRuleState.SGDSInactive);
- }
- private void ContexRecognition(int iIndex, object obj, SpeechLib.SpeechRecognitionType type, SpeechLib.ISpeechRecoResult result)
- {
- cDisplay.Text += result.PhraseInfo.GetText(0, -1, true);
- }
- }
- }