SpeechSynthesizer Classe

Définition

Fournit l’accès aux fonctionnalités d’un moteur de synthèse vocale (voix) installé pour les services de synthèse vocale (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
Héritage
Object Platform::Object IInspectable SpeechSynthesizer
Attributs
Implémente

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v1.0)

Exemples

L’exemple suivant montre comment générer un flux audio vocal à partir d’une chaîne de texte de base.

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

Cet exemple montre comment générer un flux audio vocal à partir d’une chaîne SSML, qui inclut des éléments de modulation qui contrôlent la hauteur, la vitesse de parole et le volume de la sortie vocale.

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

Remarques

Seules les voix signées Par Microsoft installées sur le système peuvent être utilisées pour générer la voix.

Windows inclut diverses voix signées par Microsoft qui peuvent être utilisées pour un certain nombre de langues. Chaque voix génère une synthèse vocale dans une seule langue, telle qu’elle est parlée dans un pays ou une région spécifique.

Par défaut, un nouvel objet SpeechSynthesizer utilise la voix système actuelle (appelez DefaultVoice pour savoir quelle est la voix par défaut).

Pour spécifier l’une des autres voix de synthèse vocale (synthèse vocale) installées sur le système de l’utilisateur, utilisez la méthode Voice (pour savoir quelles voix sont installées sur le système, appelez AllVoices).

Si vous ne spécifiez pas de langue, la voix qui correspond le plus à la langue sélectionnée dans le panneau de configuration Langue est chargée.

Utilisez un objet SpeechSynthesizer pour :

Historique des versions

Version de Windows Version du SDK Valeur ajoutée
1703 15063 Options
1709 16299 TrySetDefaultVoiceAsync

Constructeurs

SpeechSynthesizer()

Initialise une nouvelle instance d’un objet SpeechSynthesizer.

Propriétés

AllVoices

Obtient une collection de tous les moteurs de synthèse vocale (voix) installés.

DefaultVoice

Obtient le moteur de synthèse vocale par défaut (voix).

Options

Obtient une référence à la collection d’options qui peut être définie sur l’objet SpeechSynthesizer.

Voice

Obtient ou définit le moteur de synthèse vocale (voix).

Méthodes

Close()

Ferme speechSynthesizer et libère les ressources système.

Dispose()

Exécute les tâches définies par l'application associées à la libération ou à la redéfinition des ressources non managées.

SynthesizeSsmlToStreamAsync(String)

Générez et contrôlez de manière asynchrone la sortie vocale à partir d’une chaîne SSML (Speech Synthesis Markup Language) version 1.1 .

SynthesizeTextToStreamAsync(String)

Générez de façon asynchrone une sortie vocale à partir d’une chaîne.

TrySetDefaultVoiceAsync(VoiceInformation)

Tente de manière asynchrone de définir la voix utilisée pour la synthèse vocale sur un appareil IoT .

Notes

Cette méthode est disponible uniquement en mode Incorporé.

S’applique à

Voir aussi