SpeechEventInfo.Param2 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得並設定 System.IntPtr 該實例(param2 在建構子中)引用要傳遞給 Speech 平台的物件,以產生當前實例 SpeechEventInfo 用來請求的事件。
public:
property IntPtr Param2 { IntPtr get(); };
public IntPtr Param2 { get; }
member this.Param2 : nativeint
Public ReadOnly Property Param2 As IntPtr
屬性值
nativeint
當 的System.IntPtr當前實例所指定的事件產生時,會回傳SpeechEventInfo要傳遞給 Speech 平台的物件的參考。
範例
以下範例是繼承自 TtsEngineSsml、 TextFragmentSpeechEventInfoFragmentState及 的自訂語音合成實作的一部分TtsEventId
實作 Speak
接收一個實例陣列 TextFragment ,並建立一個新的實例陣列 TextFragment ,在底層合成引擎上傳遞給該
Speak方法。若從TtsEngineAction每個實例的屬性 ActionFragmentState 中找出StateTextFragment的枚舉值為 Speak,則實作
將美國主義翻譯成英語口語中的英語口語。
如果 EventInterest 實作介面上的屬性 ITtsEngineSite 支援事件 WordBoundary 類型,則會使用實 SpeechEventInfo 例建立事件以驅動合成器進度計量表。
包含 的SpeechEventInfoParam2參數用於記錄透過該
LogSpeechEvent方法產生的事件。
接著會呼叫語音渲染引擎,並使用修改過 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);
}
備註
屬性System.IntPtr的參考Param2SpeechEventInfo要求由 和 屬性的值EventIdParameterTypeSpeechEventInfo唯一決定。
關於如何使用 Param2,請參閱相關 EventId文件。