Export (0) Print
Expand All

SpeechSynthesizer class

Applies to Windows and Windows Phone

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

Windows includes Microsoft-signed voices that can be used for a variety of languages. Each voice generates synthesized speech in a single language, as spoken in a specific country/region.

Only Microsoft-signed voices installed on the system can be used to generate speech. If no language is specified, the voice that most closely matches the language selected by the user in the Language control panel is loaded.

Syntax


public sealed class SpeechSynthesizer : IDisposable

Attributes

[MarshalingBehavior(Agile)]
[Version(0x06030000)]

Members

The SpeechSynthesizer class has these types of members:

Constructors

The SpeechSynthesizer class has these constructors.

ConstructorDescription
SpeechSynthesizer Initializes a new instance of a SpeechSynthesizer object.

 

Methods

The SpeechSynthesizer class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Close [C++, JavaScript]Closes the SpeechSynthesizer and releases system resources.
Dispose [C#, VB]Performs tasks associated with freeing, releasing, or resetting unmanaged resources.
SynthesizeSsmlToStreamAsync Asynchronously generate speech output from a string containing Speech Synthesis Markup Language (SSML).
SynthesizeTextToStreamAsync Asynchronously generate speech output from a string.

 

Properties

The SpeechSynthesizer class has these properties.

PropertyAccess typeDescription

AllVoices

Read-onlyGets a collection of all installed speech synthesis engines (voices).

DefaultVoice

Read-onlyGets the default speech synthesis engine (voice).

Voice

Read/writeGets or sets the speech synthesis engine (voice).

 

Examples

Your Windows Store app can use a SpeechSynthesizer object to create an audio stream and output speech based on a plain text string.


// The media object for controlling and playing audio.
MediaElement mediaElement = this.media;

// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");

// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();

Your Windows Store app can also use a SpeechSynthesizer object to create an audio stream and output speech based on a Speech Synthesis Markup Language (SSML) text string.


// The string to speak with SSML customizations.
string Ssml =
    @"<speak version='1.0' " +
    "xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>" +
    "Hello <prosody contour='(0%,+80Hz) (10%,+80%) (40%,+80Hz)'>World</prosody> " + 
    "<break time='500ms' />" +
    "Goodbye <prosody rate='slow' contour='(0%,+20Hz) (10%,+30%) (40%,+10Hz)'>World</prosody>" +
    "</speak>";

// The media object for controlling and playing audio.
MediaElement mediaElement = this.media;

// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.synthesizeSsmlToStreamAsync(Ssml);

// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();

Requirements

Minimum supported client

Windows 8.1 [Windows Store apps only]

Minimum supported server

Windows Server 2012 R2 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Media.SpeechSynthesis
Windows::Media::SpeechSynthesis [C++]

Metadata

Windows.winmd

See also

Reference
Windows.Media.SpeechSynthesis
Object
IClosable
VoiceInformation
Samples
Speech synthesis sample

 

 

Show:
© 2015 Microsoft