Windows.Media.SpeechSynthesis namespace

Applies to Windows and Windows Phone

Provides support for initializing and configuring a speech synthesis engine (voice) to convert a text string to an audio stream, also known as text-to-speech (TTS). Voice characteristics, pronunciation, volume, pitch, rate or speed, emphasis, and so on are customized through Speech Synthesis Markup Language (SSML).

Members

The Windows.Media.SpeechSynthesis namespace has these types of members:

Classes

The Windows.Media.SpeechSynthesis namespace has these classes.

ClassDescription
SpeechSynthesisStream Supports reading and writing audio data generated by the speech synthesis engine (voice) to/from a random access stream.
SpeechSynthesizer Provides access to the functionality of an installed speech synthesis engine (voice).
VoiceInformation Provides info about an installed speech synthesis engine (voice).

 

Enumerations

The Windows.Media.SpeechSynthesis namespace has these enumerations.

EnumerationDescription
VoiceGender Specifies the gender settings for an installed speech synthesis engine (voice).

 

Generating speech output from plain text

The following example demonstrates how a Windows Store app uses 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();
});

Generating speech output from SSML

The following example demonstrates how a Windows Store app uses a SpeechSynthesizer object to create an audio stream and output speech based on an 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

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

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

Metadata

Windows.winmd

See also

Samples
Speech synthesis sample

 

 

Show:
© 2014 Microsoft