SpeechEventInfo(Int16, Int16, Int32, IntPtr) SpeechEventInfo(Int16, Int16, Int32, IntPtr) SpeechEventInfo(Int16, Int16, Int32, IntPtr) SpeechEventInfo(Int16, Int16, Int32, IntPtr) Constructor

定義

建構適當的 SpeechEventInfoConstructs an appropriate SpeechEventInfo.

public:
 SpeechEventInfo(short eventId, short parameterType, int param1, IntPtr param2);
public SpeechEventInfo (short eventId, short parameterType, int param1, IntPtr param2);
new System.Speech.Synthesis.TtsEngine.SpeechEventInfo : int16 * int16 * int * nativeint -> System.Speech.Synthesis.TtsEngine.SpeechEventInfo
Public Sub New (eventId As Short, parameterType As Short, param1 As Integer, param2 As IntPtr)

參數

eventId
Int16 Int16 Int16 Int16

TtsEventId的執行個體,指出SpeechEventInfo 物件要處理的語音平台事件的排序。An instance of TtsEventId indicating the sort of Speech platform event the SpeechEventInfo object is to handle.

parameterType
Int16 Int16 Int16 Int16

EventParameterType的執行個體,指出param2System.IntPtr參考的解譯方式,以及隱含地指出param1的使用。An instance of EventParameterType indicating how the System.IntPtr reference of param2 is to be interpreted, and, by implication, the use of param1.

param1
Int32 Int32 Int32 Int32

當要建構的SpeechEventInfo的執行個體所要求的事件產生時,要傳遞至語音平台的整數值。An integer value to be passed to the Speech platform when the event requested by the instance of SpeechEventInfo to be constructed is generated.

這個整數的確切意義隱含取決於 parameterType 的值。The exact meaning of this integer is implicitly determined by the value of parameterType.

param2
IntPtr IntPtr IntPtr IntPtr

參考物件的 System.IntPtr 執行個體。A System.IntPtr instance referencing an object. 當要建構的 SpeechEventInfo 的執行個體所要求的事件產生時,要傳遞至語音平台的整數值。to be passed to the Speech platform when the event requested by the instance of SpeechEventInfo to be constructed is generated.

必須參考的型別是由 parameterType 值來明確定義的。The type which must be referenced is explicitly defined by the value parameterType. System.IntPtr.ZeroThe value System.IntPtr.Zero.

範例

以下範例是自訂語音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].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);  

}  

備註

parameterType TtsEventId eventId、、和所param2使用的允許值, 是由所要求的事件種類所決定, 如同用於的成員所指定。 param1Permitted values used for parameterType, param1, and param2 and their meaning is dictated by the type of event being requested, as specified by the member of TtsEventId used for eventId.

如需parameterTypeparam1param2之適當值的詳細資訊, 請參閱的檔EventIdFor detailed information on appropriate values for parameterType, param1, and param2, see documentation for EventId

可由語音平臺基礎結構處理的事件種類, 可以透過的合成器引擎網站EventInterest ITtsEngineSite執行上的屬性取得。The type of the events which can be handled by the Speech platform infrastructure can be obtained through the EventInterest property on the synthesizer engine site implementation of ITtsEngineSite.

適用於