SpeakProgressEventArgs Class

Returns data from the SpeakProgress event.

Namespace:  Microsoft.Speech.Synthesis
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

public class SpeakProgressEventArgs : PromptEventArgs

An instance of SpeakProgressEventArgs is created when the SpeechSynthesizer object raises the SpeakProgress event. The SpeechSynthesizer raises this event for each new word that it speaks in a prompt using any of the Speak(), SpeakAsync(), SpeakSsml(String), or SpeakSsmlAsync(String) methods.

The returned data is based on the Speech Synthesis Markup Language (SSML) that the code generates. The values returned for CharacterCount include spaces and the characters and contents of the SSML tags generated by the code.

The following example demonstrates the information that is available from SpeakProgressEventArgs. Note how the StartParagraph(), EndParagraph(), StartSentence(), and EndSentence() methods affect the CharacterCount by their addition of <p>, </p>, <s>, and </s> tags to the generated SSML. Also, there are two entries in the output for "30%", one for each word to speak this number string (thirty percent). The CharacterCount and CharacterPosition are the same for each entry and represent the characters "30%. However, the AudioPosition changes to reflect the speaking of the words "thirty" and "percent" by the SpeechSynthesizer.

using System;
using Microsoft.Speech.Synthesis;

namespace SampleSynthesis
  class Program
    static void Main(string[] args)

      // Initialize a new instance of the SpeechSynthesizer.
      using (SpeechSynthesizer synth = new SpeechSynthesizer())

        // Configure the audio output. 

        // Create a SoundPlayer instance to play the output audio file.
        System.Media.SoundPlayer m_SoundPlayer =
          new System.Media.SoundPlayer(@"C:\test\weather.wav");

        // Build a prompt containing a paragraph and two sentences.
        PromptBuilder builder = new PromptBuilder(
          new System.Globalization.CultureInfo("en-US"));
          "The weather forecast for today is partly cloudy with some sun breaks.");
          "Tonight's weather will be cloudy with a 30% chance of showers.");

        // Add a handler for the SpeakProgress event.
        synth.SpeakProgress +=
          new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);

        // Speak the prompt and play back the output file.

      Console.WriteLine("Press any key to exit...");

    // Write each word and its character postion to the console.
    static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
      Console.WriteLine("CharPos: {0}   CharCount: {1}   AudioPos: {2}    \"{3}\"",
        e.CharacterPosition, e.CharacterCount, e.AudioPosition, e.Text);

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.