TtsEventId 枚举

定义

枚举语音合成事件的类型。Enumerates types of speech synthesis events.

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

字段

AudioLevel 9

当语音合成引擎在讲话过程中完成一个音频级别的更改时,标识生成的事件。Identifies events generated when a speech synthesize engine completes an audio level change while speaking.

Bookmark 4

当语音合成引擎在讲话过程中遇到一个书签时,标识生成的事件。Identifies events generated when a speech synthesize engine encounters a bookmark while speaking.

EndInputStream 2

当语音合成引擎在讲话过程中遇到它的输入流的末尾时,标识生成的事件。Identifies events generated when a speech synthesize engine encounters the end of its input stream while speaking.

Phoneme 6

当语音合成引擎在讲话过程中完成一个音素时,标识生成的事件。Identifies events generated when a speech synthesize engine completes a phoneme while speaking.

SentenceBoundary 7

当语音合成引擎在讲话过程中完成一个句子时,标识生成的事件。Identifies events generated when a speech synthesize engine completes a sentence while speaking.

StartInputStream 1

当语音合成引擎开始讲话时,标识生成的事件。Identifies events generated when a speech synthesize engine a begins speaking a stream.

Viseme 8

当语音合成引擎在讲话过程中完成一个 viseme 时,标识生成的事件。Identifies events generated when a speech synthesize engine completes a viseme while speaking.

VoiceChange 3

当语音合成引擎在讲话过程中遇到一个语音更改时,标识生成的事件。Identifies events generated when a speech synthesize engine encounters a change of Voice while speaking.

WordBoundary 5

当语音合成引擎在讲话过程中完成一个词语时,标识生成的事件。Identifies events generated when a speech synthesize engine completes a word while speaking.

示例

下面TtsEngineSsml的示例是继承自的自定义语音合成实现的一部分, 并TextFragment使用、 SpeechEventInfoFragmentStateTtsEventId类。The following example is part of a custom speech synthesis implementation inheriting from TtsEngineSsml, and using the TextFragment, SpeechEventInfo, FragmentState, and TtsEventId classes.

的实现TtsEngineSsml.Speak包括以下步骤:The implementation of TtsEngineSsml.Speak includes the following steps:

  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. 如果每ActionTextFragment.State实例的属性等于TtsEngineAction.Speak, 则代码会执行以下操作:If the Action property of each TextFragment.State instance is equal to TtsEngineAction.Speak, the code does the following:

    • 将美国英语翻译为要朗读的文本。Translates American English to British English in the text to be spoken.

    • 如果为实现提供的WordBoundary SpeechEventInfo属性支持事件类型, 则将使用实例创建事件来驱动合成器的进度计量。 ITtsEngineSite.EventInterestIf the ITtsEngineSite.EventInterest property provided to the implementation supports 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);

}

注解

自定义语音合成引擎用TtsEventId来定义提交到语音平台合成器基础结构的事件类型。Custom speech synthesis engines define the types of events submitted to the Speech platform synthesizer infrastructure with the TtsEventId.

通过EventId设置传递到类的AddEvents成员的SpeechEventInfo实例的属性来执行规范, Speak此类成员ITtsEngineSite实现了在自定义语音引擎的的TtsEngineSsml实现。Specification is performed by setting the EventId property of SpeechEventInfo instances passed to the AddEvents member of the class implementing the ITtsEngineSite interface passed to the Speak method on a custom speech engine's implementation of TtsEngineSsml.

语音平台基础结构通过EventInterest传递到说话实现的ITtsEngineSite中的属性指示当前正在处理的事件类型。The Speech platform infrastructure indicates the type of events it is currently handling through the EventInterest property on the ITtsEngineSite passed to the speak implementation.

的值EventInterest是一个位掩码, 其中的TtsEventId成员定义与事件类型相对应的位的位置。The value of EventInterest is a bitmask, where the members of TtsEventId define the location of the bit corresponding to the event type. 例如, WordBoundary 的值为 5 (5), 表示由EventInterest返回的值中的第五位指示站点是否支持事件类型。For example, WordBoundary has a value of five (5), meaning the fifth bit in the value returned by EventInterest indicates if the site supports the event type.

适用于