1 out of 1 rated this helpful - Rate this topic

SpeechSynthesizer Class

Provides access to the functionality of an installed a speech synthesis engine.

System.Object
  System.Speech.Synthesis.SpeechSynthesizer

Namespace:  System.Speech.Synthesis
Assembly:  System.Speech (in System.Speech.dll)
public sealed class SpeechSynthesizer : IDisposable

The SpeechSynthesizer type exposes the following members.

  Name Description
Public method SpeechSynthesizer Initializes a new instance of the SpeechSynthesizer class.
Top
  Name Description
Public property Rate Gets or sets the speaking rate of the SpeechSynthesizer object.
Public property State Gets the speaking state of the SpeechSynthesizer object.
Public property Voice Gets information about the current voice of the SpeechSynthesizer object.
Public property Volume Get or sets the output volume of the SpeechSynthesizer object.
Top
  Name Description
Public method AddLexicon Adds a lexicon to the SpeechSynthesizer object.
Public method Dispose Disposes the SpeechSynthesizer object and releases resources used during the session.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetCurrentlySpokenPrompt Gets the contents of the prompt that the SpeechSynthesizer is speaking.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetInstalledVoices() Returns all of the installed speech synthesis (text-to-speech) voices.
Public method GetInstalledVoices(CultureInfo) Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Pause Pauses the speaking of a prompt by a SpeechSynthesizer object.
Public method RemoveLexicon Removes a lexicon from the SpeechSynthesizer object.
Public method Resume Resumes the speaking of a prompt by the SpeechSynthesizer object after it has been paused.
Public method SelectVoice Selects a specific voice by name.
Public method SelectVoiceByHints(VoiceGender) Selects a voice with a specific gender.
Public method SelectVoiceByHints(VoiceGender, VoiceAge) Selects a voice with a specific gender and age.
Public method SelectVoiceByHints(VoiceGender, VoiceAge, Int32) Selects a voice with a specific gender and age, based on the position in which the voices are ordered.
Public method SelectVoiceByHints(VoiceGender, VoiceAge, Int32, CultureInfo) Selects a voice with a specific gender, age, and locale, based on the position in which the voices are ordered.
Public method SetOutputToAudioStream Configures the SpeechSynthesizer object to append output to an audio stream.
Public method SetOutputToDefaultAudioDevice Configures the SpeechSynthesizer object to send output to the default audio device.
Public method SetOutputToNull Configures the SpeechSynthesizer object to not send output from synthesis operations to a device, file, or stream.
Public method SetOutputToWaveFile(String) Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio.
Public method SetOutputToWaveFile(String, SpeechAudioFormatInfo) Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format.
Public method SetOutputToWaveStream Configures the SpeechSynthesizer object to append output to a stream that contains Waveform format audio.
Public method Speak(Prompt) Synchronously speaks the contents of a Prompt object.
Public method Speak(PromptBuilder) Synchronously speaks the contents of a PromptBuilder object.
Public method Speak(String) Synchronously speaks the contents of a string.
Public method SpeakAsync(Prompt) Asynchronously speaks the contents of a Prompt object.
Public method SpeakAsync(PromptBuilder) Asynchronously speaks the contents of a PromptBuilder object.
Public method SpeakAsync(String) Asynchronously speaks the contents of a string.
Public method SpeakAsyncCancel Cancels the asynchronous synthesis operation for a queued prompt.
Public method SpeakAsyncCancelAll Cancels all queued, asynchronous, speech synthesis operations.
Public method SpeakSsml Synchronously speaks a String that contains SSML markup.
Public method SpeakSsmlAsync Asynchronously speaks a String that contains SSML markup.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public event BookmarkReached Raised when the SpeechSynthesizer encounters a bookmark in a prompt.
Public event PhonemeReached Raised when a phoneme is reached.
Public event SpeakCompleted Raised when the SpeechSynthesizer completes the speaking of a prompt.
Public event SpeakProgress Raised after the SpeechSynthesizer speaks each individual word of a prompt.
Public event SpeakStarted Raised when the SpeechSynthesizer begins the speaking of a prompt.
Public event StateChanged Raised when the state of the SpeechSynthesizer changes.
Public event VisemeReached Raised when a viseme is reached.
Public event VoiceChange Raised when the voice of the SpeechSynthesizer changes.
Top

When you create a new SpeechSynthesizer object, it uses the default system voice. To configure the SpeechSynthesizer to use one of the installed speech synthesis (text-to-speech) voices, use the SelectVoice or SelectVoiceByHints method. To get information about which voices are installed, use the GetInstalledVoices method and the VoiceInfo class.

This class also provides control over the following aspects of speech synthesis:

The SpeechSynthesizer raises events when it encounters certain features in prompts: (BookmarkReached, PhonemeReached, VisemeReached, and SpeakProgress). It also raises events that report on the start (SpeakStarted) and end (SpeakCompleted) of speak operations and on the change of the speaking voice (VoiceChange).

Note Note

Always call Dispose() before you release your last reference to the SpeechSynthesizer. Otherwise, the resources it is using will not be freed until the garbage collector calls the SpeechSynthesizer object's Finalize() method.

The following example is part of a console application that initializes a SpeechSynthesizer object and speaks a single prompt.

using System;
using System.Speech.Synthesis;

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

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

        // Configure the audio output.
        synthesizer.SetOutputToDefaultAudioDevice();

        // Build and speak a prompt.
        PromptBuilder builder = new PromptBuilder();
        builder.AppendText("This is a sample phrase.");
        synthesizer.Speak(builder);
      }

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

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ