/// <summary> /// Handler for speech detection events /// </summary> /// <param name="detectionResult"></param> /// <returns>Return true if the result was handled</returns> bool HandleDetectionResult(DetectionResult detectionResult) { if (null == detectionResult) { return(false); } SpeechRecognitionResult[] results = detectionResult.results; if (null == results) { return(false); } bool doAbort = false; foreach (SpeechRecognitionResult result in results) { SpeechRecognitionAlternative[] alternatives = result.alternatives; if (null == alternatives) { continue; } foreach (SpeechRecognitionAlternative alternative in alternatives) { if (string.IsNullOrEmpty(alternative.transcript)) { continue; } string lower = alternative.transcript.ToLower(); Debug.LogFormat("Detected: {0}", lower); foreach (KeyValuePair <string, Example02Word> kvp in _mWords) { if (lower.Contains(kvp.Key)) { kvp.Value.Highlight(); doAbort = true; break; } } } if (doAbort) { break; } } // abort detection on match for faster matching on words instead of complete sentences if (doAbort) { _mSpeechDetectionPlugin.Abort(); return(true); } return(false); }
/// <summary> /// Handler for changing dialects /// </summary> public static void HandleDialectChanged(string[] dialectOptions, int dialectIndex, LanguageResult languageResult, ISpeechDetectionPlugin plugin) { if (null == dialectOptions) { Debug.LogError("The dialect options are not set!"); return; } if (null == languageResult) { Debug.LogError("The language result is not set!"); return; } string display = dialectOptions[dialectIndex]; Dialect dialect = null; if (dialectIndex > 0) { //Debug.Log(display); SetDefaultDialect(display); dialect = SpeechDetectionUtils.GetDialect(languageResult, display); if (null == dialect) { Debug.LogError("Did not find specified dialect!"); return; } //Debug.Log(dialect.name); if (null != plugin) { plugin.Abort(); plugin.SetLanguage(dialect.name); LanguageChangedResult languageChangedResult = new LanguageChangedResult(); languageChangedResult._mDialect = dialect.name; plugin.Invoke(languageChangedResult); } } }
/// <summary> /// Handler for changing dialects /// </summary> public static void HandleDialectChanged(Dropdown dropdownDialects, LanguageResult languageResult, ISpeechDetectionPlugin plugin) { if (null == dropdownDialects) { Debug.LogError("The dropdown for dialects is not set!"); return; } if (null == languageResult) { Debug.LogError("The language result is not set!"); return; } string display = dropdownDialects.options[dropdownDialects.value].text; Dialect dialect = null; if (dropdownDialects.value > 0) { //Debug.Log(display); SetDefaultDialect(display); dialect = SpeechDetectionUtils.GetDialect(languageResult, display); if (null == dialect) { Debug.LogError("Did not find specified dialect!"); return; } //Debug.Log(dialect.name); if (null != plugin) { plugin.Abort(); plugin.SetLanguage(dialect.name); LanguageChangedResult languageChangedResult = new LanguageChangedResult(); languageChangedResult._mDialect = dialect.name; plugin.Invoke(languageChangedResult); } } }