Condividi tramite


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

SpeakProgressEventArgs.Text Property

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

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

Syntax

'Declaration
Public Property Text As String
    Get
    Friend Set
'Usage
Dim instance As SpeakProgressEventArgs
Dim value As String

value = instance.Text
public string Text { get; internal set; }

Property Value

Type: System.String
Returns the text that was just spoken when the event was raised.

Remarks

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.

Examples

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

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. 
        synth.SetOutputToWaveFile(@"C:\test\TextNumber.wav");

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

        // Create a PromptBuilder and append a number as a string.
        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);
        m_SoundPlayer.Play();
      }

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

See Also

Reference

SpeakProgressEventArgs Class

SpeakProgressEventArgs Members

Microsoft.Speech.Synthesis Namespace