SpeechSynthesisStream SpeechSynthesisStream SpeechSynthesisStream SpeechSynthesisStream SpeechSynthesisStream Class

Definition

Supports reading and writing audio data generated by the speech synthesis engine (voice) to/from a random access stream.

public : sealed class SpeechSynthesisStream : IClosable, ITimedMetadataTrackProvider, ISpeechSynthesisStream, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
struct winrt::Windows::Media::SpeechSynthesis::SpeechSynthesisStream : IClosable, ITimedMetadataTrackProvider, ISpeechSynthesisStream, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
public sealed class SpeechSynthesisStream : IDisposable, ITimedMetadataTrackProvider, ISpeechSynthesisStream, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
Public NotInheritable Class SpeechSynthesisStream Implements IDisposable, ITimedMetadataTrackProvider, ISpeechSynthesisStream, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
// This class does not provide a public constructor.
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

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

Properties

CanRead CanRead CanRead CanRead CanRead

Gets whether SpeechSynthesisStream can be read from.

CanWrite CanWrite CanWrite CanWrite CanWrite

Gets a value that indicates whether SpeechSynthesisStream can be written to.

ContentType ContentType ContentType ContentType ContentType

Gets the MIME type of the content of SpeechSynthesisStream.

Markers Markers Markers Markers Markers

Gets the collection of timeline markers associated with the SpeechSynthesisStream.

Note

SpeechSynthesisStream.Markers is deprecated. We recommend using the MediaPlayerElement and MediaPlaybackItem objects instead (in conjunction with the IncludeSentenceBoundaryMetadata and IncludeWordBoundaryMetadata properties of a SpeechSynthesizerOptions object).

Position Position Position Position Position

Gets the current position within the SpeechSynthesisStream.

Size Size Size Size Size

Gets or sets the size of the SpeechSynthesisStream.

TimedMetadataTracks TimedMetadataTracks TimedMetadataTracks TimedMetadataTracks TimedMetadataTracks

Gets the collection of optional word and sentence boundaries in the speech synthesis stream as specified by the SpeechSynthesizer.Options property.

Methods

CloneStream() CloneStream() CloneStream() CloneStream() CloneStream()

Creates a copy of SpeechSynthesisStream that references the same bytes as the original stream.

Close() Close() Close() Close() Close()

Releases system resources that are exposed by SpeechSynthesisStream.

Dispose() Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

FlushAsync() FlushAsync() FlushAsync() FlushAsync() FlushAsync()

Flushes data asynchronously in a sequential stream.

GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64)

Retrieves an input stream at a specified location in SpeechSynthesisStream.

GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64)

Retrieves an output stream at a specified location in SpeechSynthesisStream.

ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions)

Reads data asynchronously in a sequential stream.

Seek(UInt64) Seek(UInt64) Seek(UInt64) Seek(UInt64) Seek(UInt64)

Goes to the specified position within SpeechSynthesisStream.

WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer)

Writes data asynchronously in a sequential stream.

See also