SpeechSynthesizer.Speak SpeechSynthesizer.Speak SpeechSynthesizer.Speak SpeechSynthesizer.Speak Method

定義

以同步方式從字串、Prompt 物件或 PromptBuilder 物件產生語音輸出。Generates speech output synchronously from a string, a Prompt object, or a PromptBuilder object.

多載

Speak(Prompt) Speak(Prompt) Speak(Prompt)

以同步方式讀出 Prompt 物件的內容。Synchronously speaks the contents of a Prompt object.

Speak(PromptBuilder) Speak(PromptBuilder) Speak(PromptBuilder)

以同步方式讀出 PromptBuilder 物件的內容。Synchronously speaks the contents of a PromptBuilder object.

Speak(String) Speak(String) Speak(String) Speak(String)

以同步方式讀出字串的內容。Synchronously speaks the contents of a string.

備註

Speak方法會以同步方式產生語音。The Speak methods generate speech synchronously. 除非已完全讀出Speak實例的內容, 否則方法不會傳回。The methods do not return until the content of the Speak instance has been completely spoken. 這是產生語音的最簡單方式。This is the simplest way to generate speech. 不過, 如果您的應用程式需要在說話時執行工作, 例如反白顯示文字、繪製動畫、監視器控制項或其他工作, SpeakAsync請使用方法SpeakSsmlAsync或方法, 以非同步方式產生語音。However, if your application needs to perform tasks while speaking, for example highlight text, paint animation, monitor controls, or other tasks, use the SpeakAsync methods or the SpeakSsmlAsync method to generate speech asynchronously.

呼叫這個方法時, 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處理任何方法SpeakSpeakCompleted , 不會引發事件。The SpeechSynthesizer does not raise the SpeakCompleted event while processing any of the Speak methods.

Speak(Prompt) Speak(Prompt) Speak(Prompt)

以同步方式讀出 Prompt 物件的內容。Synchronously speaks the contents of a Prompt object.

public:
 void Speak(System::Speech::Synthesis::Prompt ^ prompt);
public void Speak (System.Speech.Synthesis.Prompt prompt);
member this.Speak : System.Speech.Synthesis.Prompt -> unit

參數

prompt
Prompt Prompt Prompt Prompt

要讀出的內容。The content to speak.

範例

下列範例會從字串Prompt建立物件, 並將物件當做引數傳遞Speak給方法。The following example creates a Prompt object from a string and passes the object as an argument to the Speak method.

using System;  
using System.Speech.Synthesis;  
  
namespace SampleSynthesis  
{  
  class Program  
  {  
    static void Main(string[] args)  
    {  
  
      // Initialize a new instance of the SpeechSynthesizer.  
      using (SpeechSynthesizer synth = new SpeechSynthesizer())  
      {  
  
        // Configure the audio output.   
        synth.SetOutputToDefaultAudioDevice();  
  
        // Create a prompt from a string.  
        Prompt color = new Prompt("What is your favorite color?");  
  
        // Speak the contents of the prompt synchronously.  
        synth.Speak(color);  
      }  
  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  
  }  
}  

備註

若要以非同步方式朗讀Prompt物件的內容, 請使用。 SpeakAsyncTo asynchronously speak the contents of a Prompt object, use SpeakAsync.

Speak(PromptBuilder) Speak(PromptBuilder) Speak(PromptBuilder)

以同步方式讀出 PromptBuilder 物件的內容。Synchronously speaks the contents of a PromptBuilder object.

public:
 void Speak(System::Speech::Synthesis::PromptBuilder ^ promptBuilder);
public void Speak (System.Speech.Synthesis.PromptBuilder promptBuilder);
member this.Speak : System.Speech.Synthesis.PromptBuilder -> unit

參數

promptBuilder
PromptBuilder PromptBuilder PromptBuilder PromptBuilder

要讀出的內容。The content to speak.

範例

下列範例會從字串PromptBuilder建立物件, 並將物件當做引數傳遞Speak給方法。The following example creates a PromptBuilder object from a string and passes the object as an argument to the Speak method.

using System;  
using System.Speech.Synthesis;  
  
namespace SampleSynthesis  
{  
  class Program  
  {  
    static void Main(string[] args)  
    {  
  
      // Initialize a new instance of the SpeechSynthesizer.  
      using (SpeechSynthesizer synth = new SpeechSynthesizer())  
      {  
  
        // Configure the audio output.   
        synth.SetOutputToDefaultAudioDevice();  
  
        // Create a PromptBuilder object and append a text string.  
        PromptBuilder song = new PromptBuilder();  
        song.AppendText("Say the name of the song you want to hear");  
  
        // Speak the contents of the prompt synchronously.  
        synth.Speak(song);  
      }  
  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  
  }  
}  

備註

若要以非同步方式朗讀PromptBuilder物件的內容, 請使用。 SpeakAsyncTo asynchronously speak the contents of a PromptBuilder object, use SpeakAsync.

Speak(String) Speak(String) Speak(String) Speak(String)

以同步方式讀出字串的內容。Synchronously speaks the contents of a string.

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

參數

textToSpeak
String String String String

要讀出的文字。The text to speak.

範例

如下列範例所示, Speak方法提供最簡單的方式來同步產生語音輸出。As shown in the following example, the Speak method provides the simplest means to generate speech output synchronously.

using System;  
using System.Speech.Synthesis;  
  
namespace SampleSynthesis  
{  
  class Program  
  {  
    static void Main(string[] args)  
    {  
  
      // Initialize a new instance of the SpeechSynthesizer.  
      using (SpeechSynthesizer synth = new SpeechSynthesizer())  
      {  
  
        // Configure the audio output.   
        synth.SetOutputToDefaultAudioDevice();  
  
        // Speak a string synchronously.  
        synth.Speak("What is your favorite color?");  
      }  
  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  
  }  
}  

備註

若要同步地說出包含 SSML 標記的字串, SpeakSsml請使用方法。To synchronously speak a string that contains SSML markup, use the SpeakSsml method. 若要以非同步方式說出字串的內容, SpeakAsync請使用方法。To asynchronously speak the contents of a string, use the SpeakAsync method.

適用於