EventParameterType 枚举

定义

枚举传递到语音合成事件的数据指针的类型。Enumerates the types of data pointers passed to speech synthesis events.

public enum class EventParameterType
public enum EventParameterType
type EventParameterType = 
Public Enum EventParameterType
继承
EventParameterType

字段

Object 2

当前不支持。Currently not supported.

Pointer 3

当前不支持。Currently not supported.

String 4

指示传到 SpeechEventInfoparam2 参数是使用引用 System.IntPtr 的对象的 System.Runtime.InteropServices.Marshal.StringToCoTaskMemUni 创建的 System.Stringparam1 可以具有任何值。Indicates that the param2 argument to the SpeechEventInfo is a System.IntPtr created using System.Runtime.InteropServices.Marshal.StringToCoTaskMemUni referencing a System.String object; param1 may take on any value.

Token 1

指示 SpeechEventInfoparam2 参数是使用 PtrToStructure 创建的 IntPtr,它引用 Windows 桌面语音技术令牌,该令牌是一个表示资源的 Windows 桌面语音技术对象,如语音 (VoiceInfo)。Indicates that the param2 argument to the SpeechEventInfo is an IntPtr created using PtrToStructure that references a Windows Desktop Speech Technology token, which is a Windows Desktop Speech Technology object representing a resource, such as a voice (VoiceInfo). param1 可能具有任何价值。param1 may take on any value.

Undefined 0

指示传到 SpeechEventInfo 的参数 param2 未定义。Indicates that the param2 argument to the SpeechEventInfo is undefined. 通常,忽略 param1param2Generally, param1 and param2 are then ignored. 但是,如果 EventIdWordBoundary,则可以生成进度条事件。However, if EventId is WordBoundary, a progress meter event can be generated. param1 应为包含当前单词长度的整数,param2 为引用包含当前单词偏移量的整数的 IntPtrparam1 should be an integer containing the length of the current word, and param2 an IntPtr referencing an integer containing the offset of the current word.

示例

下面的示例TtsEngineSsml是继承自的自定义语音合成实现的一部分, 并使用TextFragmentSpeechEventInfoFragmentStateTtsEventIdThe following example 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. Action FragmentState State 如果在Speak每个TtsEngineAction 实例的属性返回的的属性中找到枚举TextFragment值, 则实现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

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

注解

构造对象时使用EventParameterType枚举 SpeechEventInfoThe EventParameterType enumeration is used when constructing a SpeechEventInfo object. IntPtr作为参数传递param2给构造函数的SpeechEventInfo 枚举成员,用于指定如何解释构造函数的参数(必须为)。EventParameterType parameterTypeAn EventParameterType enumeration member passed as the parameterType argument to the constructor for SpeechEventInfo specifies how the param2 argument of the constructor (which must be an IntPtr) is interpreted.

的选择EventParameterType取决于所请求的事件类型, 由的System.Speech.Synthesis.TtsEngine.TtsEventId成员指定。The choice of EventParameterType is dictated by the type of event being requested, as specified by a member of System.Speech.Synthesis.TtsEngine.TtsEventId.

有关如何使用EventParameterType的详细信息, 请参阅文档EventIdFor detailed information on how use EventParameterType, see the documentation for EventId

备注

目前, 使用System.Speech.Synthesis命名空间的成员编写的托管合成语音引擎的实例不能在构造后更改资源。Currently, instances of a managed synthetic speech engines written using the members of the System.Speech.Synthesis namespace cannot change resources after construction.

适用于

另请参阅