SpeechSynthesizer.SpeakAsync Method (PromptBuilder)

Asynchronously speaks the contents of a PromptBuilder object.

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


Public Function SpeakAsync ( _
    promptBuilder As PromptBuilder _
) As Prompt
Dim instance As SpeechSynthesizer
Dim promptBuilder As PromptBuilder
Dim returnValue As Prompt

returnValue = instance.SpeakAsync(promptBuilder)
public Prompt SpeakAsync(
    PromptBuilder promptBuilder


Return Value

Type: Microsoft.Speech.Synthesis.Prompt
Returns the object that contains the content to speak.


To synchronously speak the contents of a PromptBuilder object, use Speak(PromptBuilder).


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

using System;
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. 

      // Register for the SpeakCompleted event.
      synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);

      // Create a PromptBuilder object and append a text string.
      PromptBuilder song = new PromptBuilder();
      song.AppendText("Say the name of the song you want to hear");

      // Speak the contents of the prompt asynchronously.

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

    // Handle the SpeakCompleted event.
    static void synth_SpeakCompleted(object sender, SpeakCompletedEventArgs e)

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

      //  Play the output file.

See Also


SpeechSynthesizer Class

SpeechSynthesizer Members

SpeakAsync Overload

Microsoft.Speech.Synthesis Namespace