SpeechEventInfo 結構

定義

用來指定要在自訂合成語音引擎將文字轉譯為語音過程中產生之事件的型別及其引數 (如果有的話)。

public value class SpeechEventInfo : IEquatable<System::Speech::Synthesis::TtsEngine::SpeechEventInfo>
public struct SpeechEventInfo : IEquatable<System.Speech.Synthesis.TtsEngine.SpeechEventInfo>
type SpeechEventInfo = struct
Public Structure SpeechEventInfo
Implements IEquatable(Of SpeechEventInfo)
繼承
SpeechEventInfo
實作

範例

下列範例是自訂語音合成衍生的一部分 TtsEngineSsml ,並使用 TextFragmentSpeechEventInfoFragmentStateTtsEventId

的執行 Speak

  1. 接收實例的陣列 TextFragment ,並建立新的實例陣列, TextFragment 以傳遞至 Speak 基礎合成引擎上的方法。

  2. 如果在 TtsEngineAction Action FragmentState State 每個實例之屬性所傳回的屬性中找到列舉值,則 TextFragmentSpeak 執行

    • 將要說出的文字中的 Americanism 轉譯為 Britishisms。

    • 如果 EventInterest 提供給實作為的介面上的屬性 ITtsEngineSite 支援 WordBoundary 事件種類,則 SpeechEventInfo 會使用實例來建立事件,以建立可驅動合成器進度計量的事件。

  3. 接著會使用修改過的陣列來呼叫語音轉譯引擎 TextFragment

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].State=frags[i].State;  
    //truncate  
    newFrags[i].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,  
                               frags[i].TextLength);  
    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,   
                (Int16)EventParameterType.Undefined,   
                 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);  

}  

備註

自訂語音合成引擎會在語音平臺下要求產生事件,方法是提供適當的 SpeechEventInfo 實例給 AddEvents ITtsEngineSite 傳遞給、和之執行的引擎網站物件成員 Speak AddLexicon RemoveLexicon

建構函式

SpeechEventInfo(Int16, Int16, Int32, IntPtr)

建構適當的 SpeechEventInfo

屬性

EventId

取得和設定使用 SpeechEventInfo 之執行個體進行要求的語音平台事件。

Param1

取得和設定 integer值 (建構函式中的 param1),這個值要傳遞至語音平台以產生使用 SpeechEventInfo 之目前執行個體進行要求的事件。

Param2

取得和設定 System.IntPtr執行個體 (建構函式中的 param2),這個執行個體所參考的物件要傳遞至語音平台以產生使用 SpeechEventInfo 之目前執行個體進行要求的事件。

ParameterType

傳回目前 Param2 物件上 SpeechEventInfo 參數所傳回的 IntPtr 所指向之物件的資料型別。

方法

Equals(Object)

判斷指定的物件是否為 SpeechEventInfo 的執行個體且等於 SpeechEventInfo 目前的執行個體。

Equals(SpeechEventInfo)

判斷指定的 SpeechEventInfo 物件是否等於 SpeechEventInfo 目前的執行個體。

GetHashCode()

提供 SpeechEventInfo 物件的雜湊碼。

運算子

Equality(SpeechEventInfo, SpeechEventInfo)

判斷 SpeechEventInfo 的兩個執行個體是否相等。

Inequality(SpeechEventInfo, SpeechEventInfo)

判斷 SpeechEventInfo 的兩個執行個體是否不相等。

適用於