SpeechSynthesizer.SpeakAsync Method (Prompt)

 

Asynchronously speaks the contents of a Prompt object.

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

public void SpeakAsync(
	Prompt prompt
)

Parameters

prompt
Type: System.Speech.Synthesis.Prompt

The content to speak.

You can cancel the asynchronous speaking of a prompt with the SpeakAsyncCancel or the SpeakAsyncCancelAll method.

To synchronously speak the contents of a Prompt object, use Speak.

The following example creates a Prompt object from a string and passes the object as an argument to the SpeakAsync method.

using System;
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();

      // Create a prompt from a string.
      Prompt color = new Prompt("What is your favorite color?");

      // Speak the contents of the prompt asynchronously.
      synth.SpeakAsync(color);

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


.NET Framework
Available since 3.0
Return to top
Show: