protected void watcher_Changed(object sender, SoftMade.IO.FileSystemEventArgs e) { if (e.ChangeType == SoftMade.IO.WatcherChangeTypes.BeginWrite) { return; } watcher.EnableRaisingEvents = false; // Backup current context var ctxt = ContextManager.GetInstance().Current; // Reload all grammar Load(path); // Set context back ContextManager.GetInstance().SetContext(ctxt); // Apply cache to all engines foreach (SpeechEngine engine in SpeechManager.GetInstance().Engines.Values) { engine.Load(Cache, true); } // Reset context timeout ContextManager.GetInstance().ResetContextTimeout(); watcher.EnableRaisingEvents = true; }
protected void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e) { try { SpeechManager.GetInstance().SpeechRejected(this, e.Result); } catch (Exception ex) { Error(ex); } }
public override void BeforeSpeechRecognition(string device, string text, double confidence, XPathNavigator xnav, string grammar, Stream stream, IDictionary <string, string> options) { base.BeforeSpeechRecognition(device, text, confidence, xnav, grammar, stream, options); var listen = xnav.SelectSingleNode("/SML/action/@listen"); if (listen != null) { bool state = Boolean.Parse(listen.Value); SpeechManager.GetInstance().Pause(!state); } }
// ------------------------------------------ // HTTP Management // ------------------------------------------ public override void BeforeHTTPRequest(string qs, NameValueCollection parameters, IDictionary files, StreamWriter writer) { base.BeforeHTTPRequest(qs, parameters, files, writer); // Start/Stop SpeechEngine var listen = parameters.Get("listen"); if (listen != null) { bool state = Boolean.Parse(listen); SpeechManager.GetInstance().Pause(!state); } }
// ------------------------------------------- // APPLY GRAMMAR STATE // ------------------------------------------- public void ApplyGrammarsToEngines() { Log("Forward Context enable/disable grammar"); foreach (SpeechEngine engine in SpeechManager.GetInstance().GetEngines()) { foreach (Grammar g in engine.Engine.Grammars) { if (!Cache.ContainsKey(g.Name)) { continue; } g.Enabled = Cache[g.Name].Enabled; Log(g.Name + " = " + g.Enabled); } } }
protected void SpeechRecognized(RecognitionResult rr) { // 1. Handle the Working local state if (IsWorking) { Log("REJECTED Speech while working: " + rr.Confidence + " Text: " + rr.Text); return; } // 2. Start IsWorking = true; var start = DateTime.Now; // 3. Handle Results try { SpeechManager.GetInstance().SpeechRecognized(this, rr); } catch (Exception ex) { Error(ex); } // 4. End IsWorking = false; Debug("SpeechRecognized: " + (DateTime.Now - start).TotalMilliseconds + "ms Text: " + rr.Text); }
public SpeechGrammar UpdateXML(SpeechGrammar grammar, String bodyXML) { if (grammar == null) { return(null); } // Include BODY to XML var name = grammar.Name; var rule = "rule" + Char.ToUpper(name[0]) + name.Substring(1); var xml = "\n<grammar version=\"1.0\" xml:lang=\"" + ConfigManager.GetInstance().Find("bot.language", "fr-FR") + "\" mode=\"voice\" root=\"" + name + "\" xmlns=\"http://www.w3.org/2001/06/grammar\" tag-format=\"semantics/1.0\">"; xml += "\n<rule id=\"" + name + "\" scope=\"public\">"; xml += "\n<tag>out.action=new Object(); </tag>"; xml += bodyXML; xml += "\n</rule>"; xml += "\n</grammar>"; // Load Grammar LoadXML(grammar, xml); grammar.LastModified = DateTime.Now; // Add to cache if (!Cache.ContainsKey(name)) { Cache[name] = grammar; } // Reload the XML of the Grammar foreach (SpeechEngine engine in SpeechManager.GetInstance().GetEngines()) { engine.Load(name, grammar.Build()); } return(grammar); }
// ------------------------------------------ // Audio Management // ------------------------------------------ public override void HandleAudioSource(string device, Stream stream, string format, string language, double confidence) { base.HandleAudioSource(device, stream, format, language, confidence); SpeechManager.GetInstance().AddSpeechEngine(stream, format, device, language, confidence); }
public override void Dispose() { base.Dispose(); GrammarManager.GetInstance().Dispose(); SpeechManager.GetInstance().Dispose(); }