SpeechEventInfo.EventId SpeechEventInfo.EventId SpeechEventInfo.EventId SpeechEventInfo.EventId Property

定義

取得和設定使用 SpeechEventInfo 之執行個體進行要求的語音平台事件。Gets and set the Speech platform event which an instance of SpeechEventInfo is used to request.

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

屬性值

傳回 TtsEventId 的成員做為 short,表示 SpeechEventInfo 物件要產生的事件型別。Returns a member of TtsEventId as a short, indicating the event type the SpeechEventInfo object is to generate.

範例

下列範例是繼承自客製化語音合成器實作的一部分TtsEngineSsml,並使用將TextFragmentSpeechEventInfoFragmentState,及 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. 如果TtsEngineAction列舉值,藉由從找到Action屬性上的FragmentState所傳回State屬性的每個TextFragment執行個體是Speak,實作If 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

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

    • 如果EventInterest上的屬性ITtsEngineSite提供的實作支援介面WordBoundary事件類型、SpeechEventInfo執行個體用來建立事件,以便建立合成進度計量表的磁碟機。If 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.

      上的參數SpeechEventInfo,包括EventId用來記錄事件產生透過LogSpeechEvent方法。The parameters on SpeechEventInfo, including EventId are used to log the event generated through the LogSpeechEvent method.

  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].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);  

}  

適用於