SpeechSynthesizer.Speak Method (PromptBuilder)

Synchronously speaks the contents of a PromptBuilder object.

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

Syntax

'Declaration
Public Sub Speak ( _
    promptBuilder As PromptBuilder _
)
'Usage
Dim instance As SpeechSynthesizer
Dim promptBuilder As PromptBuilder

instance.Speak(promptBuilder)
public void Speak(
    PromptBuilder promptBuilder
)

Parameters

Remarks

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

Examples

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. 
        synth.SetOutputToWaveFile(@"C:\Test\Song.wav");

        // 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.
        synth.Speak(song);
        m_SoundPlayer.Play();
      }

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

See Also

Reference

SpeechSynthesizer Class

SpeechSynthesizer Members

Speak Overload

Microsoft.Speech.Synthesis Namespace