SpeechSynthesizer 類別

定義

提供安裝的語音合成引擎功能的存取權。Provides access to the functionality of an installed speech synthesis engine.

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

範例

下列範例是主控台應用程式的一部分, 它會初始化SpeechSynthesizer物件並說出字串。The following example is part of a console application that initializes a SpeechSynthesizer object and speaks a string.

  
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的物件時, 它會使用預設的系統聲音。When you create a new SpeechSynthesizer object, it uses the default system voice. 若要將SpeechSynthesizer設定為使用其中一種已安裝的語音合成 (文字轉換語音) 語音, SelectVoiceSelectVoiceByHints使用或方法。To configure the SpeechSynthesizer to use one of the installed speech synthesis (text-to-speech) voices, use the SelectVoice or SelectVoiceByHints method. 若要取得已安裝之語音的相關資訊, GetInstalledVoices請使用方法VoiceInfo和類別。To get information about which voices are installed, use the GetInstalledVoices method and the VoiceInfo class.

此類別也可讓您控制語音合成的下列層面:This class also provides control over the following aspects of speech synthesis:

SpeechSynthesizer它在提示中遇到特定功能時, 會引發BookmarkReached事件: VisemeReached(、 SpeakProgress PhonemeReached、和)。The SpeechSynthesizer raises events when it encounters certain features in prompts: (BookmarkReached, PhonemeReached, VisemeReached, and SpeakProgress). 它也會引發事件, 以報告說話作業SpeakStarted的開始 ()SpeakCompleted和結束 (), 以及說話語音 (VoiceChange) 的變更。It also raises events that report on the start (SpeakStarted) and end (SpeakCompleted) of speak operations and on the change of the speaking voice (VoiceChange).

注意

在您釋放最後一個 Dispose 參考之前,請務必呼叫 SpeechSynthesizerAlways call Dispose before you release your last reference to the SpeechSynthesizer. 否則工作窗格所使用的資源不會釋放,直到記憶體回收行程呼叫 SpeechSynthesizer 物件的 Finalize 方法。Otherwise, the resources it is using will not be freed until the garbage collector calls the SpeechSynthesizer object's Finalize method.

建構函式

SpeechSynthesizer()

初始化 SpeechSynthesizer 類別的新執行個體。Initializes a new instance of the SpeechSynthesizer class.

屬性

Rate

取得或設定 SpeechSynthesizer 物件的讀出速率。Gets or sets the speaking rate of the SpeechSynthesizer object.

State

取得 SpeechSynthesizer 物件目前的讀出狀態。Gets the current speaking state of the SpeechSynthesizer object.

Voice

取得目前 SpeechSynthesizer 物件之語音的相關資訊。Gets information about the current voice of the SpeechSynthesizer object.

Volume

取得或設定 SpeechSynthesizer 物件的輸出音量。Get or sets the output volume of the SpeechSynthesizer object.

方法

AddLexicon(Uri, String)

將字典加入至 SpeechSynthesizer 物件。Adds a lexicon to the SpeechSynthesizer object.

Dispose()

處置 SpeechSynthesizer 物件,並釋放工作階段期間所使用的資源。Disposes the SpeechSynthesizer object and releases resources used during the session.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Finalize()

在未呼叫 Dispose() 方法時,做為清除資源的防護措施。Acts as a safeguard to clean up resources in the event that the Dispose() method is not called.

GetCurrentlySpokenPrompt()

取得 SpeechSynthesizer 正在讀出的提示。Gets the prompt that the SpeechSynthesizer is speaking.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetInstalledVoices()

傳回所有已安裝的語音合成 (文字轉換語音) 語音。Returns all of the installed speech synthesis (text-to-speech) voices.

GetInstalledVoices(CultureInfo)

傳回支援特定地區設定的所有已安裝語音合成 (文字轉換語音) 語音。Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
Pause()

暫停 SpeechSynthesizer 物件。Pauses the SpeechSynthesizer object.

RemoveLexicon(Uri)

SpeechSynthesizer 物件中移除字典。Removes a lexicon from the SpeechSynthesizer object.

Resume()

在暫停 SpeechSynthesizer 物件之後使其繼續。Resumes the SpeechSynthesizer object after it has been paused.

SelectVoice(String)

依名稱選取特定的語音。Selects a specific voice by name.

SelectVoiceByHints(VoiceGender)

選取特定性別的語音。Selects a voice with a specific gender.

SelectVoiceByHints(VoiceGender, VoiceAge)

選取特定性別和年齡的語音。Selects a voice with a specific gender and age.

SelectVoiceByHints(VoiceGender, VoiceAge, Int32)

根據已排序的語音位置,選取特定性別和年齡的語音。Selects a voice with a specific gender and age, based on the position in which the voices are ordered.

SelectVoiceByHints(VoiceGender, VoiceAge, Int32, CultureInfo)

根據已排序的語音位置,選取特定性別、年齡和地區設定的語音。Selects a voice with a specific gender, age, and locale, based on the position in which the voices are ordered.

SetOutputToAudioStream(Stream, SpeechAudioFormatInfo)

設定SpeechSynthesizer物件,以便將輸出附加至音訊資料流。Configures the SpeechSynthesizer object to append output to an audio stream.

SetOutputToDefaultAudioDevice()

設定SpeechSynthesizer物件,以便將輸出傳送至預設音訊裝置。Configures the SpeechSynthesizer object to send output to the default audio device.

SetOutputToNull()

設定SpeechSynthesizer物件,不將來自合成作業的輸出傳送至裝置、檔案或資料流。Configures the SpeechSynthesizer object to not send output from synthesis operations to a device, file, or stream.

SetOutputToWaveFile(String)

設定SpeechSynthesizer物件,以便將輸出附加至包含波形格式音訊的檔案。Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio.

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

設定SpeechSynthesizer物件,以便將輸出附加至指定格式的波形音訊格式檔案。Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format.

SetOutputToWaveStream(Stream)

設定SpeechSynthesizer物件,以便將輸出附加至包含波形格式音訊的資料流。Configures the SpeechSynthesizer object to append output to a stream that contains Waveform format audio.

Speak(Prompt)

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

Speak(PromptBuilder)

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

Speak(String)

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

SpeakAsync(Prompt)

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

SpeakAsync(PromptBuilder)

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

SpeakAsync(String)

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

SpeakAsyncCancel(Prompt)

取消已佇列提示的非同步合成作業。Cancels the asynchronous synthesis operation for a queued prompt.

SpeakAsyncCancelAll()

取消所有已佇列、非同步的語音合成作業。Cancels all queued, asynchronous, speech synthesis operations.

SpeakSsml(String)

以同步方式讀出包含 SSML 標記的 StringSynchronously speaks a String that contains SSML markup.

SpeakSsmlAsync(String)

以非同步方式讀出包含 SSML 標記的 StringAsynchronously speaks a String that contains SSML markup.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

BookmarkReached

SpeechSynthesizer 在提示中遇到書籤時引發。Raised when the SpeechSynthesizer encounters a bookmark in a prompt.

PhonemeReached

到達音素時引發。Raised when a phoneme is reached.

SpeakCompleted

SpeechSynthesizer 完成讀出提示時引發。Raised when the SpeechSynthesizer completes the speaking of a prompt.

SpeakProgress

SpeechSynthesizer 說出提示的每個字之後引發。Raised after the SpeechSynthesizer speaks each individual word of a prompt.

SpeakStarted

SpeechSynthesizer 開始讀出提示時引發。Raised when the SpeechSynthesizer begins the speaking of a prompt.

StateChanged

變更 SpeechSynthesizer 的狀態時引發。Raised when the state of the SpeechSynthesizer changes.

VisemeReached

到達視素 (Viseme) 時引發。Raised when a viseme is reached.

VoiceChange

變更 SpeechSynthesizer 的語音時引發。Raised when the voice of the SpeechSynthesizer changes.

適用於

另請參閱