-api-id | -api-type |
---|---|
T:Windows.Media.SpeechSynthesis.SpeechSynthesisStream |
winrt class |
Supports reading and writing audio data generated by the speech synthesis engine (voice) to/from a random access stream.
Windows version | SDK version | Value added |
---|---|---|
1703 | 15063 | TimedMetadataTracks |
Your UWP app can use a SpeechSynthesizer object to create an audio stream and output speech based on a plain text string.
// 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();
[!code-cppSpeechSynthesizerText]
// 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();
[!code-cppSpeechSynthesizerSSML]
Windows.Media.SpeechSynthesis, IRandomAccessStreamWithContentType, IRandomAccessStream, IClosable, IInputStream, IOutputStream, IContentTypeProvider, Speech interactions, Speech recognition and speech synthesis sample