SpeechEventInfo.Param2 屬性

定義

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

public:
 property IntPtr Param2 { IntPtr get(); };
public IntPtr Param2 { get; }
member this.Param2 : nativeint
Public ReadOnly Property Param2 As IntPtr

屬性值

IntPtr

nativeint

傳回 System.IntPtr,參考在目前的 SpeechEventInfo 執行個體所指定的事件產生時,要傳遞至語音平台的物件。

範例

下列範例是繼承自 TtsEngineSsml 的自訂語音合成實作的一部分,並使用 TextFragmentSpeechEventInfoFragmentStateTtsEventId

的實作 Speak

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

  2. TtsEngineAction如果從 Action 每個 TextFragment 實例之 屬性所 State 傳回之 上的 屬性 FragmentState 找到的列舉值為 Speak ,則實作

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

}  

備註

屬性參考 SpeechEventInfoParam2 的需求 System.IntPtr 是由 實例的 EventIdParameterType 屬性 SpeechEventInfo 的值所唯一決定。

如需如何使用 Param2 的詳細資訊,請參閱 的檔。 EventId

適用於