TextFragment TextFragment TextFragment TextFragment Class

定義

包含語音合成器引擎所使用的文字和語音屬性資訊。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
繼承
TextFragmentTextFragmentTextFragmentTextFragment

範例

以下範例是自訂語音合成實TtsEngineSsml作為繼承自的一部分, 並使用TextFragmentSpeechEventInfo FragmentState、和TtsEventIdThe 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陣列, 並建立要傳遞至基礎TextFragment合成引擎上方法的Speak新實例陣列。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.

    TextOffset在新TextFragment TextLength的實例上TextToSpeak建立時, 會特別小心用來尊重原始的。 TextFragmentParticular care is used to respect the TextOffset, TextLength on the original TextFragment when creating the TextToSpeak on the new TextFragment instances.

  2. Action FragmentState Speak如果在每個State實例的屬性所傳回之的屬性中找到的列舉值為,則會執行TtsEngineAction TextFragmentIf 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.

    • 如果提供EventInterest ITtsEngineSite 給實SpeechEventInfo作為之介面上的屬性支援事件種類,則會使用實例來建立事件,以驅動合成器進度計量器的建立。WordBoundaryIf 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);  

}  

備註

語音平臺基礎結構會解壓縮 SSML 輸入的 XML 架構結構, 並TextFragment建立物件。The Speech platform infrastructure unpacks the XML based structure of the SSML input and constructs TextFragment objects.

語音內容TextLength可透過TextFragment實例的、 TextOffsetTextToSpeak屬性取得。Speech content is available through the TextLength, TextOffset, and TextToSpeak properties of a TextFragment instance.

語音屬性資訊 (例如強調、音調和速率) 是從FragmentState State屬性傳回TextFragment的物件取得。Speech attribute information, such as emphasis, pitch, and rate, are obtained from the FragmentState object returned by the TextFragmentState property.

建構函式

TextFragment() TextFragment() TextFragment() TextFragment()

建構 TextFragment 的新執行個體。Constructs a new instance of TextFragment.

屬性

State State State State

取得或設定 TextFragment 的語音屬性資訊。Gets or sets speech attribute information for a TextFragment.

TextLength TextLength TextLength TextLength

取得或設定片段中語音文字的長度。Gets or sets the length of the speech text in the fragment.

TextOffset TextOffset TextOffset TextOffset

取得或設定片段中文字起始的位置。Gets or sets the starting location of the text in the fragment.

TextToSpeak TextToSpeak TextToSpeak TextToSpeak

設定或取得片段的語音文字。Sets or gets the speech text of the fragment.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於