SpeechEventInfo 结构

定义

用于指定事件的类型及其将生成的参数(如果有的话)作为文本呈现到语音一部分由自定义复合语音引擎。Used to specify the type of event, and its arguments (if any) to be generated as part of the rendering of text to speech by a custom synthetic speech engine.

public value class SpeechEventInfo : IEquatable<System::Speech::Synthesis::TtsEngine::SpeechEventInfo>
public struct SpeechEventInfo : IEquatable<System.Speech.Synthesis.TtsEngine.SpeechEventInfo>
type SpeechEventInfo = struct
Public Structure SpeechEventInfo
Implements IEquatable(Of SpeechEventInfo)
继承
SpeechEventInfo
实现

示例

下面的示例是自定义语音合成实现的一部分,该实现继承自 TtsEngineSsml,并使用 TextFragmentSpeechEventInfoFragmentStateTtsEventIdThe 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 实例的数组,并创建要在基础合成引擎上传递到 Speak 方法的 TextFragment 实例的新数组。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. 如果从每个 TextFragment 实例的 State 属性返回的 FragmentState 上的 Action 属性中找到 TtsEngineAction 枚举值 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

    • 将 Americanism 转换为要口述的文本中的 Britishisms。Translates Americanism to Britishisms in the text to be spoken.

    • 如果为实现提供的 ITtsEngineSite 接口上的 EventInterest 属性支持 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.

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

注解

自定义语音合成引擎通过向传递到 SpeakAddLexiconRemoveLexicon的实现的 ITtsEngineSite 引擎站点对象 AddEvents 成员提供相应的 SpeechEventInfo 实例,请求在语音平台下生成事件。A custom speech synthesis engine requests the generation of events under the Speech Platform by providing an appropriate SpeechEventInfo instance to AddEvents member of the ITtsEngineSite engine site object passed to implementations of Speak, AddLexicon, and RemoveLexicon.

构造函数

SpeechEventInfo(Int16, Int16, Int32, IntPtr)

构造相应的 SpeechEventInfoConstructs an appropriate SpeechEventInfo.

属性

EventId

获取和设置 SpeechEventInfo 实例用于请求的语音平台事件。Gets and set the Speech platform event which an instance of SpeechEventInfo is used to request.

Param1

获取和设置 integer 值(构造函数中的 param1),此值需要传递至语音平台以生成 SpeechEventInfo 的当前实例用于请求的事件。Gets and set the integer value (param1 in the constructor) to be passed to the Speech platform to generate an event the current instance of SpeechEventInfo is used to request.

Param2

获取和设置 System.IntPtr 实例(构造函数中的 param2),此实例引用需要传递至语音平台以生成 SpeechEventInfo 的当前实例用于请求的事件。Gets and set the System.IntPtr instance (param2 in the constructor) referencing the object to be passed to the Speech platform to generate an event the current instance of SpeechEventInfo is used to request.

ParameterType

返回当前 IntPtr 对象上的 Param2 参数返回的 SpeechEventInfo 所指向的对象的数据类型。Returns the data type of the object pointed to by the IntPtr returned by the Param2 parameter on the current SpeechEventInfo object.

方法

Equals(Object)

确定指定的对象是否为 SpeechEventInfo 的实例,并与当前 SpeechEventInfo 实例是否相等。Determines whether a specified object is an instance of SpeechEventInfo and equal to the current instance of SpeechEventInfo.

Equals(SpeechEventInfo)

确定指定的 SpeechEventInfo 对象与 SpeechEventInfo 的当前实例是否相等。Determines whether a specified SpeechEventInfo object is equal to the current instance of SpeechEventInfo.

GetHashCode()

提供 SpeechEventInfo 对象的哈希代码。Provides a hash code for a SpeechEventInfo object.

运算符

Equality(SpeechEventInfo, SpeechEventInfo)

确定两个 SpeechEventInfo 实例是否相等。Determines whether two instances of SpeechEventInfo are equal.

Inequality(SpeechEventInfo, SpeechEventInfo)

确定两个 SpeechEventInfo 实例是否不相等。Determines whether two instances of SpeechEventInfo are not equal.

适用于