SpeechEventInfo.ParameterType Property


Returns the data type of the object pointed to by the IntPtr returned by the Param2 parameter on the current SpeechEventInfo object.

Namespace:   System.Speech.Synthesis.TtsEngine
Assembly:  System.Speech (in System.Speech.dll)

public short ParameterType { get; internal set; }

Property Value

Type: System.Int16

A short value corresponding to a member of the EventParameterType enumeration and indicating the data type of the object pointed to by the IntPtr returned by the Param2 parameter and used as the second argument for the constructor of the current SpeechEventInfo object.

The requirements on the System.IntPtr reference of the Param2 property of SpeechEventInfo are uniquely determined by the values of the EventId and ParameterType properties the SpeechEventInfo instance.

For detailed information on how use Param2, see documentation for EventId.

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.

      The parameters on SpeechEventInfo, including ParameterType are used to log the event generated through the LogSpeechEvent method.

  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].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,
    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, 
                 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
Available since 3.0
Return to top