SpeechSynthesizer
SpeechSynthesizer
SpeechSynthesizer
SpeechSynthesizer
Class
Definition
Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Prerelease APIs are identified by a Prerelease label.
[Contains prerelease APIs.]
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.
public : sealed class SpeechSynthesizer : IClosable, ISpeechSynthesizer, ISpeechSynthesizer2public sealed class SpeechSynthesizer : IDisposable, ISpeechSynthesizer, ISpeechSynthesizer2Public NotInheritable Class SpeechSynthesizer Implements IDisposable, ISpeechSynthesizer, ISpeechSynthesizer2// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
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();
});
// 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
SpeechSynthesizer() SpeechSynthesizer() SpeechSynthesizer() SpeechSynthesizer()
Initializes a new instance of a SpeechSynthesizer object.
public : SpeechSynthesizer()public SpeechSynthesizer()Public Sub New()// You can use this method in JavaScript.
- See Also
Properties
AllVoices AllVoices AllVoices AllVoices
Gets a collection of all installed speech synthesis engines (voices).
public : static IVectorView<VoiceInformation> AllVoices { get; }public static IReadOnlyList<VoiceInformation> AllVoices { get; }Public Static ReadOnly Property AllVoices As IReadOnlyList<VoiceInformation>// You can use this property in JavaScript.
- Value
- IVectorView<VoiceInformation> IReadOnlyList<VoiceInformation> IReadOnlyList<VoiceInformation> IReadOnlyList<VoiceInformation>
All installed voices.
- See Also
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// You can use this property in JavaScript.
A voice based on language settings and installed voices.
- See Also
Options Options Options Options
Gets a reference to the collection of options that can be set on the SpeechSynthesizer object.
public : SpeechSynthesizerOptions Options { get; }public SpeechSynthesizerOptions Options { get; }Public ReadOnly Property Options As SpeechSynthesizerOptions// You can use this property in JavaScript.
- Value
- SpeechSynthesizerOptions SpeechSynthesizerOptions SpeechSynthesizerOptions SpeechSynthesizerOptions
The speech synthesizer options.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
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// You can use this property in JavaScript.
A speech synthesis engine (voice). The default value is the system voice.
Remarks
Only Microsoft-signed voices can be used by SpeechSynthesizer. Here is a list of Microsoft-signed voices provided with Windows.
| Voice | Gender | Windows 8 | Windows 8.1 | Name | Display name |
|---|---|---|---|---|---|
| English US | Female | Y | Y | Zira | Microsoft Zira (en-US, female). |
| English US | Male | Y | Y | David | Microsoft David (en-US, male) |
| English GB | Female | Y | Y | Hazel | Microsoft Hazel (en-GB, female) |
| French FR | Female | Y | Y | Hortense | Microsoft Hortense (fr-FR , female) |
| German DE | Female | Y | Y | Hedda | Microsoft Hedda (de-DE, female) |
| Spanish ES | Female | Y | Y | Helena | Microsoft Helena (es-ES, female) |
| Chinese PRC | Female | Y | Y | Huihui | Microsoft Huihui (zh-CN, female) |
| Chinese TW | Female | Y | Y | Hanhan | Microsoft Hanhan (zh-TW, female) |
| Japanese JA | Female | Y | Y | Haruka | Microsoft Haruka (ja-JP, female) |
| Korean KR | Female | Y | Y | Heami | Microsoft Heami (ko-KR, female) |
| Spanish MX | Female | N | Y | Sabina | Microsoft Sabina (es-MX, female) |
| Italian IT | Female | N | Y | Elsa | Microsoft Elsa (it-IT, female) |
| English IN | Female | N | Y | Heera | Microsoft Heera (en-IN, female) |
| Russian RU | Female | N | Y | Irina | Microsoft Irina (ru-RU, female) |
| Chinese HK | Female | N | Y | Tracy | Microsoft Tracy (zh-HK, female) |
| Polish PL | Female | N | Y | Paulina | Microsoft Paulina (pl-PL, female) |
| Portuguese BR | Female | N | Y | Maria | Microsoft Maria (pt-BR, female) |
- See Also
Methods
Close() Close() Close() Close()
Closes the SpeechSynthesizer and releases system resources.
public : void Close()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.
- See Also
Dispose() Dispose() Dispose() Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()
SynthesizeSsmlToStreamAsync(String) SynthesizeSsmlToStreamAsync(String) SynthesizeSsmlToStreamAsync(String) SynthesizeSsmlToStreamAsync(String)
Asynchronously generate speech output from a string containing Speech Synthesis Markup Language (SSML).
public : IAsyncOperation<SpeechSynthesisStream> SynthesizeSsmlToStreamAsync(PlatForm::String Ssml)public IAsyncOperation<SpeechSynthesisStream> SynthesizeSsmlToStreamAsync(String Ssml)Public Function SynthesizeSsmlToStreamAsync(Ssml As String) As IAsyncOperation( Of SpeechSynthesisStream )// You can use this method in JavaScript.
- Ssml
- PlatForm::String String String String
The SSML-modified text to speak.
A SpeechSynthesisStream that represents the speech generated from the .
- See Also
SynthesizeTextToStreamAsync(String) SynthesizeTextToStreamAsync(String) SynthesizeTextToStreamAsync(String) SynthesizeTextToStreamAsync(String)
Asynchronously generate speech output from a string.
public : IAsyncOperation<SpeechSynthesisStream> SynthesizeTextToStreamAsync(PlatForm::String text)public IAsyncOperation<SpeechSynthesisStream> SynthesizeTextToStreamAsync(String text)Public Function SynthesizeTextToStreamAsync(text As String) As IAsyncOperation( Of SpeechSynthesisStream )// You can use this method in JavaScript.
- text
- PlatForm::String String String String
The text to speak.
A SpeechSynthesisStream that represents the speech generated from the text.
- See Also
TrySetDefaultVoiceAsync(VoiceInformation) TrySetDefaultVoiceAsync(VoiceInformation) TrySetDefaultVoiceAsync(VoiceInformation) TrySetDefaultVoiceAsync(VoiceInformation)
Prerelease. Asynchronously attempts to set the voice used for speech synthesis on an IoT device.
Note
This method is available only in Embedded mode.
public : static IAsyncOperation<PlatForm::Boolean> TrySetDefaultVoiceAsync(VoiceInformation voice)public static IAsyncOperation<bool> TrySetDefaultVoiceAsync(VoiceInformation voice)Public Static Function TrySetDefaultVoiceAsync(voice As VoiceInformation) As IAsyncOperation( Of bool )// You can use this method in JavaScript.
One of the installed speech synthesis engines (voices).
An asynchronous operation that returns true if the set operation was a success. Otherwise, returns false.
| Device family |
Windows 10 Insider Preview (introduced v10.0.16257.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v5)
|
Remarks
Your app must declare the systemManagement capability, which lets apps access basic system administration privileges including locale, timezone, shut down, and reboot.
The systemManagement capability must include the iot namespace when you declare it in your app's package manifest.
<Capabilities><iot:Capability Name="systemManagement"/></Capabilities>
Use Windows.Globalization.ApplicationLanguages.Languages to get the ranked list of current runtime language values preferred by the user.
- See Also