SpeechSynthesizer.SpeakSsml(String) 方法

定义

同步包含 SSML 标记的 String 的语言。Synchronously speaks a String that contains SSML markup.

public:
 void SpeakSsml(System::String ^ textToSpeak);
public void SpeakSsml (string textToSpeak);
member this.SpeakSsml : string -> unit
Public Sub SpeakSsml (textToSpeak As String)

参数

textToSpeak
String

要朗读的 SSML。The SSML string to speak.

示例

下面的示例将日期1/29/2009 呈现为日期,以月、日、年顺序显示。The following example renders the date 1/29/2009 as a date, in month, day, year order.

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 synchronously.
      synth.SpeakSsml(str);  

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

注解

参数的内容 textToSpeak 必须包括一个 speak 元素,并且必须符合 语音合成标记语言 (SSML) 版本 1.0The 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.

若要以异步方式口述包含 SSML 标记的字符串,请使用 SpeakSsmlAsync 方法。To asynchronously speak a string that contains SSML markup, use the SpeakSsmlAsync method. 您可以使用 Speak 来启动同步,而不包含 SSML 标记的字符串。You can use Speak to initiate the synchronous speaking of a string that does not contain SSML markup.

在调用此方法的过程中, SpeechSynthesizer 可能会引发以下事件:During a call to this method, the SpeechSynthesizer can raise the following events:

  • StateChanged.StateChanged. 合成器的讲述状态更改时引发。Raised when the speaking state of the synthesizer changes.

  • SpeakStarted.SpeakStarted. 合成器开始生成语音时引发。Raised when the synthesizer begins generating speech.

  • PhonemeReached.PhonemeReached. 每次合成器达到一种语言的字母或字母组合时引发。Raised each time the synthesizer reaches a letter or combination of letters that constitute a discreet sound of speech in a language.

  • SpeakProgress.SpeakProgress. 每次合成器完成字词时引发。Raised each time the synthesizer completes speaking a word.

  • VisemeReached.VisemeReached. 每次出现口述输出时,需要更改嘴或用于生成语音的面部肌肉的位置。Raised each time spoken output requires a change in the position of the mouth or the facial muscles used to produce speech.

  • BookmarkReached.BookmarkReached. 当合成器在提示符处遇到书签时引发。Raised when the synthesizer encounters a bookmark in a prompt.

  • VoiceChange.VoiceChange. 合成器的说话声音发生变化时引发。Raised when the speaking voice for the synthesizer changes.

SpeechSynthesizer SpeakCompleted 处理方法时不会引发事件 SpeakSsmlThe SpeechSynthesizer does not raise the SpeakCompleted event while processing the SpeakSsml method.

适用于