TextFragment Class

Definition

包含供语音合成引擎使用的文本和语音特性信息。Contains text and speech attribute information for consumption by a speech synthesizer engine.

public ref class TextFragment
public class TextFragment
type TextFragment = class
Public Class TextFragment
Inheritance
TextFragment

Examples

下面的示例是自定义语音合成实现的一部分,该实现继承自 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.

    在新的 TextFragment 实例上创建 TextToSpeak 时,需要特别注意的是,在原始 TextFragmentTextLength TextOffsetParticular care is used to respect the TextOffset, TextLength on the original TextFragment when creating the TextToSpeak on the new TextFragment instances.

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

Remarks

语音平台基础结构解压缩了 SSML 输入的基于 XML 的结构,并构造 TextFragment 的对象。The Speech platform infrastructure unpacks the XML based structure of the SSML input and constructs TextFragment objects.

语音内容可通过 TextFragment 实例的 TextLengthTextOffsetTextToSpeak 属性获得。Speech content is available through the TextLength, TextOffset, and TextToSpeak properties of a TextFragment instance.

语音特性信息(如强调、螺距和速率)是从 TextFragmentState 属性返回的 FragmentState 对象获取的。Speech attribute information, such as emphasis, pitch, and rate, are obtained from the FragmentState object returned by the TextFragmentState property.

Constructors

TextFragment()

构造 TextFragment 的新实例。Constructs a new instance of TextFragment.

Properties

State

获取或设置 TextFragment 的语音特性信息。Gets or sets speech attribute information for a TextFragment.

TextLength

设置或获取片段中的语音文本的长度。Gets or sets the length of the speech text in the fragment.

TextOffset

设置或获取片段中的文本的起始位置。Gets or sets the starting location of the text in the fragment.

TextToSpeak

获取或设置片段的语音文本。Gets or sets the speech text of the fragment.

Methods

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Applies to