/// <summary> /// Disable the dialects UI when not available /// </summary> public static void DisableDialects(Dropdown dropdown) { SpeechDetectionUtils.PopulateDropdown(dropdown, SpeechDetectionUtils.GetDefaultDialectOptions()); SpeechDetectionUtils.SetInteractable(false, dropdown); }
/// <summary> /// Handler for changing languages /// </summary> public static void HandleLanguageChanged(Dropdown dropdownLanguages, Dropdown dropdownDialects, LanguageResult languageResult, ISpeechDetectionPlugin plugin) { if (null == dropdownLanguages) { Debug.LogError("The dropdown for languages is not set!"); return; } 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 = dropdownLanguages.options[dropdownLanguages.value].text; //Debug.Log(display); SetDefaultLanguage(display); Language language = null; if (dropdownLanguages.value > 0) { language = SpeechDetectionUtils.GetLanguage(languageResult, display); if (null == language) { Debug.LogError("Did not find specified language!"); } else { LanguageChangedResult languageChangedResult = new LanguageChangedResult(); languageChangedResult._mLanguage = language.name; plugin.Invoke(languageChangedResult); } } List <string> options = SpeechDetectionUtils.GetDefaultDialectOptions(); if (dropdownLanguages.value > 0 && null != language && null != language.dialects && language.dialects.Length > 0) { foreach (Dialect dialect in language.dialects) { if (!string.IsNullOrEmpty(dialect.display)) { options.Add(dialect.display); } else if (!string.IsNullOrEmpty(dialect.description)) { options.Add(dialect.description); } else if (!string.IsNullOrEmpty(dialect.name)) { options.Add(dialect.name); } } } SpeechDetectionUtils.PopulateDropdown(dropdownDialects, options); SpeechDetectionUtils.SetInteractable(options.Count > 1, dropdownDialects); SpeechDetectionUtils.SelectIndex(dropdownDialects, 1); HandleDialectChanged(dropdownDialects, languageResult, plugin); }
// Use this for initialization IEnumerator Start() { // get the singleton instance _mSpeechDetectionPlugin = SpeechDetectionUtils.GetInstance(); // check the reference to the plugin if (null == _mSpeechDetectionPlugin) { Debug.LogError("WebGL Speech Detection Plugin is not set!"); yield break; } // wait for plugin to become available while (!_mSpeechDetectionPlugin.IsAvailable()) { yield return(null); } // no need to display a warning if the plugin is available SpeechDetectionUtils.SetActive(false, _mTextWarning); // make the dropdowns non-interactive SpeechDetectionUtils.SetInteractable(false, _mDropDownLanguages, _mDropDownDialects); // show UI controls SpeechDetectionUtils.SetActive(true, _mDropDownDialects, _mDropDownLanguages, _mImageWords, _mTextSummary); // subscribe to events _mSpeechDetectionPlugin.AddListenerOnDetectionResult(HandleDetectionResult); // Get languages from plugin, _mSpeechDetectionPlugin.GetLanguages((languageResult) => { _mLanguageResult = languageResult; // prepare the language drop down items SpeechDetectionUtils.PopulateLanguagesDropdown(_mDropDownLanguages, _mLanguageResult); // make the dropdowns interactive SpeechDetectionUtils.SetInteractable(true, _mDropDownLanguages, _mDropDownDialects); // subscribe to language change events if (_mDropDownLanguages) { _mDropDownLanguages.onValueChanged.AddListener(delegate { SpeechDetectionUtils.HandleLanguageChanged(_mDropDownLanguages, _mDropDownDialects, _mLanguageResult, _mSpeechDetectionPlugin); }); } // subscribe to dialect change events if (_mDropDownDialects) { _mDropDownDialects.onValueChanged.AddListener(delegate { SpeechDetectionUtils.HandleDialectChanged(_mDropDownDialects, _mLanguageResult, _mSpeechDetectionPlugin); }); } // Disabled until a language is selected SpeechDetectionUtils.DisableDialects(_mDropDownDialects); // set the default language SpeechDetectionUtils.RestoreLanguage(_mDropDownLanguages); // set the default dialect SpeechDetectionUtils.RestoreDialect(_mDropDownDialects); }); // get all the words in the UI foreach (Example02Word word in GameObject.FindObjectsOfType <Example02Word>()) { Text text = word.GetComponentInChildren <Text>(); if (text) { _mWords[text.text.ToLower()] = word; } } }