Поділитися через


SpeechSynthesizer.SpeakSsmlAsync(String) Method

Definition

Asynchronously speaks a String that contains SSML markup.

public:
 System::Speech::Synthesis::Prompt ^ SpeakSsmlAsync(System::String ^ textToSpeak);
public System.Speech.Synthesis.Prompt SpeakSsmlAsync (string textToSpeak);
member this.SpeakSsmlAsync : string -> System.Speech.Synthesis.Prompt
Public Function SpeakSsmlAsync (textToSpeak As String) As Prompt

Parameters

textToSpeak
String

The SMML markup to speak.

Returns

The object that contains the content to speak.

Exceptions

textToSpeakis null.

Examples

using System;
using System.Speech.Synthesis;

namespace SampleSynthesis
{
  class Program
  {
    static void Main(string[] args)
    {

      // Initialize a new instance of the SpeechSynthesizer.
      SpeechSynthesizer synth = new SpeechSynthesizer();

      // Configure the audio output.
      synth.SetOutputToDefaultAudioDevice();

      // Build an SSML prompt in a string.
      string str = "<speak version=\"1.0\"";
      str += " xmlns=\"http://www.w3.org/2001/10/synthesis\"";
      str += " xml:lang=\"en-US\">";
      str += "<say-as type=\"date:mdy\"> 1/29/2009 </say-as>";
      str += "</speak>";

      // Speak the contents of the prompt asynchronously.
      synth.SpeakSsmlAsync(str);

      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by SpeakSsml(String).

Remarks

The contents of the textToSpeak parameter must include a speak element and must conform to the Speech Synthesis Markup Language (SSML) Version 1.0. For more information, see Speech Synthesis Markup Language Reference.

To synchronously speak a string that contains SSML markup, use the SpeakSsml method. You can use SpeakAsync to initiate the asynchronous speaking of a string that does not contain SSML markup.

During a call to this method, the SpeechSynthesizer can raise the following events:

  • StateChanged. Raised when the speaking state of the synthesizer changes.

  • SpeakStarted. Raised when the synthesizer begins generating speech.

  • PhonemeReached. Raised each time the synthesizer reaches a letter or combination of letters that constitute a discreet sound of speech in a language.

  • SpeakProgress. Raised each time the synthesizer completes speaking a word.

  • VisemeReached. Raised each time spoken output requires a change in the position of the mouth or the facial muscles used to produce speech.

  • BookmarkReached. Raised when the synthesizer encounters a bookmark in a prompt.

  • VoiceChange. Raised when the speaking voice for the synthesizer changes.

  • SpeakCompleted. Raised when the synthesizer finishes processing a SpeakSsmlAsync operation.

If your application dos not need to perform tasks while speaking, you can use the Speak or the SpeakSsml method to generate speech synchronously.

Applies to