Windows.Media.SpeechSynthesis namespace
Collapse the table of content
Expand the table of content

Windows.Media.SpeechSynthesis namespace

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

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

See also

Speech interactions
Designers
Speech design guidelines
Samples
Speech recognition and speech synthesis sample

 

 

Show:
© 2016 Microsoft