Use SSML to Control Synthesized Speech
You can use the AppendSsmlMarkup(String) method to append a string containing Speech Synthesis Markup Language (SSML) to a prompt. This topic shows simple examples that use a variety of SSML elements in prompts to control speech output. For more information about SSML elements, see Speech Synthesis Markup Language Reference.
Using the voice element, you can select an installed text-to-speech (TTS) engine to speak the content of a prompt. For more information, see voice Element. You can specify the voice to use by name, or you can let the SpeechSynthesizer object select an installed voice that matches one or more attributes which you specify. The following example uses the xml:lang attribute of the voice element to specify an English speaking voice.
SpeechSynthesizer synth = new SpeechSynthesizer(); PromptBuilder pb = new PromptBuilder(); pb.AppendSsmlMarkup("<voice xml:lang=\"en-US\">"); pb.AppendText("This is an example of a voice that speaks English as spoken in the United States of America."); pb.AppendSsmlMarkup("</voice>"); synth.Speak(pb);
Speech synthesis is often referred to as text-to-speech or TTS. A voice contains the information that a TTS engine needs to generate speech in a specific language. An TTS engine can use any voice installed on the system to perform speech synthesis. See InstalledVoice for more information.
You can use the prosody element to control the pitch, volume, and speaking rate for synthesized speech output. For more information, see prosody Element. The following example creates three strings containing SSML markup that demonstrate control of the pitch, volume, and speaking rate characteristics of a voice. The example creates a PromptBuilder object and appends each of the three strings, and then passes the PromptBuilder as an argument to the Speak(PromptBuilder) method of the SpeechSynthesizer object.
SpeechSynthesizer synth = new SpeechSynthesizer(); PromptBuilder pb1 = new PromptBuilder(); string high = "<prosody pitch=\"x-high\"> This is extra high pitch. </prosody >"; string loud = "<prosody volume=\"x-loud\"> This is extra loud volume. </prosody>"; string slow = "<prosody rate=\"slow\"> This is the slow speaking rate. </prosody>"; pb1.AppendSsmlMarkup(high); pb1.AppendSsmlMarkup(loud); pb1.AppendSsmlMarkup(slow); synth.Speak(pb1);
The audio element can be used to append audio to a prompt. In the following example, the synthesizer speaks “Substitute text” if it cannot find or play the audio file. For more information, see audio Element.
The sub element can be used to provide alternate text to be rendered. In the following example, the synthesizer speaks “First in first out". For more information, see sub Element.
You can use the phoneme element to render speech by its phonetic pronunciation. For more information, see phoneme Element. The following example creates a prompt that, when played, renders the Spanish word "llama" approximately as it would be spoken in Mexican Spanish. The SpeechSynthesizer ignores the contents of the phoneme element (llama) and speaks the phonetic spelling contained by the ph attribute.