Beispiel #1
0
 /// <summary>Filter voices by language.</summary>
 static InstalledVoiceEx[] FilterVoicesByGender(InstalledVoiceEx[] voices, MessageGender gender)
 {
     if (gender == MessageGender.Male)
     {
         return(voices.Where(x => x.Male > 0).ToArray());
     }
     else if (gender == MessageGender.Female)
     {
         return(voices.Where(x => x.Female > 0).ToArray());
     }
     else
     {
         return(voices.Where(x => x.Neutral > 0).ToArray());
     }
 }
Beispiel #2
0
 /// <summary>Reorder voices by gender.</summary>
 static void OrderVoicesByGender(ref InstalledVoiceEx[] voices, MessageGender gender)
 {
     if (gender == MessageGender.Male)
     {
         voices = voices.OrderByDescending(x => x.Male).ToArray();
     }
     else if (gender == MessageGender.Female)
     {
         voices = voices.OrderByDescending(x => x.Female).ToArray();
     }
     else
     {
         voices = voices.OrderByDescending(x => x.Neutral).ToArray();
     }
 }
Beispiel #3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (MessageName.Length != 0)
            {
                hash ^= MessageName.GetHashCode();
            }
            if (MessageGender.Length != 0)
            {
                hash ^= MessageGender.GetHashCode();
            }
            if (MessageAge.Length != 0)
            {
                hash ^= MessageAge.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #4
0
        // Set voice.
        static InstalledVoiceEx SelectVoice(string name, string language, MessageGender gender)
        {
            // Get only enabled voices.
            var data = InstalledVoices.Where(x => x.Enabled).ToArray();
            InstalledVoiceEx voice = null;
            var culture            = Capturing.message.GetCultureInfo(language);

            // Order voices by putting matching gender with highest value first.
            OrderVoicesByGender(ref data, gender);
            var missing = "";

            missing += "There are no voices enabled in \"{0}\" column with value \"{1}\". ";
            missing += "Set popularity value to 100 ( normal usage ) or 101 ( normal usage / favourite ) for at least one voice.";
            // Initial choice will be all enabled voices.
            InstalledVoiceEx[] choice = data;
            InstalledVoiceEx[] tmp;
            // If voice name was supplied then...
            if (!string.IsNullOrEmpty(name))
            {
                // Select voices by name if exists ("IVONA 2 Amy").
                tmp = data.Where(x => string.Equals(x.Name, name, StringComparison.InvariantCulture)).ToArray();
                // If choice available then...
                if (tmp.Length > 0)
                {
                    choice = tmp;
                }
                else
                {
                    OnHelp(missing, "Name", name);
                }
            }
            // Filter by gender (more important than by culture).
            tmp = FilterVoicesByGender(choice, gender);
            // If choice available then...
            if (tmp.Length > 0)
            {
                choice = tmp;
            }
            else
            {
                OnHelp(missing, "Gender", gender);
                // Order by Male as default.
                OrderVoicesByGender(ref data, MessageGender.Male);
            }
            // If culture supplied.
            if (culture != null)
            {
                tmp = FilterVoicesByCulture(choice, culture);
                // If choice available then...
                if (tmp.Length > 0)
                {
                    choice = tmp;
                }
                else
                {
                    OnHelp(missing, "Culture", language);
                }
            }
            // If nothing to choose from then...
            if (choice.Length == 0)
            {
                return(null);
            }
            // Generate number for selecting voice.
            var number = MainHelper.GetNumber(0, choice.Length - 1, "name", name);

            voice = choice[number];
            if (SelectedVoice != voice)
            {
                OnEvent(VoiceChanged, voice);
            }
            return(voice);
        }