SpeechSynthesizer SpeechSynthesizer SpeechSynthesizer SpeechSynthesizer Class

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

Declaration

public sealed class SpeechSynthesizerpublic sealed class SpeechSynthesizerPublic NotInheritable Class SpeechSynthesizer

Remarks

Examples

Your Windows Store app can use a GetDeviceSelector(System.UInt16,System.UInt16,System.UInt16,System.UInt16) 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();
});
// 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();
// The object for controlling the speech synthesis engine (voice).
synth = ref new SpeechSynthesizer();
// The media object for controlling and playing audio.
media = ref new MediaElement();
// The string to speak.
String^ text = "Hello World";

// Generate the audio stream from plain text.
task<SpeechSynthesisStream ^> speakTask = create_task(synth->SynthesizeTextToStreamAsync(text));
speakTask.then([this, text](SpeechSynthesisStream ^speechStream)
{
	// Send the stream to the media object.
	// media === MediaElement XAML object.
	media->SetSource(speechStream, speechStream->ContentType);
	media->AutoPlay = true;
	media->Play();
});

// 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();
});
// 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();
// The object for controlling the speech synthesis engine (voice).
synth = ref new SpeechSynthesizer();
// The media object for controlling and playing audio.
media = ref new MediaElement();
// The string to speak.
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>";

// Generate the audio stream from SSML.
task<SpeechSynthesisStream ^> speakTask = create_task(synth->SynthesizeSsmlToStreamAsync(ssml));
speakTask.then([this, ssml](SpeechSynthesisStream ^speechStream)
{
	// Send the stream to the media object.
	// media === MediaElement XAML object.
	media->SetSource(speechStream, speechStream->ContentType);
	media->AutoPlay = true;
	media->Play();
});

Constructors summary

Initializes a new instance of a SpeechSynthesizer object.

Properties summary

Gets a collection of all installed speech synthesis engines (voices).

Gets the default speech synthesis engine (voice).

Gets or sets the speech synthesis engine (voice).

Methods summary

Closes the SpeechSynthesizer and releases system resources.

Asynchronously generate speech output from a string containing .

Asynchronously generate speech output from a string.

Constructors

  • SpeechSynthesizer()
    SpeechSynthesizer()
    SpeechSynthesizer()
    SpeechSynthesizer()

    Initializes a new instance of a SpeechSynthesizer object.

    public SpeechSynthesizer()public SpeechSynthesizer()Public Function SpeechSynthesizer() As

Properties

  • AllVoices
    AllVoices
    AllVoices
    AllVoices

    Gets a collection of all installed speech synthesis engines (voices).

    public static IVectorView<VoiceInformation> AllVoices { get; }public static IVectorView<VoiceInformation> AllVoices { get; }Public Static ReadOnly Property AllVoices As IVectorView<VoiceInformation>

    Property Value

    • All installed voices.

  • DefaultVoice
    DefaultVoice
    DefaultVoice
    DefaultVoice

    Gets the default speech synthesis engine (voice).

    public static VoiceInformation DefaultVoice { get; }public static VoiceInformation DefaultVoice { get; }Public Static ReadOnly Property DefaultVoice As VoiceInformation

    Property Value

  • Voice
    Voice
    Voice
    Voice

    Gets or sets the speech synthesis engine (voice).

    public VoiceInformation Voice { get; set; }public VoiceInformation Voice { get; set; }Public ReadWrite Property Voice As VoiceInformation

    Property Value

    Remarks

    Only Microsoft-signed voices can be used by SpeechSynthesizer. Here is a list of Microsoft-signed voices provided with Windows.

    VoiceGenderWindows 8Windows 8.1NameDisplay name
    English USFemaleYYZiraMicrosoft Zira (en-US, female).
    English USMaleYYDavidMicrosoft David (en-US, male)
    English GBFemaleYYHazelMicrosoft Hazel (en-GB, female)
    French FRFemaleYYHortenseMicrosoft Hortense (fr-FR , female)
    German DEFemaleYYHeddaMicrosoft Hedda (de-DE, female)
    Spanish ESFemaleYYHelenaMicrosoft Helena (es-ES, female)
    Chinese PRCFemaleYYHuihuiMicrosoft Huihui (zh-CN, female)
    Chinese TWFemaleYYHanhanMicrosoft Hanhan (zh-TW, female)
    Japanese JAFemaleYYHarukaMicrosoft Haruka (ja-JP, female)
    Korean KRFemaleYYHeamiMicrosoft Heami (ko-KR, female)
    Spanish MXFemaleNYSabinaMicrosoft Sabina (es-MX, female)
    Italian ITFemaleNYElsaMicrosoft Elsa (it-IT, female)
    English INFemaleNYHeeraMicrosoft Heera (en-IN, female)
    Russian RUFemaleNYIrinaMicrosoft Irina (ru-RU, female)
    Chinese HKFemaleNYTracyMicrosoft Tracy (zh-HK, female)
    Polish PLFemaleNYPaulinaMicrosoft Paulina (pl-PL, female)
    Portuguese BRFemaleNYMariaMicrosoft Maria (pt-BR, female)

Methods

  • Close()
    Close()
    Close()
    Close()

    Closes the SpeechSynthesizer and releases system resources.

    public void Close()public void Close()Public Function Close() As void
  • SynthesizeSsmlToStreamAsync(System.String)
    SynthesizeSsmlToStreamAsync(System.String)
    SynthesizeSsmlToStreamAsync(System.String)
    SynthesizeSsmlToStreamAsync(System.String)

    Asynchronously generate speech output from a string containing .

    public IAsyncOperation<SpeechSynthesisStream> SynthesizeSsmlToStreamAsync(System.String)public IAsyncOperation<SpeechSynthesisStream> SynthesizeSsmlToStreamAsync(System.String)Public Function SynthesizeSsmlToStreamAsync(System.String) As IAsyncOperation( Of SpeechSynthesisStream )

    Parameters

    • Ssml
      System.String
      System.String
      System.String
      System.String

      The SSML-modified text to speak.

    Returns

  • SynthesizeTextToStreamAsync(System.String)
    SynthesizeTextToStreamAsync(System.String)
    SynthesizeTextToStreamAsync(System.String)
    SynthesizeTextToStreamAsync(System.String)

    Asynchronously generate speech output from a string.

    public IAsyncOperation<SpeechSynthesisStream> SynthesizeTextToStreamAsync(System.String)public IAsyncOperation<SpeechSynthesisStream> SynthesizeTextToStreamAsync(System.String)Public Function SynthesizeTextToStreamAsync(System.String) As IAsyncOperation( Of SpeechSynthesisStream )

    Parameters

    • text
      System.String
      System.String
      System.String
      System.String

      The text to speak.

    Returns

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.Media.SpeechSynthesis.dll