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, IRandomAccessStreamWithContentTypepublic sealed class SpeechSynthesisStream : IDisposable, ITimedMetadataTrackProvider, ISpeechSynthesisStream, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentTypePublic NotInheritable Class SpeechSynthesisStream Implements IDisposable, ITimedMetadataTrackProvider, ISpeechSynthesisStream, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType// You can use this class in JavaScript.
Attributes
Windows 10 requirements
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();
});

Properties

CanRead CanRead CanRead CanRead

Gets whether SpeechSynthesisStream can be read from.

public : PlatForm::Boolean CanRead { get; }public bool CanRead { get; }Public ReadOnly Property CanRead As bool// You can use this property in JavaScript.
Value
PlatForm::Boolean bool bool bool

True if the stream can be read from; otherwise false.

See Also

CanWrite CanWrite CanWrite CanWrite

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

public : PlatForm::Boolean CanWrite { get; }public bool CanWrite { get; }Public ReadOnly Property CanWrite As bool// You can use this property in JavaScript.
Value
PlatForm::Boolean bool bool bool

True if the stream can be written to; otherwise false.

See Also

ContentType ContentType ContentType ContentType

Gets the MIME type of the content of SpeechSynthesisStream.

public : PlatForm::String ContentType { get; }public string ContentType { get; }Public ReadOnly Property ContentType As string// You can use this property in JavaScript.
Value
PlatForm::String string string string

The MIME type (audio/wav) of the stream.

See Also

Markers Markers Markers Markers

Gets the collection of timeline markers associated with the SpeechSynthesisStream.

public : IVectorView<IMediaMarker> Markers { get; }public IReadOnlyList<IMediaMarker> Markers { get; }Public ReadOnly Property Markers As IReadOnlyList<IMediaMarker>// You can use this property in JavaScript.
Value
IVectorView<IMediaMarker> IReadOnlyList<IMediaMarker> IReadOnlyList<IMediaMarker> IReadOnlyList<IMediaMarker>

When this method completes successfully, it returns a collection of IMediaMarker objects that represent the timeline markers in the stream.

See Also

Position Position Position Position

Gets the position within SpeechSynthesisStream.

public : ulong Position { get; }public ulong Position { get; }Public ReadOnly Property Position As ulong// You can use this property in JavaScript.
Value
ulong ulong ulong ulong

The current position within the stream.

See Also

Size Size Size Size

Gets or sets the size of the SpeechSynthesisStream.

public : ulong Size { get; set; }public ulong Size { get; set; }Public ReadWrite Property Size As ulong// You can use this property in JavaScript.
Value
ulong ulong ulong ulong

The size of the stream.

See Also

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.

public : IVectorView<TimedMetadataTrack> TimedMetadataTracks { get; }public IReadOnlyList<TimedMetadataTrack> TimedMetadataTracks { get; }Public ReadOnly Property TimedMetadataTracks As IReadOnlyList<TimedMetadataTrack>// You can use this property in JavaScript.
Value
IVectorView<TimedMetadataTrack> IReadOnlyList<TimedMetadataTrack> IReadOnlyList<TimedMetadataTrack> IReadOnlyList<TimedMetadataTrack>

A collection of TimedMetadataTrack objects.

Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Methods

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

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

public : IRandomAccessStream CloneStream()public IRandomAccessStream CloneStream()Public Function CloneStream() As IRandomAccessStream// You can use this method in JavaScript.
Returns

The new stream.

The Position (0), Seek pointer, and lifetime of this new stream are independent from those of the original stream.

See Also

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

Releases system resources that are exposed by SpeechSynthesisStream.

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.

Remarks

All outstanding asynchronous operations must complete before calling Close.

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

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

Flushes data asynchronously in a sequential stream.

public : IAsyncOperation<PlatForm::Boolean> FlushAsync()public IAsyncOperation<bool> FlushAsync()Public Function FlushAsync() As IAsyncOperation( Of bool )// You can use this method in JavaScript.
Returns

An asynchronous operation. For more information, see FlushAsync method.

See Also

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

Retrieves an input stream at a specified location in SpeechSynthesisStream.

public : IInputStream GetInputStreamAt(unsigned __int64 position)public IInputStream GetInputStreamAt(UInt64 position)Public Function GetInputStreamAt(position As UInt64) As IInputStream// You can use this method in JavaScript.
Parameters
position
unsigned __int64 UInt64 UInt64 UInt64

The location in the stream at which to begin.

Returns
See Also

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

Retrieves an output stream at a specified location in SpeechSynthesisStream.

public : IOutputStream GetOutputStreamAt(unsigned __int64 position)public IOutputStream GetOutputStreamAt(UInt64 position)Public Function GetOutputStreamAt(position As UInt64) As IOutputStream// You can use this method in JavaScript.
Parameters
position
unsigned __int64 UInt64 UInt64 UInt64

The location in the stream at which to begin.

Returns
See Also

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

Reads data asynchronously in a sequential stream.

public : IAsyncOperationWithProgress<IBuffer, unsigned int> ReadAsync(IBuffer buffer, unsigned int count, InputStreamOptions options)public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, UInt32 count, InputStreamOptions options)Public Function ReadAsync(buffer As IBuffer, count As UInt32, options As InputStreamOptions) As IAsyncOperationWithProgress( Of IBuffer, uint )// You can use this method in JavaScript.
Parameters
buffer
IBuffer IBuffer IBuffer IBuffer

The buffer into which the asynchronous read operation places the bytes that are read.

count
unsigned int UInt32 UInt32 UInt32

The number of bytes to read that is less than or equal to the Capacity value.

options
InputStreamOptions InputStreamOptions InputStreamOptions InputStreamOptions

Specifies the type of the asynchronous read operation.

Returns

An asynchronous operation that includes progress updates. For more information, see ReadAsync method.

See Also

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

Goes to the specified position within SpeechSynthesisStream.

public : void Seek(unsigned __int64 position)public void Seek(UInt64 position)Public Function Seek(position As UInt64) As void// You can use this method in JavaScript.
Parameters
position
unsigned __int64 UInt64 UInt64 UInt64

The desired position within the stream.

See Also

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

Writes data asynchronously in a sequential stream.

public : IAsyncOperationWithProgress<unsigned int, unsigned int> WriteAsync(IBuffer buffer)public IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)Public Function WriteAsync(buffer As IBuffer) As IAsyncOperationWithProgress( Of uint, uint )// You can use this method in JavaScript.
Parameters
buffer
IBuffer IBuffer IBuffer IBuffer

The buffer into which the asynchronous writer operation places the bytes to write.

Returns

An asynchronous operation that includes progress updates. For more information, see WriteAsync method.

See Also

See Also