コード例 #1
0
        // Get attributes of all the recognizers that are installed
        public static ReadOnlyCollection <RecognizerInfo> InstalledRecognizers()
        {
            List <RecognizerInfo> recognizers = new();

            // Get list of ObjectTokens
            using (ObjectTokenCategory category = ObjectTokenCategory.Create(SAPICategories.Recognizers))
            {
                if (category != null)
                {
                    // For each element in list
                    foreach (ObjectToken token in (IEnumerable <ObjectToken>)category)
                    {
                        // Create RecognizerInfo + add to collection
                        RecognizerInfo recognizerInfo = RecognizerInfo.Create(token);

                        if (recognizerInfo == null)
                        {
                            // But if this entry has a corrupt registry entry then skip it.
                            // Otherwise one bogus entry prevents the whole method from working.
                            continue;
                        }
                        recognizers.Add(recognizerInfo);
                    }
                }
            }
            return(new ReadOnlyCollection <RecognizerInfo>(recognizers));
        }
コード例 #2
0
        public static ReadOnlyCollection <RecognizerInfo> InstalledRecognizers()
        {
            List <RecognizerInfo> list = new List <RecognizerInfo>();

            using (ObjectTokenCategory objectTokenCategory = ObjectTokenCategory.Create("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Recognizers"))
            {
                if (objectTokenCategory != null)
                {
                    foreach (ObjectToken item in (IEnumerable <ObjectToken>)objectTokenCategory)
                    {
                        RecognizerInfo recognizerInfo = RecognizerInfo.Create(item);
                        if (recognizerInfo != null)
                        {
                            list.Add(recognizerInfo);
                        }
                    }
                }
            }
            return(new ReadOnlyCollection <RecognizerInfo>(list));
        }