Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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


var speechSynthesizer = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();

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 object for controlling and playing audio.
var audio = new Audio();

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

// Generate the audio stream from plain text.
synth.synthesizeTextToStreamAsync("hello World").then(function (markersStream) {

    // Convert the stream to a URL Blob.
    var blob = MSApp.createBlobFromRandomAccessStream(markersStream.ContentType, markersStream);

    // Send the Blob to the audio object.
    audio.src = URL.createObjectURL(blob, { oneTimeOnly: true });
    audio.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.
var 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 object for controlling and playing audio.
var audio = new Audio();

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

// Generate the audio stream from plain text.
synth.synthesizeSsmlToStreamAsync(Ssml).then(function(synthesisStream){

    // Convert the stream to a URL Blob.
    var blob = MSApp.createBlobFromRandomAccessStream(synthesisStream.ContentType, synthesisStream);

    // Send the Blob to the audio object.
    audio.src = URL.createObjectURL(blob, { oneTimeOnly: true });
    audio.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:
© 2014 Microsoft. All rights reserved.