// Use this for initialization IEnumerator Start() { // get the singleton instance _mSpeechDetectionPlugin = SpeechDetectionUtils.GetInstance(); // check the reference to the plugin if (null == _mSpeechDetectionPlugin) { Debug.LogError("Proxy 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, _mTextWaiting); // display the UI controls SpeechDetectionUtils.SetActive(true, _mDropDownDialects, _mDropDownLanguages, _mTextDictation, _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); // 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); }); }
/// <summary> /// Reinitialize the editor proxy when enabled and not compiling /// </summary> private void Update() { bool enabled = EditorProxySpeechDetectionPlugin.IsEnabled(); if (!enabled || EditorApplication.isCompiling) { _mInitialized = false; return; } EditorProxySpeechDetectionPlugin plugin = EditorProxySpeechDetectionPlugin.GetInstance(); if (null != plugin) { if (!_mInitialized) { if (!plugin.IsAvailable()) { return; } //Debug.LogFormat("Update: Plugin is available"); // Reset the detection list _mWords.Clear(); _mWords.Add("Say something..."); plugin.GetLanguages((languageResult) => { _mLanguageResult = languageResult; // populate the language options SpeechDetectionUtils.PopulateLanguages(out _mLanguages, out _mLanguage, languageResult); // Restore the default language SpeechDetectionUtils.RestoreLanguage(_mLanguages, out _mLanguage); // Handle setting the default language SpeechDetectionUtils.PausePlayerPrefs(true); SpeechDetectionUtils.HandleLanguageChanged(_mLanguages, _mLanguage, out _mDialects, ref _mDialect, _mLanguageResult, plugin); SpeechDetectionUtils.PausePlayerPrefs(false); // Restore the default dialect SpeechDetectionUtils.RestoreDialect(_mDialects, out _mDialect); // Update UI Repaint(); }); // subscribe to events plugin.AddListenerOnDetectionResult(HandleDetectionResult); // get on language changed events plugin.AddListenerOnLanguageChanged(HandleOnLanguageChanged); //Debug.Log("Update: HandleDetectionResult subscribed"); _mInitialized = true; Repaint(); } } // run pending UI actions while (_mPendingActions.Count > 0) { Action action = _mPendingActions[0]; _mPendingActions.RemoveAt(0); action.Invoke(); } }
// 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; } } }
/// <summary> /// Reinitialize the editor proxy when enabled and not compiling /// </summary> private void Update() { bool enabled = EditorProxySpeechDetectionPlugin.IsEnabled(); if (!enabled || EditorApplication.isCompiling) { _mInitialized = false; return; } // handle init EditorProxySpeechDetectionPlugin plugin = EditorProxySpeechDetectionPlugin.GetInstance(); if (null != plugin) { if (!_mInitialized) { if (!plugin.IsAvailable()) { return; } //Debug.LogFormat("Update: Plugin is available"); plugin.GetLanguages((languageResult) => { _mLanguageResult = languageResult; // populate the language options SpeechDetectionUtils.PopulateLanguages(out _mLanguages, out _mLanguage, languageResult); // Restore the default language SpeechDetectionUtils.RestoreLanguage(_mLanguages, out _mLanguage); // Handle setting the default language SpeechDetectionUtils.PausePlayerPrefs(true); SpeechDetectionUtils.HandleLanguageChanged(_mLanguages, _mLanguage, out _mDialects, ref _mDialect, _mLanguageResult, plugin); SpeechDetectionUtils.PausePlayerPrefs(false); // Restore the default dialect SpeechDetectionUtils.RestoreDialect(_mDialects, out _mDialect); // Update UI Repaint(); }); // subscribe to events plugin.AddListenerOnDetectionResult(HandleDetectionResult); // get on language changed events plugin.AddListenerOnLanguageChanged(HandleOnLanguageChanged); //Debug.Log("Update: HandleDetectionResult subscribed"); _mInitialized = true; Repaint(); } } // Check timers to deactivate button after delay bool doRepaint = false; foreach (KeyValuePair <string, MethodInfo> kvp in _mEditorCommands) { DateTime timer = _mTimers[kvp.Key]; if (timer != DateTime.MinValue && timer < DateTime.Now) { _mTimers[kvp.Key] = DateTime.MinValue; doRepaint = true; } } if (doRepaint) { Repaint(); } // run pending UI actions while (_mPendingActions.Count > 0) { Action action = _mPendingActions[0]; _mPendingActions.RemoveAt(0); action.Invoke(); } }