Esempio n. 1
0
        /// <summary>
        /// Handle multiple panels open and changing languages
        /// </summary>
        /// <param name="languageChangedResult"></param>
        void HandleOnLanguageChanged(LanguageChangedResult languageChangedResult)
        {
            ISpeechDetectionPlugin plugin = EditorProxySpeechDetectionPlugin.GetInstance();
            int languageIndex             = _mLanguage;

            if (SpeechDetectionUtils.HandleOnLanguageChanged(
                    ref _mLanguage,
                    _mLanguages,
                    ref _mDialect,
                    _mDialects,
                    _mLanguageResult,
                    plugin,
                    languageChangedResult))
            {
                if (languageIndex != _mLanguage)
                {
                    SpeechDetectionUtils.HandleLanguageChanged(_mLanguages,
                                                               _mLanguage,
                                                               out _mDialects,
                                                               ref _mDialect,
                                                               _mLanguageResult,
                                                               plugin);
                }
                Repaint();
            }
        }
        // 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);
            }

            // subscribe to events
            _mSpeechDetectionPlugin.AddListenerOnDetectionResult(HandleDetectionResult);

            // A list of words to detect
            string[] wordsToDetect =
            {
                "Climb",
                "Crouch",
                "Jump",
                "Left",
                "Right",
                "Stand",
                "Run",
                "10", // match 10 before 1
                "Ten",
                "1",
                "One",
                "2",
                "Two",
                "3",
                "Three",
                "4",
                "Four",
                "5",
                "Five",
                "6",
                "Six",
                "7",
                "Seven",
                "8",
                "Eight",
                "9",
                "Nine",
            };

            foreach (string word in wordsToDetect)
            {
                _mWords.Add(word.ToLower());
            }
        }
Esempio n. 3
0
        /// <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);
                }
            }
        }
Esempio n. 4
0
        /// <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);
                }
            }
        }
Esempio n. 5
0
        // 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);
            }

            // subscribe to events
            _mSpeechDetectionPlugin.AddListenerOnDetectionResult(HandleDetectionResult);
        }
Esempio n. 6
0
        // 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);
            });
        }
Esempio n. 7
0
        public static bool HandleOnLanguageChanged(
            ref int languageIndex,
            string[] languageOptions,
            ref int dialectIndex,
            string[] dialectOptions,
            LanguageResult languageResult,
            ISpeechDetectionPlugin plugin,
            LanguageChangedResult languageChangedResult)
        {
            if (_sPausePreferences)
            {
                return(false);
            }

            if (null == languageResult)
            {
                Debug.LogError("LanguageResult is null!");
                return(false);
            }

            if (null == languageChangedResult)
            {
                Debug.LogError("LanguageChangedResult is null!");
                return(false);
            }

            bool changed = false;

            /*
             * Debug.LogFormat("GetLanguageDisplay: language={0} dialect={1}",
             *  (languageChangedResult._mLanguage == null) ? "null" : languageChangedResult._mLanguage,
             *  (languageChangedResult._mDialect == null) ? "null" : languageChangedResult._mDialect);
             */

            if (null != languageChangedResult._mLanguage)
            {
                string language = GetLanguageDisplay(languageResult, languageChangedResult._mLanguage);
                for (int index = 0; index < languageOptions.Length; ++index)
                {
                    if (languageOptions[index] == language)
                    {
                        if (languageIndex != index)
                        {
                            languageIndex = index;
                            changed       = true;
                            break;
                        }
                    }
                }
            }

            if (null != languageChangedResult._mDialect)
            {
                string dialect = GetDialectDisplay(languageResult, languageChangedResult._mDialect);
                for (int index = 0; index < dialectOptions.Length; ++index)
                {
                    if (dialectOptions[index] == dialect)
                    {
                        if (dialectIndex != index)
                        {
                            dialectIndex = index;
                            changed      = true;
                        }
                    }
                }
            }

            return(changed);
        }
Esempio n. 8
0
        /// <summary>
        /// Handler for changing languages
        /// </summary>
        public static void HandleLanguageChanged(string[] languageOptions,
                                                 int languageIndex,
                                                 out string[] dialectOptions,
                                                 ref int dialectIndex,
                                                 LanguageResult languageResult,
                                                 ISpeechDetectionPlugin plugin)
        {
            List <string> options = GetDefaultDialectOptions();

            dialectOptions = options.ToArray();
            dialectIndex   = 0;

            if (null == languageOptions)
            {
                Debug.LogError("The language options are not set!");
                return;
            }

            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 = languageOptions[languageIndex];

            //Debug.Log(display);
            SetDefaultLanguage(display);

            Language language = null;

            if (languageIndex > 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);
                }
            }

            if (languageIndex > 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);
                    }
                }
            }
            dialectOptions = options.ToArray();
            if (dialectOptions.Length > 1)
            {
                dialectIndex = 1;
            }

            HandleDialectChanged(dialectOptions, dialectIndex, languageResult, plugin);
        }
Esempio n. 9
0
        /// <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);
        }
Esempio n. 10
0
        // 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;
            }

            // proxy needs to be launched before it's available
            if (_mButtonLaunchProxy)
            {
                _mButtonLaunchProxy.onClick.AddListener(() =>
                {
                    _mSpeechDetectionPlugin.ManagementLaunchProxy();
                });
            }

            // wait for plugin to become available
            while (!_mSpeechDetectionPlugin.IsAvailable())
            {
                yield return(null);
            }

            if (_mButtonCloseBrowserTab)
            {
                _mButtonCloseBrowserTab.onClick.AddListener(() =>
                {
                    _mSpeechDetectionPlugin.ManagementCloseBrowserTab();
                });
            }

            if (_mButtonCloseProxy)
            {
                _mButtonCloseProxy.onClick.AddListener(() =>
                {
                    _mSpeechDetectionPlugin.ManagementCloseProxy();
                });
            }

            if (_mButtonOpenBrowserTab)
            {
                _mButtonOpenBrowserTab.onClick.AddListener(() =>
                {
                    _mSpeechDetectionPlugin.ManagementOpenBrowserTab();
                });
            }

            if (_mButtonSetProxyPort &&
                _mInputPort)
            {
                _mButtonSetProxyPort.onClick.AddListener(() =>
                {
                    int port;
                    if (int.TryParse(_mInputPort.text, out port))
                    {
                        _mSpeechDetectionPlugin.ManagementSetProxyPort(port);
                    }
                    else
                    {
                        _mInputPort.text = "5000";
                    }
                });
            }
        }
Esempio n. 11
0
        // 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;
                }
            }
        }