Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TtsEventId Enumeration

Enumerates types of speech synthesis events.

Namespace:  System.Speech.Synthesis.TtsEngine
Assembly:  System.Speech (in System.Speech.dll)
public enum TtsEventId
Member nameDescription
StartInputStreamIdentifies events generated when a speech synthesize engine a begins speaking a stream.
EndInputStreamIdentifies events generated when a speech synthesize engine encounters the end of its input stream while speaking.
VoiceChangeIdentifies events generated when a speech synthesize engine encounters a change of Voice while speaking.
BookmarkIdentifies events generated when a speech synthesize engine encounters a bookmark while speaking.
WordBoundaryIdentifies events generated when a speech synthesize engine completes a word while speaking.
PhonemeIdentifies events generated when a speech synthesize engine completes a phoneme while speaking.
SentenceBoundaryIdentifies events generated when a speech synthesize engine completes a sentence while speaking.
VisemeIdentifies events generated when a speech synthesize engine completes a viseme while speaking.
AudioLevelIdentifies events generated when a speech synthesize engine completes an audio level change while speaking.

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.

The example below is part of a custom speech synthesis implementation inheriting from TtsEngineSsml, and using the use of TextFragment, SpeechEventInfo, FragmentState, and TtsEventID

The implementation of Speak()

  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 TtsEngineAction enumeration value by found from the Action property on the FragmentState returned by the State property of each TextFragment instance is Speak, the implementation

    • Translates Americanism to Britishisms in the text to be spoken.

    • If the EventInterest property on the ITtsEngineSite interfaces provided to the implementation support 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);
  
}

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.