TtsEventId Enum

Definition

Enumerates types of speech synthesis events.

public enum class TtsEventId
public enum TtsEventId
type TtsEventId = 
Public Enum TtsEventId
Inheritance
TtsEventId

Fields

AudioLevel 9

Identifies events generated when a speech synthesize engine completes an audio level change while speaking.

Bookmark 4

Identifies events generated when a speech synthesize engine encounters a bookmark while speaking.

EndInputStream 2

Identifies events generated when a speech synthesize engine encounters the end of its input stream while speaking.

Phoneme 6

Identifies events generated when a speech synthesize engine completes a phoneme while speaking.

SentenceBoundary 7

Identifies events generated when a speech synthesize engine completes a sentence while speaking.

StartInputStream 1

Identifies events generated when a speech synthesize engine a begins speaking a stream.

Viseme 8

Identifies events generated when a speech synthesize engine completes a viseme while speaking.

VoiceChange 3

Identifies events generated when a speech synthesize engine encounters a change of Voice while speaking.

WordBoundary 5

Identifies events generated when a speech synthesize engine completes a word while speaking.

Examples

The following example is part of a custom speech synthesis implementation inheriting from TtsEngineSsml, and using the TextFragment, SpeechEventInfo, FragmentState, and TtsEventId classes.

The implementation of TtsEngineSsml.Speak includes the following steps:

  1. Receives an array of TextFragment instances and creates a new array of TextFragment instances to be passed to the Speak method on an underlying synthesis engine.

  2. If the Action property of each TextFragment.State instance is equal to TtsEngineAction.Speak, the code does the following:

    • Translates American English to British English in the text to be spoken.

    • If the ITtsEngineSite.EventInterest property provided to the implementation supports the WordBoundary event type, a SpeechEventInfo instance is used to create an event to drive a synthesizer progress meter is created.

  3. A speech rendering engine is then called with the modified TextFragment array.

private const int WordBoundaryFlag = 1 << (int)TtsEventId.WordBoundary;
private readonly char[] spaces = new char[] { ' ', '\t', '\r', '\n' };
internal struct UsVsUk
{
    internal string UK;
    internal string US;
}

override public void Speak (TextFragment [] frags, IntPtr wfx, ITtsEngineSite site)
{
    TextFragment [] newFrags=new TextFragment[frags.Length];
  
    for (int i=0;i<frags.Length;i++)
    {
        newFrags[i].State=frags[i].State;
        //truncate
        newFrags[i].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,
                                  frags[i].TextLength);
        newFrags[i].TextLength = newFrags[i].TextToSpeak.Length;
        newFrags[i].TextOffset = 0;
        if (newFrags[i].State.Action == TtsEngineAction.Speak)
        {
            //US to UK conversion
            foreach (UsVsUk term in TransList)
            {
              newFrags[i].TextToSpeak.Replace(term.US, term.UK);
            }
            //Generate progress meter events if supported
            if ((site.EventInterest & WordBoundaryFlag) != 0)
            {
                string[] subs = newFrags[i].TextToSpeak.Split(spaces);

                foreach (string s in subs)
                {
                    int offset = newFrags[i].TextOffset;
                    SpeechEventInfo spEvent = new SpeechEventInfo((Int16)TtsEventId.WordBoundary,
                        (Int16)EventParameterType.Undefined,
                        s.Length, new IntPtr(offset));
                    offset += s.Length;
                    if (s.Trim().Length > 0)
                    {
                        SpeechEventInfo[] events = new SpeechEventInfo[1];
                        events[0] = spEvent;
                        site.AddEvents(events, 1);
                    }
                }
            }
        }
    }

    _baseSynthesize.Speak(newFrags, wfx, site);

}

Remarks

Custom speech synthesis engines define the types of events submitted to the Speech platform synthesizer infrastructure with the TtsEventId.

Specification is performed by setting the EventId property of SpeechEventInfo instances passed to the AddEvents member of the class implementing the ITtsEngineSite interface passed to the Speak method on a custom speech engine's implementation of TtsEngineSsml.

The Speech platform infrastructure indicates the type of events it is currently handling through the EventInterest property on the ITtsEngineSite passed to the speak implementation.

The value of EventInterest is a bitmask, where the members of TtsEventId define the location of the bit corresponding to the event type. For example, WordBoundary has a value of five (5), meaning the fifth bit in the value returned by EventInterest indicates if the site supports the event type.

Applies to