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

SpeechEventInfo Constructor

Constucts an appropriate SpeechEventInfo.

Namespace:  System.Speech.Synthesis.TtsEngine
Assembly:  System.Speech (in System.Speech.dll)
public SpeechEventInfo(
	short eventId,
	short parameterType,
	int param1,
	IntPtr param2
)

Parameters

eventId
Type: System.Int16

An instance of TtsEventId indicating the sort of Speech platform event the SpeechEventInfo object is to handle.

parameterType
Type: System.Int16

An instance of EventParameterType indicating how the System.IntPtr reference of param2 is to be interpreted, and, by implication, the use of param1.

param1
Type: System.Int32

An integer value to be passed to the Speech platform when the event requested by the instance of SpeechEventInfo to be constructed is generated.

The exact meaning of this integer is implicitly determined by the value of parameterType.

param2
Type: System.IntPtr

A System.IntPtr instance referencing an object. to be passed to the Speech platform when the event requested by the instance of SpeechEventInfo to be constructed is generated.

The type which must be referenced is explicitly defined by the value parameterType. The value System.IntPtr.Zero.

Permitted values used for parameterType, param1, and param2 and their meaning is dictated by the type of event being requested, as specified by the member of TtsEventId used for eventId.

For detailed information on appropriate values for parameterType, param1, and param2, see documentation for EventId

The type of the events which can be handled by the Speech platform infrastructure can be obtained through the EventInterest property on the synthesizer engine site implementation of ITtsEngineSite.

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.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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
Show:
© 2014 Microsoft. All rights reserved.