Export (0) Print
Expand All

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

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft