コード例 #1
0
 /// <summary>
 /// Ensure the this element is properly placed in the SSML markup
 /// </summary>
 private static void ValidateElement(StackElement stackElement, SsmlElement currentElement)
 {
     if ((stackElement._possibleChildren & currentElement) == 0)
     {
         throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, SR.Get(SRID.PromptBuilderInvalidElement), currentElement.ToString(), stackElement._state.ToString()));
     }
 }
コード例 #2
0
        public void StartStyle(PromptStyle style)
        {
            Helpers.ThrowIfNull(style, nameof(style));

            // Validate that text can be added in this context
            StackElement stackElement = _elementStack.Peek();

            ValidateElement(stackElement, SsmlElement.Prosody);

            // For emphasis or Prosody the list of possible elements that can be children is different.
            SsmlState   ssmlState        = 0;
            SsmlElement possibleChildren = stackElement._possibleChildren;

            _elements.Add(new Element(ElementType.StartStyle));

            if (style.Emphasis != PromptEmphasis.NotSet)
            {
                Element emphasisElement = new(ElementType.Emphasis);
                _elements.Add(emphasisElement);

                emphasisElement._attributes = new Collection <AttributeItem>();
                emphasisElement._attributes.Add(new AttributeItem("level", style.Emphasis.ToString().ToLowerInvariant()));

                // Set the expected children and mark the element used
                possibleChildren = SsmlElement.AudioMarkTextWithStyle;
                ssmlState        = SsmlState.StyleEmphasis;
            }

            if (style.Rate != PromptRate.NotSet || style.Volume != PromptVolume.NotSet)
            {
                // two elements add a second start style
                if (ssmlState != 0)
                {
                    _elements.Add(new Element(ElementType.StartStyle));
                }

                Element prosodyElement = new(ElementType.Prosody);
                _elements.Add(prosodyElement);

                if (style.Rate != PromptRate.NotSet)
                {
                    string sPromptRate;
                    switch (style.Rate)
                    {
                    case PromptRate.ExtraFast:
                        sPromptRate = "x-fast";
                        break;

                    case PromptRate.ExtraSlow:
                        sPromptRate = "x-slow";
                        break;

                    default:
                        sPromptRate = style.Rate.ToString().ToLowerInvariant();
                        break;
                    }
                    prosodyElement._attributes = new Collection <AttributeItem>();
                    prosodyElement._attributes.Add(new AttributeItem("rate", sPromptRate));
                }

                if (style.Volume != PromptVolume.NotSet)
                {
                    string sVolumeLevel;
                    switch (style.Volume)
                    {
                    case PromptVolume.ExtraSoft:
                        sVolumeLevel = "x-soft";
                        break;

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

                    default:
                        sVolumeLevel = style.Volume.ToString().ToLowerInvariant();
                        break;
                    }
                    if (prosodyElement._attributes == null)
                    {
                        prosodyElement._attributes = new Collection <AttributeItem>();
                    }
                    prosodyElement._attributes.Add(new AttributeItem("volume", sVolumeLevel));
                }

                // Set the expected children and mark the element used
                possibleChildren = SsmlElement.ParagraphOrSentence | SsmlElement.AudioMarkTextWithStyle;
                ssmlState       |= SsmlState.StyleProsody;
            }

            _elementStack.Push(new StackElement(possibleChildren, ssmlState, stackElement._culture));
        }
コード例 #3
0
 internal StackElement(SsmlElement possibleChildren, SsmlState state, CultureInfo culture)
 {
     _possibleChildren = possibleChildren;
     _state            = state;
     _culture          = culture;
 }
コード例 #4
0
        public void StartStyle(PromptStyle style)
        {
            Helpers.ThrowIfNull(style, "style");
            StackElement stackElement = _elementStack.Peek();

            ValidateElement(stackElement, SsmlElement.Prosody);
            SsmlState   ssmlState        = (SsmlState)0;
            SsmlElement possibleChildren = stackElement._possibleChildren;

            _elements.Add(new Element(ElementType.StartStyle));
            if (style.Emphasis != 0)
            {
                Element element = new Element(ElementType.Emphasis);
                _elements.Add(element);
                element._attributes = new Collection <AttributeItem>();
                element._attributes.Add(new AttributeItem("level", style.Emphasis.ToString().ToLowerInvariant()));
                possibleChildren = SsmlElement.AudioMarkTextWithStyle;
                ssmlState        = SsmlState.StyleEmphasis;
            }
            if (style.Rate != 0 || style.Volume != 0)
            {
                if (ssmlState != 0)
                {
                    _elements.Add(new Element(ElementType.StartStyle));
                }
                Element element2 = new Element(ElementType.Prosody);
                _elements.Add(element2);
                if (style.Rate != 0)
                {
                    string value;
                    switch (style.Rate)
                    {
                    case PromptRate.ExtraFast:
                        value = "x-fast";
                        break;

                    case PromptRate.ExtraSlow:
                        value = "x-slow";
                        break;

                    default:
                        value = style.Rate.ToString().ToLowerInvariant();
                        break;
                    }
                    element2._attributes = new Collection <AttributeItem>();
                    element2._attributes.Add(new AttributeItem("rate", value));
                }
                if (style.Volume != 0)
                {
                    string value2;
                    switch (style.Volume)
                    {
                    case PromptVolume.ExtraSoft:
                        value2 = "x-soft";
                        break;

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

                    default:
                        value2 = style.Volume.ToString().ToLowerInvariant();
                        break;
                    }
                    if (element2._attributes == null)
                    {
                        element2._attributes = new Collection <AttributeItem>();
                    }
                    element2._attributes.Add(new AttributeItem("volume", value2));
                }
                possibleChildren = (SsmlElement.Voice | SsmlElement.Audio | SsmlElement.Sentence | SsmlElement.Paragraph | SsmlElement.SayAs | SsmlElement.Phoneme | SsmlElement.Sub | SsmlElement.Emphasis | SsmlElement.Break | SsmlElement.Prosody | SsmlElement.Mark | SsmlElement.Text | SsmlElement.PromptEngineOutput);
                ssmlState       |= SsmlState.StyleProsody;
            }
            _elementStack.Push(new StackElement(possibleChildren, ssmlState, stackElement._culture));
        }