Поділитися через


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
SpeechSynthesizer
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()

Initializes a new instance of the SpeechSynthesizer class.

Properties

Rate

Gets or sets the speaking rate of the SpeechSynthesizer object.

State

Gets the current speaking state of the SpeechSynthesizer object.

Voice

Gets information about the current voice of the SpeechSynthesizer object.

Volume

Get or sets the output volume of the SpeechSynthesizer object.

Methods

AddLexicon(Uri, String)

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

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

GetCurrentlySpokenPrompt()

Gets the prompt that the SpeechSynthesizer is speaking.

GetHashCode()

Serves as the default hash function.

(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 SpeechSynthesizer object.

RemoveLexicon(Uri)

Removes a lexicon from the SpeechSynthesizer object.

Resume()

Resumes the SpeechSynthesizer object after it has been paused.

SelectVoice(String)

Selects a specific voice by name.

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.

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)

Selects a voice with a specific gender and age.

SelectVoiceByHints(VoiceGender)

Selects a voice with a specific gender.

SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)

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, SpeechAudioFormatInfo)

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

SetOutputToWaveFile(String)

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

SetOutputToWaveStream(Stream)

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(Prompt)

Cancels the asynchronous synthesis operation for a queued prompt.

SpeakAsyncCancelAll()

Cancels all queued, asynchronous, speech synthesis operations.

SpeakSsml(String)

Synchronously speaks a String that contains SSML markup.

SpeakSsmlAsync(String)

Asynchronously speaks a String that contains SSML markup.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Events

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.

Applies to

See also