private SpInProcRecoContext m_wavRecoContext; private ISpeechRecoGrammar m_Grammar; private SpFileStream m_infile; public CtiLine ctiLine; private string result = string.Empty; SpInprocRecognizer recognizer; public SpRecognizer() { try { recognizer = new SpInprocRecognizer(); m_wavRecoContext = (SpInProcRecoContext)recognizer.CreateRecoContext(); m_wavRecoContext.RetainedAudio = SpeechRetainedAudioOptions.SRAORetainAudio; m_infile = new SpFileStreamClass(); m_infile.Format.GetWaveFormatEx(); } catch (Exception ex) { SearchLog.Log.AppendLog("RecognizeWav", ex.ToString()); } } public void OpenWAV() { try { m_Grammar = m_wavRecoContext.CreateGrammar(0); m_Grammar.DictationLoad("", SpeechLoadOption.SLOStatic); m_wavRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition); m_wavRecoContext.EndStream += new _ISpeechRecoContextEvents_EndStreamEventHandler(RecoContext_EndRecognition); m_infile.Open(ctiLine.MStation.RecorderFilePath, SpeechStreamFileMode.SSFMOpenForRead, false); m_wavRecoContext.Recognizer.AudioInputStream = m_infile; m_Grammar.DictationSetState(SpeechRuleState.SGDSActive); } catch (Exception ex) { SearchLog.Log.AppendLog("OpenWAV", ex.ToString()); } } void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result) { if (m_infile != null) { result += Result.PhraseInfo.GetText(0, -1, true); } } void RecoContext_EndRecognition(int StreamNumber, object StreamPosition, bool f) { ctiLine.MStation.MobileIsStation = IsMobileStation(); SearchLog.Log.AppendLog("(" + ctiLine.MStation.MobileNo + ")" + "Recognize Result", result); m_Grammar.DictationSetState(SpeechRuleState.SGDSInactive); m_wavRecoContext.Recognition -= RecoContext_Recognition; m_wavRecoContext.EndStream -= RecoContext_EndRecognition; ctiLine.IsRecognized = true; m_infile.Close(); m_infile = null; m_wavRecoContext = null; m_Grammar = null; recognizer = null; }
上面是主要代码,资源释放有问题,运行一段时间后 大概识别3700个左右的时候就会报System.OutOfMemoryException: Insufficient memory to continue the execution of the program.错误,内存不足,
请各位支招,怎么修改下,急