Export (0) Print
Expand All

SpeakProgressEventArgs Class

Returns data from the SpeakProgress event.

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

public class SpeakProgressEventArgs : PromptEventArgs

The SpeakProgressEventArgs type exposes the following members.

  NameDescription
Public propertyAudioPositionGets the audio position of the event.
Public propertyCancelledGets a value indicating whether an asynchronous operation has been canceled. (Inherited from AsyncCompletedEventArgs.)
Public propertyCharacterCountGets the number of characters in the word that was spoken just before the event was raised.
Public propertyCharacterPositionGets the number of characters and spaces from the beginning of the prompt to the position before the first letter of the word that was just spoken.
Public propertyErrorGets a value indicating which error occurred during an asynchronous operation. (Inherited from AsyncCompletedEventArgs.)
Public propertyPromptGets the prompt associated with the event. (Inherited from PromptEventArgs.)
Public propertyTextThe text that was just spoken when the event was raised.
Public propertyUserStateGets the unique identifier for the asynchronous task. (Inherited from AsyncCompletedEventArgs.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodRaiseExceptionIfNecessaryRaises a user-supplied exception if an asynchronous operation failed. (Inherited from AsyncCompletedEventArgs.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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, or SpeakSsmlAsync 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 System.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. 
        synth.SetOutputToWaveFile(@"C:\test\weather.wav");

        // 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"));
        builder.StartParagraph();
        builder.StartSentence();
        builder.AppendText(
          "The weather forecast for today is partly cloudy with some sun breaks.");
        builder.EndSentence();
        builder.StartSentence();
        builder.AppendText(
          "Tonight's weather will be cloudy with a 30% chance of showers.");
        builder.EndSentence();
        builder.EndParagraph();

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

        // Speak the prompt and play back the output file.
        synth.Speak(builder);
        m_SoundPlayer.Play();
      }

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

    // 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);
    }
  }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

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.

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