SpeechSynthesizer Clase

Definición

Proporciona acceso a la funcionalidad de un motor de síntesis de voz (voz) instalado para servicios de texto a voz (TTS).

public ref class SpeechSynthesizer sealed : IClosable
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SpeechSynthesizer final : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class SpeechSynthesizer final : IClosable
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SpeechSynthesizer : System.IDisposable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class SpeechSynthesizer : System.IDisposable
function SpeechSynthesizer()
Public NotInheritable Class SpeechSynthesizer
Implements IDisposable
Herencia
Object Platform::Object IInspectable SpeechSynthesizer
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

En el ejemplo siguiente se muestra cómo generar una secuencia de audio de voz a partir de una cadena de texto básica.

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

En este ejemplo se muestra cómo generar una secuencia de audio de voz a partir de una cadena SSML, que incluye algunos elementos de modulación que controlan el tono, la velocidad de habla y el volumen de la salida de voz.

// 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

Solo se pueden usar voces firmadas por Microsoft instaladas en el sistema para generar voz.

Windows incluye varias voces firmadas por Microsoft que se pueden usar para varios idiomas. Cada voz genera voz sintetizada en un solo idioma, como se habla en un país o región específicos.

De forma predeterminada, un nuevo objeto SpeechSynthesizer usa la voz del sistema actual (llama a DefaultVoice para averiguar cuál es la voz predeterminada).

Para especificar cualquiera de las demás voces de síntesis de voz (texto a voz) instaladas en el sistema del usuario, use el método Voice (para averiguar qué voces están instaladas en el sistema, llame a AllVoices).

Si no especifica un idioma, se carga la voz que se corresponde más estrechamente con el idioma seleccionado en el panel de control Idioma.

Use un objeto SpeechSynthesizer para:

Historial de versiones

Versión de Windows Versión del SDK Valor agregado
1703 15063 Opciones
1709 16299 TrySetDefaultVoiceAsync

Constructores

SpeechSynthesizer()

Inicializa una nueva instancia de un objeto SpeechSynthesizer .

Propiedades

AllVoices

Obtiene una colección de todos los motores de síntesis de voz instalados (voces).

DefaultVoice

Obtiene el motor de síntesis de voz (voz) predeterminado.

Options

Obtiene una referencia a la colección de opciones que se pueden establecer en el objeto SpeechSynthesizer.

Voice

Obtiene o establece el motor de síntesis de voz (voz).

Métodos

Close()

Cierra speechSynthesizer y libera los recursos del sistema.

Dispose()

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

SynthesizeSsmlToStreamAsync(String)

Genere y controle la salida de voz de forma asincrónica a partir de una cadena del lenguaje de marcado de síntesis de voz (SSML) versión 1.1 .

SynthesizeTextToStreamAsync(String)

Genere de forma asincrónica la salida de voz a partir de una cadena.

TrySetDefaultVoiceAsync(VoiceInformation)

Intenta establecer de forma asincrónica la voz usada para la síntesis de voz en un dispositivo IoT .

Nota:

Este método solo está disponible en modo incrustado.

Se aplica a

Consulte también