示例#1
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);
        }
示例#2
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);
        }