Boolean Init() { if (_speech != null) { return(true); } _speech = ObjectContainer.Current.Resolve <ISpeech>(); if (_speech != null) { return(true); } try { Assembly.Load("System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); var code = Assembly.GetExecutingAssembly().GetFileResource("MySpeech.cs").ToStr(); var sc = ScriptEngine.Create(code, false); sc.Compile(); _speech = sc.Type.CreateInstance() as ISpeech; if (_speech == null) { return(false); } if (!_speech.Init()) { return(false); } _speech.SpeechRecognized += _rg_SpeechRecognized; return(true); } catch (Exception ex) { XTrace.WriteException(ex); _speech.TryDispose(); return(false); } }
/// <summary>销毁</summary> /// <param name="disposing"></param> protected override void Dispose(Boolean disposing) { base.Dispose(disposing); _speech.TryDispose(); }
/// <summary>销毁</summary> /// <param name="disposing"></param> protected override void OnDispose(bool disposing) { base.OnDispose(disposing); _speech.TryDispose(); }