예제 #1
0
        /// <summary>
        /// Retrieve the Multimedia device ID. If the entry 'DefaultTokenId' is defined in the registry
        /// under 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\AudioOutput' then a multimedia device is looked
        /// for with this token. Otherwise, picks the default WAVE_MAPPER is returned.
        /// </summary>
        internal static int DefaultDeviceOut()
        {
            int device = -1;

            using (ObjectTokenCategory tokenCategory = ObjectTokenCategory.Create(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\AudioOutput"))
            {
                if (tokenCategory != null)
                {
                    string deviceName;
                    if (tokenCategory.TryGetString(_defaultTokenIdValueName, out deviceName))
                    {
                        int pos = deviceName.IndexOf('\\');
                        if (pos > 0 && pos < deviceName.Length)
                        {
                            using (RegistryDataKey deviceKey = RegistryDataKey.Create(deviceName.Substring(pos + 1), Registry.LocalMachine))
                            {
                                if (deviceKey != null)
                                {
                                    device = AudioDeviceOut.GetDevicedId(deviceKey.Name);
                                }
                            }
                        }
                    }
                }
            }

            return(device);
        }
예제 #2
0
        internal static int DefaultDeviceOut()
        {
            int result = -1;

            using (ObjectTokenCategory objectTokenCategory = ObjectTokenCategory.Create("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Speech\\AudioOutput"))
            {
                if (objectTokenCategory == null)
                {
                    return(result);
                }
                string value;
                if (!objectTokenCategory.TryGetString("DefaultTokenId", out value))
                {
                    return(result);
                }
                int num = value.IndexOf('\\');
                if (num <= 0)
                {
                    return(result);
                }
                if (num < value.Length)
                {
                    using (RegistryDataKey registryDataKey = RegistryDataKey.Create(value.Substring(num + 1), Registry.LocalMachine))
                    {
                        if (registryDataKey != null)
                        {
                            return(AudioDeviceOut.GetDevicedId(registryDataKey.Name));
                        }
                        return(result);
                    }
                }
                return(result);
            }
        }
예제 #3
0
        /// <summary>
        /// Try to get the preferred token for a category
        /// </summary>
        private static ObjectToken GetPreference(string category, string defaultLocation)
        {
            ObjectToken token = null;

            using (ObjectTokenCategory tokenCategory = ObjectTokenCategory.Create(category))
            {
                if (tokenCategory != null)
                {
                    string sToken;
                    if (tokenCategory.TryGetString(defaultLocation, out sToken))
                    {
                        token = tokenCategory.OpenToken(sToken);
                    }
                }
            }
            return(token);
        }
예제 #4
0
        private static ObjectToken GetPreference(string category, string defaultLocation)
        {
            ObjectToken result = null;

            using (ObjectTokenCategory objectTokenCategory = ObjectTokenCategory.Create(category))
            {
                if (objectTokenCategory == null)
                {
                    return(result);
                }
                string value;
                if (objectTokenCategory.TryGetString(defaultLocation, out value))
                {
                    return(objectTokenCategory.OpenToken(value));
                }
                return(result);
            }
        }