Export (0) Print
Expand All

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)

[<Sealed>]
type SpeechSynthesizer =  
    class 
        interface IDisposable 
    end

The SpeechSynthesizer type exposes the following members.

  NameDescription
Public methodSpeechSynthesizerInitializes a new instance of the SpeechSynthesizer class.
Top

  NameDescription
Public propertyRateGets or sets the speaking rate of the SpeechSynthesizer object.
Public propertyStateGets the current speaking state of the SpeechSynthesizer object.
Public propertyVoiceGets information about the current voice of the SpeechSynthesizer object.
Public propertyVolumeGet or sets the output volume of the SpeechSynthesizer object.
Top

  NameDescription
Public methodAddLexiconAdds a lexicon to the SpeechSynthesizer object.
Public methodDisposeDisposes the SpeechSynthesizer object and releases resources used during the session.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetCurrentlySpokenPromptGets the prompt that the SpeechSynthesizer is speaking.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetInstalledVoices()Returns all of the installed speech synthesis (text-to-speech) voices.
Public methodGetInstalledVoices(CultureInfo)Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodPausePauses the SpeechSynthesizer object.
Public methodRemoveLexiconRemoves a lexicon from the SpeechSynthesizer object.
Public methodResumeResumes the SpeechSynthesizer object after it has been paused.
Public methodSelectVoiceSelects a specific voice by name.
Public methodSelectVoiceByHints(VoiceGender)Selects a voice with a specific gender.
Public methodSelectVoiceByHints(VoiceGender, VoiceAge)Selects a voice with a specific gender and age.
Public methodSelectVoiceByHints(VoiceGender, VoiceAge, Int32)Selects a voice with a specific gender and age, based on the position in which the voices are ordered.
Public methodSelectVoiceByHints(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 methodSetOutputToAudioStreamConfigures the SpeechSynthesizer object to append output to an audio stream.
Public methodSetOutputToDefaultAudioDeviceConfigures the SpeechSynthesizer object to send output to the default audio device.
Public methodSetOutputToNullConfigures the SpeechSynthesizer object to not send output from synthesis operations to a device, file, or stream.
Public methodSetOutputToWaveFile(String)Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio.
Public methodSetOutputToWaveFile(String, SpeechAudioFormatInfo)Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format.
Public methodSetOutputToWaveStreamConfigures the SpeechSynthesizer object to append output to a stream that contains Waveform format audio.
Public methodSpeak(Prompt)Synchronously speaks the contents of a Prompt object.
Public methodSpeak(PromptBuilder)Synchronously speaks the contents of a PromptBuilder object.
Public methodSpeak(String)Synchronously speaks the contents of a string.
Public methodSpeakAsync(Prompt)Asynchronously speaks the contents of a Prompt object.
Public methodSpeakAsync(PromptBuilder)Asynchronously speaks the contents of a PromptBuilder object.
Public methodSpeakAsync(String)Asynchronously speaks the contents of a string.
Public methodSpeakAsyncCancelCancels the asynchronous synthesis operation for a queued prompt.
Public methodSpeakAsyncCancelAllCancels all queued, asynchronous, speech synthesis operations.
Public methodSpeakSsmlSynchronously speaks a String that contains SSML markup.
Public methodSpeakSsmlAsyncAsynchronously speaks a String that contains SSML markup.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventBookmarkReachedRaised when the SpeechSynthesizer encounters a bookmark in a prompt.
Public eventPhonemeReachedRaised when a phoneme is reached.
Public eventSpeakCompletedRaised when the SpeechSynthesizer completes the speaking of a prompt.
Public eventSpeakProgressRaised after the SpeechSynthesizer speaks each individual word of a prompt.
Public eventSpeakStartedRaised when the SpeechSynthesizer begins the speaking of a prompt.
Public eventStateChangedRaised when the state of the SpeechSynthesizer changes.
Public eventVisemeReachedRaised when a viseme is reached.
Public eventVoiceChangeRaised 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).

NoteNote

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 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();
    }
  }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Show:
© 2014 Microsoft