SpeechSynthesizer.State Property

Definition

Gets the current speaking state of the SpeechSynthesizer object.

public System.Speech.Synthesis.SynthesizerState State { get; }

Property Value

Returns the current speaking state of the SpeechSynthesizer object.

Examples

The following example illustrates the state of the SpeechSynthesizer before, during, and after speaking a prompt.

using System;
using System.Threading;
using System.Speech.Synthesis;

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

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

      // Configure the audio output.
      synth.SetOutputToDefaultAudioDevice();

      // Subscribe to the SpeakProgress event.
      synth.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);

      // Write the state of the SpeechSynthesizer to the console.
      Console.WriteLine("Current Synthesizer state: " + synth.State + "\n");

      // Speak a string asynchronously.
      synth.SpeakAsync("What is your favorite color?");

      // Write the state of the SpeechSynthesizer to the console while it is speaking.
      Thread.Sleep(1000);
      Console.WriteLine("\n - Current Synthesizer state: " + synth.State + " - \n");

      // Write the state of the SpeechSynthesizer to the console after it is done speaking.
      Thread.Sleep(2000);
      Console.WriteLine("\nCurrent Synthesizer state: " + synth.State);

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

    static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
    {
      Console.WriteLine(e.Text);
    }
  }
}

Remarks

To get the new state of the SpeechSynthesizer after it changes, use the State property of the StateChangedEventArgs class.

Applies to

Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)