SpeechSynthesizer 類別

定義

提供安裝的語音合成引擎功能的存取權。

public ref class SpeechSynthesizer sealed : IDisposable
public sealed class SpeechSynthesizer : IDisposable
type SpeechSynthesizer = class
    interface IDisposable
Public NotInheritable Class SpeechSynthesizer
Implements IDisposable
繼承
SpeechSynthesizer
實作

範例

下列範例是初始化 物件並讀出字串之主控台應用程式的 SpeechSynthesizer 一部分。

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

      // Speak a string.
      synth.Speak("This example demonstrates a basic use of Speech Synthesizer");

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

備註

當您建立新的 SpeechSynthesizer 物件時,它會使用預設的系統語音。 若要將 設定 SpeechSynthesizer 為使用其中一個已安裝的語音合成 (文字轉換語音) 語音,請使用 SelectVoiceSelectVoiceByHints 方法。 若要取得已安裝哪些語音的相關資訊,請使用 GetInstalledVoices 方法和 VoiceInfo 類別。

此類別也提供語音合成下列層面的控制:

SpeechSynthesizer會在出現提示時引發事件: (BookmarkReachedPhonemeReachedVisemeReachedSpeakProgress) 。 它也會引發事件,這些事件會報告說話作業的開始 (SpeakStarted) 和結束 (SpeakCompleted) ,以及說話語音 () VoiceChange 的變更。

注意

在您釋放最後一個 Dispose 參考之前,請務必呼叫 SpeechSynthesizer。 否則工作窗格所使用的資源不會釋放,直到記憶體回收行程呼叫 SpeechSynthesizer 物件的 Finalize 方法。

建構函式

SpeechSynthesizer()

初始化 SpeechSynthesizer 類別的新執行個體。

屬性

Rate

取得或設定 SpeechSynthesizer 物件的讀出速率。

State

取得 SpeechSynthesizer 物件目前的讀出狀態。

Voice

取得目前 SpeechSynthesizer 物件之語音的相關資訊。

Volume

取得或設定 SpeechSynthesizer 物件的輸出音量。

方法

AddLexicon(Uri, String)

將字典加入至 SpeechSynthesizer 物件。

Dispose()

處置 SpeechSynthesizer 物件,並釋放工作階段期間所使用的資源。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
Finalize()

在未呼叫 Dispose() 方法時,做為清除資源的防護措施。

GetCurrentlySpokenPrompt()

取得 SpeechSynthesizer 正在讀出的提示。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetInstalledVoices()

傳回所有已安裝的語音合成 (文字轉換語音) 語音。

GetInstalledVoices(CultureInfo)

傳回支援特定地區設定的所有已安裝語音合成 (文字轉換語音) 語音。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Pause()

暫停 SpeechSynthesizer 物件。

RemoveLexicon(Uri)

SpeechSynthesizer 物件中移除字典。

Resume()

在暫停 SpeechSynthesizer 物件之後使其繼續。

SelectVoice(String)

依名稱選取特定的語音。

SelectVoiceByHints(VoiceGender)

選取特定性別的語音。

SelectVoiceByHints(VoiceGender, VoiceAge)

選取特定性別和年齡的語音。

SelectVoiceByHints(VoiceGender, VoiceAge, Int32)

根據已排序的語音位置,選取特定性別和年齡的語音。

SelectVoiceByHints(VoiceGender, VoiceAge, Int32, CultureInfo)

根據已排序的語音位置,選取特定性別、年齡和地區設定的語音。

SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)

設定SpeechSynthesizer物件,以便將輸出附加至音訊資料流。

SetOutputToDefaultAudioDevice()

設定SpeechSynthesizer物件,以便將輸出傳送至預設音訊裝置。

SetOutputToNull()

設定SpeechSynthesizer物件,不將來自合成作業的輸出傳送至裝置、檔案或資料流。

SetOutputToWaveFile(String)

設定SpeechSynthesizer物件,以便將輸出附加至包含波形格式音訊的檔案。

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

設定SpeechSynthesizer物件,以便將輸出附加至指定格式的波形音訊格式檔案。

SetOutputToWaveStream(Stream)

設定SpeechSynthesizer物件,以便將輸出附加至包含波形格式音訊的資料流。

Speak(Prompt)

以同步方式讀出 Prompt 物件的內容。

Speak(PromptBuilder)

以同步方式讀出 PromptBuilder 物件的內容。

Speak(String)

以同步方式讀出字串的內容。

SpeakAsync(Prompt)

以非同步方式讀出 Prompt 物件的內容。

SpeakAsync(PromptBuilder)

以非同步方式讀出 PromptBuilder 物件的內容。

SpeakAsync(String)

以非同步方式讀出字串的內容。

SpeakAsyncCancel(Prompt)

取消已佇列提示的非同步合成作業。

SpeakAsyncCancelAll()

取消所有已佇列、非同步的語音合成作業。

SpeakSsml(String)

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

SpeakSsmlAsync(String)

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

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

事件

BookmarkReached

SpeechSynthesizer 在提示中遇到書籤時引發。

PhonemeReached

到達音素時引發。

SpeakCompleted

SpeechSynthesizer 完成讀出提示時引發。

SpeakProgress

SpeechSynthesizer 說出提示的每個字之後引發。

SpeakStarted

SpeechSynthesizer 開始讀出提示時引發。

StateChanged

變更 SpeechSynthesizer 的狀態時引發。

VisemeReached

到達視素 (Viseme) 時引發。

VoiceChange

變更 SpeechSynthesizer 的語音時引發。

適用於

另請參閱