SpeechSynthesizer SpeechSynthesizer SpeechSynthesizer SpeechSynthesizer Class

Definition

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

public ref class SpeechSynthesizer sealed : IDisposable
public sealed class SpeechSynthesizer : IDisposable
type SpeechSynthesizer = class
    interface IDisposable
Public NotInheritable Class SpeechSynthesizer
Implements IDisposable
Inheritance
SpeechSynthesizerSpeechSynthesizerSpeechSynthesizerSpeechSynthesizer
Implements

Examples

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


using System;  
using System.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.   
      synth.SetOutputToDefaultAudioDevice();  

      // Speak a string.  
      synth.Speak("This example demonstrates a basic use of Speech Synthesizer");  

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

Remarks

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

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.

Constructors

SpeechSynthesizer() SpeechSynthesizer() SpeechSynthesizer() SpeechSynthesizer()

Initializes a new instance of the SpeechSynthesizer class.

Properties

Rate Rate Rate Rate

Gets or sets the speaking rate of the SpeechSynthesizer object.

State State State State

Gets the current speaking state of the SpeechSynthesizer object.

Voice Voice Voice Voice

Gets information about the current voice of the SpeechSynthesizer object.

Volume Volume Volume Volume

Get or sets the output volume of the SpeechSynthesizer object.

Methods

AddLexicon(Uri, String) AddLexicon(Uri, String) AddLexicon(Uri, String) AddLexicon(Uri, String)

Adds a lexicon to the SpeechSynthesizer object.

Dispose() Dispose() Dispose() Dispose()

Disposes the SpeechSynthesizer object and releases resources used during the session.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

Acts as a safeguard to clean up resources in the event that the Dispose() method is not called.

GetCurrentlySpokenPrompt() GetCurrentlySpokenPrompt() GetCurrentlySpokenPrompt() GetCurrentlySpokenPrompt()

Gets the prompt that the SpeechSynthesizer is speaking.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetInstalledVoices() GetInstalledVoices() GetInstalledVoices() GetInstalledVoices()

Returns all of the installed speech synthesis (text-to-speech) voices.

GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo)

Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Pause() Pause() Pause() Pause()

Pauses the SpeechSynthesizer object.

RemoveLexicon(Uri) RemoveLexicon(Uri) RemoveLexicon(Uri) RemoveLexicon(Uri)

Removes a lexicon from the SpeechSynthesizer object.

Resume() Resume() Resume() Resume()

Resumes the SpeechSynthesizer object after it has been paused.

SelectVoice(String) SelectVoice(String) SelectVoice(String) SelectVoice(String)

Selects a specific voice by name.

SelectVoiceByHints(VoiceGender) SelectVoiceByHints(VoiceGender) SelectVoiceByHints(VoiceGender) SelectVoiceByHints(VoiceGender)

Selects a voice with a specific gender.

SelectVoiceByHints(VoiceGender, VoiceAge) SelectVoiceByHints(VoiceGender, VoiceAge) SelectVoiceByHints(VoiceGender, VoiceAge) SelectVoiceByHints(VoiceGender, VoiceAge)

Selects a voice with a specific gender and age.

SelectVoiceByHints(VoiceGender, VoiceAge, Int32) SelectVoiceByHints(VoiceGender, VoiceAge, Int32) SelectVoiceByHints(VoiceGender, VoiceAge, Int32) 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) SelectVoiceByHints(VoiceGender, VoiceAge, Int32, CultureInfo) SelectVoiceByHints(VoiceGender, VoiceAge, Int32, CultureInfo) 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(Stream, SpeechAudioFormatInfo) SetOutputToAudioStream(Stream, SpeechAudioFormatInfo) SetOutputToAudioStream(Stream, SpeechAudioFormatInfo) SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)

Configures the SpeechSynthesizer object to append output to an audio stream.

SetOutputToDefaultAudioDevice() SetOutputToDefaultAudioDevice() SetOutputToDefaultAudioDevice() SetOutputToDefaultAudioDevice()

Configures the SpeechSynthesizer object to send output to the default audio device.

SetOutputToNull() SetOutputToNull() SetOutputToNull() SetOutputToNull()

Configures the SpeechSynthesizer object to not send output from synthesis operations to a device, file, or stream.

SetOutputToWaveFile(String) SetOutputToWaveFile(String) SetOutputToWaveFile(String) SetOutputToWaveFile(String)

Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio.

SetOutputToWaveFile(String, SpeechAudioFormatInfo) SetOutputToWaveFile(String, SpeechAudioFormatInfo) SetOutputToWaveFile(String, SpeechAudioFormatInfo) SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format.

SetOutputToWaveStream(Stream) SetOutputToWaveStream(Stream) SetOutputToWaveStream(Stream) SetOutputToWaveStream(Stream)

Configures the SpeechSynthesizer object to append output to a stream that contains Waveform format audio.

Speak(Prompt) Speak(Prompt) Speak(Prompt) Speak(Prompt)

Synchronously speaks the contents of a Prompt object.

Speak(PromptBuilder) Speak(PromptBuilder) Speak(PromptBuilder) Speak(PromptBuilder)

Synchronously speaks the contents of a PromptBuilder object.

Speak(String) Speak(String) Speak(String) Speak(String)

Synchronously speaks the contents of a string.

SpeakAsync(Prompt) SpeakAsync(Prompt) SpeakAsync(Prompt) SpeakAsync(Prompt)

Asynchronously speaks the contents of a Prompt object.

SpeakAsync(PromptBuilder) SpeakAsync(PromptBuilder) SpeakAsync(PromptBuilder) SpeakAsync(PromptBuilder)

Asynchronously speaks the contents of a PromptBuilder object.

SpeakAsync(String) SpeakAsync(String) SpeakAsync(String) SpeakAsync(String)

Asynchronously speaks the contents of a string.

SpeakAsyncCancel(Prompt) SpeakAsyncCancel(Prompt) SpeakAsyncCancel(Prompt) SpeakAsyncCancel(Prompt)

Cancels the asynchronous synthesis operation for a queued prompt.

SpeakAsyncCancelAll() SpeakAsyncCancelAll() SpeakAsyncCancelAll() SpeakAsyncCancelAll()

Cancels all queued, asynchronous, speech synthesis operations.

SpeakSsml(String) SpeakSsml(String) SpeakSsml(String) SpeakSsml(String)

Synchronously speaks a String that contains SSML markup.

SpeakSsmlAsync(String) SpeakSsmlAsync(String) SpeakSsmlAsync(String) SpeakSsmlAsync(String)

Asynchronously speaks a String that contains SSML markup.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Events

BookmarkReached BookmarkReached BookmarkReached BookmarkReached

Raised when the SpeechSynthesizer encounters a bookmark in a prompt.

PhonemeReached PhonemeReached PhonemeReached PhonemeReached

Raised when a phoneme is reached.

SpeakCompleted SpeakCompleted SpeakCompleted SpeakCompleted

Raised when the SpeechSynthesizer completes the speaking of a prompt.

SpeakProgress SpeakProgress SpeakProgress SpeakProgress

Raised after the SpeechSynthesizer speaks each individual word of a prompt.

SpeakStarted SpeakStarted SpeakStarted SpeakStarted

Raised when the SpeechSynthesizer begins the speaking of a prompt.

StateChanged StateChanged StateChanged StateChanged

Raised when the state of the SpeechSynthesizer changes.

VisemeReached VisemeReached VisemeReached VisemeReached

Raised when a viseme is reached.

VoiceChange VoiceChange VoiceChange VoiceChange

Raised when the voice of the SpeechSynthesizer changes.

Applies to

See Also