Partager via


Note

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

SpeechSynthesizer.State Property

Gets the speaking state of the SpeechSynthesizer object.

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

Syntax

'Declaration
Public ReadOnly Property State As SynthesizerState
    Get
'Usage
Dim instance As SpeechSynthesizer
Dim value As SynthesizerState

value = instance.State
public SynthesizerState State { get; }

Property Value

Type: Microsoft.Speech.Synthesis.SynthesizerState
Returns the speaking state of the SpeechSynthesizer object.

Remarks

To pause and resume speech synthesis, use the Pause and Resume methods.

Examples

using System;
using System.Threading;
using Microsoft.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 text 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);
    }
  }
}

See Also

Reference

SpeechSynthesizer Class

SpeechSynthesizer Members

Microsoft.Speech.Synthesis Namespace