Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SpeechSynthesizer.Speak Method (PromptBuilder)

Synchronously speaks the contents of a PromptBuilder object.

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

public void Speak(
	PromptBuilder promptBuilder


Type: Microsoft.Speech.Synthesis.PromptBuilder
The content to speak.

To asynchronously speak the contents of a PromptBuilder object, use SpeakAsync(PromptBuilder).

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

using System;
using Microsoft.Speech.Synthesis;

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

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

        // Configure the audio output. 

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

        // 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 synchronously and play the output file.

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

© 2017 Microsoft