TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) Method


以指定的輸出格式來呈現指定的 TextFragment 陣列。Renders specified TextFragment array in the specified output format.

 abstract void Speak(cli::array <System::Speech::Synthesis::TtsEngine::TextFragment ^> ^ fragment, IntPtr waveHeader, System::Speech::Synthesis::TtsEngine::ITtsEngineSite ^ site);
public abstract void Speak (System.Speech.Synthesis.TtsEngine.TextFragment[] fragment, IntPtr waveHeader, System.Speech.Synthesis.TtsEngine.ITtsEngineSite site);
abstract member Speak : System.Speech.Synthesis.TtsEngine.TextFragment[] * nativeint * System.Speech.Synthesis.TtsEngine.ITtsEngineSite -> unit
Public MustOverride Sub Speak (fragment As TextFragment(), waveHeader As IntPtr, site As ITtsEngineSite)



TextFragment執行個體的陣列,其中包含要轉換成語音的文字。An array of TextFragment instances containing the text to be rendered into speech.

IntPtr IntPtr IntPtr IntPtr

IntPtr,指向包含音訊輸出格式的結構。An IntPtr pointing to a structure containing audio output format.

ITtsEngineSite ITtsEngineSite ITtsEngineSite ITtsEngineSite

由平台基礎結構傳入ITtsEngineSite介面參考,以允許存取基礎結構資源。A reference to an ITtsEngineSite interface passed in by the platform infrastructure to allow access to the infrastructure resources.


以下範例是自訂語音TtsEngineSsml合成實作為繼承自的一部分, 並使用TextFragmentSpeechEventInfo FragmentState、和TtsEventIdThe example below is part of a custom speech synthesis implementation inheriting from TtsEngineSsml, and using the use of TextFragment, SpeechEventInfo, FragmentState, and TtsEventId

的執行SpeakThe implementation of Speak

  1. 接收實例的TextFragment陣列, 並建立要傳遞至基礎TextFragment合成引擎上方法的Speak新實例陣列。Receives an array of TextFragment instances and creates a new array of TextFragment instances to be passed to the Speak method on an underlying synthesis engine.

  2. Action FragmentState Speak如果在每個State實例的屬性所傳回之的屬性中找到的列舉值為,則會執行TtsEngineAction TextFragmentIf the TtsEngineAction enumeration value by found from the Action property on the FragmentState returned by the State property of each TextFragment instance is Speak, the implementation

    • 在要讀出的文字中, 將 Americanism 轉譯為 Britishisms。Translates Americanism to Britishisms in the text to be spoken.

    • 如果提供EventInterest ITtsEngineSite 給實SpeechEventInfo作為之介面上的屬性支援事件種類,則會使用實例來建立事件,以驅動合成器進度計量器的建立。WordBoundaryIf the EventInterest property on the ITtsEngineSite interfaces provided to the implementation support the WordBoundary event type, a SpeechEventInfo instance is used to create an event to drive a synthesizer progress meter is created.

  3. 然後使用修改過TextFragment的陣列呼叫語音轉譯引擎。A speech rendering engine is then called with the modified TextFragment array.

private const int WordBoundaryFlag = 1 << (int)TtsEventId.WordBoundary;  
private readonly char[] spaces = new char[] { ' ', '\t', '\r', '\n' };  
internal struct UsVsUk  
  internal string UK;  
  internal string US;  

override public void Speak (TextFragment [] frags, IntPtr wfx, ITtsEngineSite site)  
  TextFragment [] newFrags=new TextFragment[frags.Length];  

  for (int i=0;i<frags.Length;i++){  
    newFrags[i].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,  
    newFrags[i].TextLength = newFrags[i].TextToSpeak.Length;  
    newFrags[i].TextOffset = 0;  
    if (newFrags[i].State.Action == TtsEngineAction.Speak) {  
      //Us to UK conversion  
      foreach (UsVsUk term in TransList) {  
      newFrags[i].TextToSpeak.Replace(term.US, term.UK);  
      //Generate progress meter events if supported  
      if ((site.EventInterest & WordBoundaryFlag) != 0) {  
      string[] subs = newFrags[i].TextToSpeak.Split(spaces);  

      foreach (string s in subs) {  
        int offset = newFrags[i].TextOffset;  
        SpeechEventInfo spEvent = new SpeechEventInfo((Int16)TtsEventId.WordBoundary,   
                 s.Length, new IntPtr(offset));  
        offset += s.Length;  
        if (s.Trim().Length > 0) {  
          SpeechEventInfo[] events = new SpeechEventInfo[1];  
          events[0] = spEvent;  
          site.AddEvents(events, 1);  
    _baseSynthesize.Speak(newFrags, wfx, site);  



方法所使用waveHeader的結構, 應該與在 SAPI 底下提供的WAVEFORMATEX相容。The structure used as waveHeader and returned by the method should compatible with the WAVEFORMATEX available under SAPI.

必須struct提供相當於的功能:The struct must provide functionality equivalent to:

internal struct WaveFormat  
    public Int16 FormatTag;  
    public Int16 Channels;  
    public int SamplesPerSec;  
    public int AvgBytesPerSec;  
    public Int16 BlockAlign;  
    public Int16 BitsPerSample;  
    public Int16 Size;  


自訂語音合成器TtsEngineSsmlSpeak(TextFragment[], IntPtr, ITtsEngineSite)使用並System.Speech.Synthesis透過命名空間的成員使用平臺基礎結構, 在合成應用程式之間進行篩選或媒介。基礎系統語音合成引擎。Custom speech synthesizer implements using TtsEngineSsml and Speak(TextFragment[], IntPtr, ITtsEngineSite) work as filters or intermediaries between synthesizer applications constructed using the platform infrastructure through the members of the System.Speech.Synthesis namespace and underlying system speech synthesis engines.

Speak(TextFragment[], IntPtr, ITtsEngineSite)執行:A Speak(TextFragment[], IntPtr, ITtsEngineSite) implementation: 1.1. 陷阱或修改傳入TextFragment物件的各個層面Traps or modify aspects of the incoming TextFragment objects 2.2. 使用ITtsEngineSite實例的網站參考, 產生任何必要的事件Generates any necessary events using the site reference to a ITtsEngineSite instance 3.3. 產生實際合成語音。Generates the actual synthesized speech.

語音的產生通常是藉由呼叫作業系統所提供的其中一個語音轉譯引擎來說話Generation of speech is most typically done by calling Speak on one of the speech rendering engines provided by the operating system.

如果未使用其中一個可用的語音轉譯引擎, 則繼承自TtsEngineSsml的物件必須建立自己的語音轉譯引擎。If one of the available speech rendering engines is not used, a object inheriting from TtsEngineSsml must create its own speech rendering engine.

使用登錄和反映取得的「說話」方法存取權。Access to the Speak method on obtained using the registry and reflection. 執行個體時提供 SQL Server 登入。.

當您繼承自TtsEngineSsml時, 您必須覆寫下列成員TtsEngineSsml(String): AddLexicon(Uri, String, ITtsEngineSite)RemoveLexicon(Uri, ITtsEngineSite)GetOutputFormat(SpeakOutputFormat, IntPtr)、和Speak(TextFragment[], IntPtr, ITtsEngineSite)When you inherit from TtsEngineSsml, you must override the following members: TtsEngineSsml(String), AddLexicon(Uri, String, ITtsEngineSite), RemoveLexicon(Uri, ITtsEngineSite), GetOutputFormat(SpeakOutputFormat, IntPtr), and Speak(TextFragment[], IntPtr, ITtsEngineSite).