SpeechSynthesizer Class
Provides access to the functionality of an installed a speech synthesis engine.
Assembly: System.Speech (in System.Speech.dll)
The SpeechSynthesizer type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | AddLexicon | Adds a lexicon to the SpeechSynthesizer object. |
![]() | Dispose | Disposes the SpeechSynthesizer object and releases resources used during the session. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetCurrentlySpokenPrompt | Gets the contents of the prompt that the SpeechSynthesizer is speaking. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetInstalledVoices() | Returns all of the installed speech synthesis (text-to-speech) voices. |
![]() | GetInstalledVoices(CultureInfo) | Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale. |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | Pause | Pauses the speaking of a prompt by a SpeechSynthesizer object. |
![]() | RemoveLexicon | Removes a lexicon from the SpeechSynthesizer object. |
![]() | Resume | Resumes the speaking of a prompt by the SpeechSynthesizer object after it has been paused. |
![]() | SelectVoice | Selects a specific voice by name. |
![]() | SelectVoiceByHints(VoiceGender) | Selects a voice with a specific gender. |
![]() | SelectVoiceByHints(VoiceGender, VoiceAge) | Selects a voice with a specific gender and age. |
![]() | SelectVoiceByHints(VoiceGender, VoiceAge, Int32) | Selects a voice with a specific gender and age, based on the position in which the voices are ordered. |
![]() | 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. |
![]() | SetOutputToAudioStream | Configures the SpeechSynthesizer object to append output to an audio stream. |
![]() | SetOutputToDefaultAudioDevice | Configures the SpeechSynthesizer object to send output to the default audio device. |
![]() | SetOutputToNull | Configures the SpeechSynthesizer object to not send output from synthesis operations to a device, file, or stream. |
![]() | SetOutputToWaveFile(String) | Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio. |
![]() | SetOutputToWaveFile(String, SpeechAudioFormatInfo) | Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format. |
![]() | SetOutputToWaveStream | Configures the SpeechSynthesizer object to append output to a stream that contains Waveform format audio. |
![]() | Speak(Prompt) | Synchronously speaks the contents of a Prompt object. |
![]() | Speak(PromptBuilder) | Synchronously speaks the contents of a PromptBuilder object. |
![]() | Speak(String) | Synchronously speaks the contents of a string. |
![]() | SpeakAsync(Prompt) | Asynchronously speaks the contents of a Prompt object. |
![]() | SpeakAsync(PromptBuilder) | Asynchronously speaks the contents of a PromptBuilder object. |
![]() | SpeakAsync(String) | Asynchronously speaks the contents of a string. |
![]() | SpeakAsyncCancel | Cancels the asynchronous synthesis operation for a queued prompt. |
![]() | SpeakAsyncCancelAll | Cancels all queued, asynchronous, speech synthesis operations. |
![]() | SpeakSsml | Synchronously speaks a String that contains SSML markup. |
![]() | SpeakSsmlAsync | Asynchronously speaks a String that contains SSML markup. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | BookmarkReached | Raised when the SpeechSynthesizer encounters a bookmark in a prompt. |
![]() | PhonemeReached | Raised when a phoneme is reached. |
![]() | SpeakCompleted | Raised when the SpeechSynthesizer completes the speaking of a prompt. |
![]() | SpeakProgress | Raised after the SpeechSynthesizer speaks each individual word of a prompt. |
![]() | SpeakStarted | Raised when the SpeechSynthesizer begins the speaking of a prompt. |
![]() | StateChanged | Raised when the state of the SpeechSynthesizer changes. |
![]() | VisemeReached | Raised when a viseme is reached. |
![]() | VoiceChange | Raised when the voice of the SpeechSynthesizer changes. |
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:
To configure the output for the SpeechSynthesizer object, use the SetOutputToAudioStream, SetOutputToDefaultAudioDevice, SetOutputToNull, and SetOutputToWaveFile methods.
To generate speech, use the Speak, SpeakAsync, SpeakSsml, or SpeakSsmlAsync method. The SpeechSynthesizer can produce speech from text, a Prompt or PromptBuilder object, or from Speech Synthesis Markup Language (SSML) Version 1.0.
To pause and resume speech synthesis, use the Pause and Resume methods.
To add or remove lexicons, use the AddLexicon and RemoveLexicon methods. The SpeechSynthesizer can use one or more lexicons to guide its pronunciation of words.
To modify the delivery of speech output, use the Rate and Volume properties.
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 |
|---|
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(); } } }
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.
