SpeakProgressEventArgs.Text Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

The text that was just spoken when the event was raised.

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

public string Text { get; internal set; }

Property Value

Type: System.String

Returns the text that was just spoken when the event was raised.

The SpeechSynthesizer normalizes numbers to the words that correspond to how the number will be spoken. For example, the synthesizer speaks the number “4003” as “four thousand three”. It raises a SpeakProgress event for each of the spoken words. However, the Text property for each of the three words is the same. It is the text “4003” from the prompt.

The following example illustrates the how the SpeakProgress event reports the CharacterPosition and Text properties for strings that contain numbers.

using System;
using System.Xml;
using System.IO;
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.SetOutputToDefaultAudioDevice();

        // Create an XML Reader from the file, create a PromptBuilder and 
        // append the XmlReader.
        PromptBuilder builder = new PromptBuilder();
        builder.AppendText("4003");

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

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

    // Write each word and its character position to the console.
    static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
    {
      Console.WriteLine("Speak progress -    Character position:  {0}    Text:  {1}",
        e.CharacterPosition, e.Text);
    }
  }
}

.NET Framework
Available since 3.0
Return to top
Show: