添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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 ,請使用 SetOutputToAudioStreamSetOutputToDefaultAudioDeviceSetOutputToNullSetOutputToWaveFile 方法。

  • 若要產生語音,請使用 SpeakSpeakAsyncSpeakSsmlSpeakSsmlAsync 方法。 SpeechSynthesizer可以從文字、 PromptPromptBuilder 物件或語音合成標記語言產生語音, (SSML) 1.0 版

  • 若要暫停和繼續語音合成,請使用 PauseResume 方法。

  • 若要新增或移除語彙,請使用 AddLexiconRemoveLexicon 方法。 SpeechSynthesizer可以使用一或多個語彙來引導其單字發音。

  • 若要修改語音輸出的傳遞,請使用 RateVolume 屬性。

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

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

  •