示例#1
0
        public void SelectVoiceByHints(VoiceGender gender, VoiceAge age, int voiceAlternate, CultureInfo culture)
        {
            Helpers.ThrowIfNull(culture, nameof(culture));

            if (voiceAlternate < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(voiceAlternate), SR.Get(SRID.PromptBuilderInvalidVariant));
            }
            if (!VoiceInfo.ValidateGender(gender))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceGender"), nameof(gender));
            }

            if (!VoiceInfo.ValidateAge(age))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceAge"), nameof(age));
            }

            TTSVoice ttsVoice = VoiceSynthesizer.GetEngine(null, culture, gender, age, voiceAlternate, true);

            if (ttsVoice == null)
            {
                // No match - throw
                throw new InvalidOperationException(SR.Get(SRID.SynthesizerSetVoiceNoMatch));
            }
            VoiceSynthesizer.Voice = ttsVoice;
        }
示例#2
0
        public void StartVoice(VoiceInfo voice)
        {
            Helpers.ThrowIfNull(voice, nameof(voice));

            if (!VoiceInfo.ValidateGender(voice.Gender))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceGender"), nameof(voice));
            }

            if (!VoiceInfo.ValidateAge(voice.Age))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceAge"), nameof(voice));
            }

            StackElement stackElement = _elementStack.Peek();

            ValidateElement(stackElement, SsmlElement.Voice);

            CultureInfo culture = voice.Culture == null ? stackElement._culture : voice.Culture;

            Element startVoice = new(ElementType.StartVoice);

            startVoice._attributes = new Collection <AttributeItem>();
            _elements.Add(startVoice);

            if (!string.IsNullOrEmpty(voice.Name))
            {
                startVoice._attributes.Add(new AttributeItem("name", voice.Name));
            }

            if (voice.Culture != null)
            {
                startVoice._attributes.Add(new AttributeItem("xml", "lang", voice.Culture.Name));
            }

            if (voice.Gender != VoiceGender.NotSet)
            {
                startVoice._attributes.Add(new AttributeItem("gender", voice.Gender.ToString().ToLowerInvariant()));
            }

            if (voice.Age != VoiceAge.NotSet)
            {
                startVoice._attributes.Add(new AttributeItem("age", ((int)voice.Age).ToString(CultureInfo.InvariantCulture)));
            }

            if (voice.Variant >= 0)
            {
                startVoice._attributes.Add(new AttributeItem("variant", voice.Variant.ToString(CultureInfo.InvariantCulture)));
            }

            _elementStack.Push(new StackElement(SsmlElement.Sentence | SsmlElement.AudioMarkTextWithStyle, SsmlState.Voice, culture));
        }
示例#3
0
        public void StartVoice(VoiceInfo voice)
        {
            Helpers.ThrowIfNull(voice, "voice");
            if (!VoiceInfo.ValidateGender(voice.Gender))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceGender"), "voice");
            }
            if (!VoiceInfo.ValidateAge(voice.Age))
            {
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, "VoiceAge"), "voice");
            }
            StackElement stackElement = _elementStack.Peek();

            ValidateElement(stackElement, SsmlElement.Voice);
            CultureInfo culture = (voice.Culture == null) ? stackElement._culture : voice.Culture;
            Element     element = new Element(ElementType.StartVoice);

            element._attributes = new Collection <AttributeItem>();
            _elements.Add(element);
            if (!string.IsNullOrEmpty(voice.Name))
            {
                element._attributes.Add(new AttributeItem("name", voice.Name));
            }
            if (voice.Culture != null)
            {
                element._attributes.Add(new AttributeItem("xml", "lang", voice.Culture.Name));
            }
            if (voice.Gender != 0)
            {
                element._attributes.Add(new AttributeItem("gender", voice.Gender.ToString().ToLowerInvariant()));
            }
            if (voice.Age != 0)
            {
                element._attributes.Add(new AttributeItem("age", ((int)voice.Age).ToString(CultureInfo.InvariantCulture)));
            }
            if (voice.Variant >= 0)
            {
                element._attributes.Add(new AttributeItem("variant", voice.Variant.ToString(CultureInfo.InvariantCulture)));
            }
            _elementStack.Push(new StackElement(SsmlElement.Voice | SsmlElement.Audio | SsmlElement.Sentence | SsmlElement.SayAs | SsmlElement.Phoneme | SsmlElement.Sub | SsmlElement.Emphasis | SsmlElement.Break | SsmlElement.Prosody | SsmlElement.Mark | SsmlElement.Text | SsmlElement.PromptEngineOutput, SsmlState.Voice, culture));
        }