SpeechSynthesisStream Clase

Definición

Admite la lectura y escritura de datos de audio generados por el motor de síntesis de voz (voz) hacia y desde una secuencia de acceso aleatorio.

public ref class SpeechSynthesisStream sealed : IClosable
public ref class SpeechSynthesisStream sealed : IClosable, ITimedMetadataTrackProvider
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SpeechSynthesisStream final : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SpeechSynthesisStream final : IClosable, ITimedMetadataTrackProvider
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SpeechSynthesisStream : System.IDisposable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SpeechSynthesisStream : System.IDisposable, ITimedMetadataTrackProvider
Public NotInheritable Class SpeechSynthesisStream
Implements IDisposable
Public NotInheritable Class SpeechSynthesisStream
Implements IDisposable, ITimedMetadataTrackProvider
Herencia
Object Platform::Object IInspectable SpeechSynthesisStream
Atributos
Implementaciones

Requisitos de Windows

Familia de dispositivos
Windows 10 (se introdujo en la versión 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (se introdujo en la versión v1.0)

Ejemplos

La aplicación para UWP puede usar un objeto SpeechSynthesizer para crear una secuencia de audio y generar voz basada en una cadena de texto sin formato.

// 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.
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();
});

Comentarios

Historial de versiones

Versión de Windows Versión del SDK Valor agregado
1703 15063 TimedMetadataTracks

Propiedades

CanRead

Obtiene si SpeechSynthesisStream se puede leer.

CanWrite

Obtiene un valor que indica si SpeechSynthesisStream se puede escribir en.

ContentType

Obtiene el tipo MIME del contenido de SpeechSynthesisStream.

Markers

Obtiene la colección de marcadores de escala de tiempo asociados a SpeechSynthesisStream.

Nota:

SpeechSynthesisStream.Markers está en desuso. Se recomienda usar en su lugar los objetos MediaPlayerElement y MediaPlaybackItem (junto con las propiedades IncludeSentenceBoundaryMetadata e IncludeWordBoundaryMetadata de un objeto SpeechSynthesizerOptions ).

Position

Obtiene la posición actual dentro de SpeechSynthesisStream.

Size

Obtiene o establece el tamaño de SpeechSynthesisStream.

TimedMetadataTracks

Obtiene la colección de límites de palabras y oraciones opcionales en el flujo de síntesis de voz según lo especificado por la propiedad SpeechSynthesizer.Options .

Métodos

CloneStream()

Crea una copia de SpeechSynthesisStream que hace referencia a los mismos bytes que la secuencia original.

Close()

Libera los recursos del sistema expuestos por SpeechSynthesisStream.

Dispose()

Realiza tareas definidas por la aplicación asociadas a la liberación o al restablecimiento de recursos no administrados.

FlushAsync()

Vacía los datos de forma asincrónica en una secuencia secuencial.

GetInputStreamAt(UInt64)

Recupera un flujo de entrada en una ubicación especificada en SpeechSynthesisStream.

GetOutputStreamAt(UInt64)

Recupera un flujo de salida en una ubicación especificada en SpeechSynthesisStream.

ReadAsync(IBuffer, UInt32, InputStreamOptions)

Lee los datos de forma asincrónica en una secuencia secuencial.

Seek(UInt64)

Va a la posición especificada en SpeechSynthesisStream.

WriteAsync(IBuffer)

Escribe datos de forma asincrónica en una secuencia secuencial.

Se aplica a

Consulte también