예제 #1
0
        public void AppendText(string textToSpeak, PromptVolume volume)
        {
            Helpers.ThrowIfNull(textToSpeak, nameof(textToSpeak));

            if (volume < PromptVolume.NotSet || volume > PromptVolume.Default)
            {
                throw new ArgumentOutOfRangeException(nameof(volume));
            }

            // Validate that text can be added in this context
            ValidateElement(_elementStack.Peek(), SsmlElement.Text);

            Element prosodyElement = new(ElementType.Prosody, textToSpeak);

            _elements.Add(prosodyElement);

            string sVolumeLevel = null;

            switch (volume)
            {
            // No volume do not set the attribute
            case PromptVolume.NotSet:
                break;

            case PromptVolume.ExtraSoft:
                sVolumeLevel = "x-soft";
                break;

            case PromptVolume.ExtraLoud:
                sVolumeLevel = "x-loud";
                break;

            default:
                sVolumeLevel = volume.ToString().ToLowerInvariant();
                break;
            }
            if (!string.IsNullOrEmpty(sVolumeLevel))
            {
                prosodyElement._attributes = new Collection <AttributeItem>();
                prosodyElement._attributes.Add(new AttributeItem("volume", sVolumeLevel));
            }
        }
예제 #2
0
        public void AppendText(string textToSpeak, PromptVolume volume)
        {
            Helpers.ThrowIfNull(textToSpeak, "textToSpeak");
            if (volume < PromptVolume.NotSet || volume > PromptVolume.Default)
            {
                throw new ArgumentOutOfRangeException("volume");
            }
            ValidateElement(_elementStack.Peek(), SsmlElement.Text);
            Element element = new Element(ElementType.Prosody, textToSpeak);

            _elements.Add(element);
            string value = null;

            switch (volume)
            {
            case PromptVolume.ExtraSoft:
                value = "x-soft";
                break;

            case PromptVolume.ExtraLoud:
                value = "x-loud";
                break;

            default:
                value = volume.ToString().ToLowerInvariant();
                break;

            case PromptVolume.NotSet:
                break;
            }
            if (!string.IsNullOrEmpty(value))
            {
                element._attributes = new Collection <AttributeItem>();
                element._attributes.Add(new AttributeItem("volume", value));
            }
        }