Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
SpeechSynthesizer.SpeakSsmlAsync Method
Asynchronously speaks a String that contains SSML markup.
Namespace: Microsoft.Speech.Synthesis
Assembly: Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
'Declaration
Public Function SpeakSsmlAsync ( _
textToSpeak As String _
) As Prompt
'Usage
Dim instance As SpeechSynthesizer
Dim textToSpeak As String
Dim returnValue As Prompt
returnValue = instance.SpeakSsmlAsync(textToSpeak)
public Prompt SpeakSsmlAsync(
string textToSpeak
)
Parameters
- textToSpeak
Type: System.String
The SMML markup to speak.
Return Value
Type: Microsoft.Speech.Synthesis.Prompt
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 (Microsoft.Speech).
To synchronously speak a string that contains SSML markup, use the SpeakSsml(String) method. You can use SpeakAsync(String) 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.
SpeakProgress. Raised each time the synthesizer completes speaking a word.
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(String) operation.
Examples
using System;
using Microsoft.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.SetOutputToWaveFile(@"C:\Test\Date.wav");
// Register for the SpeakCompleted event.
synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);
// 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();
}
// Handle the SpeakCompleted event.
static void synth_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
// Create a SoundPlayer instance to play the output audio file.
System.Media.SoundPlayer m_SoundPlayer =
new System.Media.SoundPlayer(@"C:\Test\Date.wav");
// Play the output file.
m_SoundPlayer.Play();
}
}
}