SpeechSynthesizer.SpeakSsmlAsync(String) 方法

定義

以非同步方式讀出包含 SSML 標記的 String

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

參數

textToSpeak
String

要讀出的 SMML 標記。

傳回

包含要說話之內容的 物件。

例外狀況

textToSpeaknull

範例

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

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用狀況例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用狀況例外狀況,例如 ArgumentException ,仍會同步擲回。 如需預存的例外狀況,請參閱 所 SpeakSsml(String) 擲回的例外狀況。

備註

參數的內容 textToSpeak 必須包含 speak 元素,且必須符合 語音合成標記語言 (SSML) 1.0 版。 如需詳細資訊,請參閱 語音合成標記語言參考

若要以同步方式說出包含 SSML 標記的字串,請使用 SpeakSsml 方法。 您可以使用 SpeakAsync 來起始不包含 SSML 標記之字串的非同步說話。

在呼叫此方法期間, SpeechSynthesizer 可以引發下列事件:

如果您的應用程式不需要在說話時執行工作,您可以使用 SpeakSpeakSsml 方法來同步產生語音。

適用於