SpeechEventInfo.EventId 屬性

定義

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

public:
 property short EventId { short get(); };
public short EventId { get; }
member this.EventId : int16
Public ReadOnly Property EventId As Short

屬性值

Int16

傳回 TtsEventId 的成員做為 short,表示 SpeechEventInfo 物件要產生的事件型別。

範例

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

的執行 Speak

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

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

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

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

      上的參數 SpeechEventInfo (包括) EventId 會用來記錄透過方法所產生的事件 LogSpeechEvent

  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));  
         LogSpeechEvent(spEvent.EventId,   
                        spEvent.ParameterType,   
                        spEvent.Param1,  
                        spEvent.Param2);  
        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);  

}  

適用於