/// <summary> /// Adds a callback to be called when any of the keywords get called in the list of keywords passed in. /// </summary> /// <param name="keywords">The list of keywords to track.</param> /// <param name="handler">The callback to call when any of the keywords are spoken.</param> /// <param name="level">The minimum level of confidence for any of the keywords spoken.</param> public void AddKeywords(IEnumerable <string> keywords, KeywordRecognizedDelegate handler, KeywordConfidenceLevel level = KeywordConfidenceLevel.Medium) { foreach (string keyword in keywords) { this.AddKeyword(keyword, handler, level); } }
/// <summary> /// Removes all the keywords assosiated with the callback. /// </summary> /// <param name="keywords">The list of keywords to remove.</param> /// <param name="handler">The callback assosiated with them.</param> public void RemoveKeywords(IEnumerable <string> keywords, KeywordRecognizedDelegate handler) { foreach (string keyword in keywords) { this.RemoveKeyword(keyword, handler); } }
/// <summary> /// Adds a new listener entry. /// </summary> /// <param name="listener">The callback to call.</param> /// <param name="level">The minimum confidence for this callback to be called.</param> public void AddListener(KeywordRecognizedDelegate listener, KeywordConfidenceLevel level) { if (listener != null) { CommandInfo info = new CommandInfo(); info.m_Handler = listener; info.m_ConfidenceLevel = level; m_Handlers.Add(info); Enabled = true; } }
/// <summary> /// Removed the callback assosited with the keyword passed in. If a string with commas is passed in it will be split /// and each word seperated by a comma will be used as a keyword. /// </summary> /// <param name="wordOrPhrase">The keyword to remove.</param> /// <param name="handler">The callback to remove.</param> public void RemoveKeyword(string wordOrPhrase, KeywordRecognizedDelegate handler) { string[] phrases = wordOrPhrase.ToLower().Split(','); foreach (string phrase in phrases) { string fixedPhrase = phrase.Trim(); if (this.m_Commands.ContainsKey(fixedPhrase)) { m_Commands[fixedPhrase].RemoveListener(handler); } } m_UpdateRemovals = true; }
/// <summary> /// Adds a callback to be called if the keyword is spoken. If a string with commas is passed in it will be split /// and each word seperated by a comma will be used as a keyword. /// </summary> /// <param name="wordOrPhrase">The keyword to track.</param> /// <param name="handler">The callback to call when the keyword is spoken.</param> /// <param name="level">The minimum level of confidence for any of the keywords spoken.</param> public void AddKeyword(string wordOrPhrase, KeywordRecognizedDelegate handler, KeywordConfidenceLevel level = KeywordConfidenceLevel.Medium) { string[] phrases = wordOrPhrase.ToLower().Split(','); foreach (string phrase in phrases) { string fixedPhrase = phrase.Trim(); if (fixedPhrase.Length > 0) { if (!m_Commands.ContainsKey(fixedPhrase)) { m_Commands[fixedPhrase] = new KeywordCommandInfo(fixedPhrase); } m_Commands[fixedPhrase].AddListener(handler, level); } } }
/// <summary> /// Removes a listener from the tracking list. /// </summary> /// <param name="listener">The callback to remove.</param> public void RemoveListener(KeywordRecognizedDelegate listener) { if (listener != null) { int activeHandlers = 0; for (int index = 0; index < m_Handlers.Count; index++) { if (m_Handlers[index].m_Handler == listener) { m_Handlers[index].m_ToRemove = true; m_CleanUpRemovals = true; } else if (!m_Handlers[index].m_ToRemove) { activeHandlers++; } } if (activeHandlers == 0) { Enabled = false; } } }