TextFragment.TextToSpeak 属性

定义

获取或设置片段的语音文本。

public:
 property System::String ^ TextToSpeak { System::String ^ get(); void set(System::String ^ value); };
public string TextToSpeak { get; set; }
member this.TextToSpeak : string with get, set
Public Property TextToSpeak As String

属性值

返回或使用 System.String 来设置语音合成引擎用来生成音频输出的语音文本。

示例

以下示例是继承自 TtsEngineSsml的自定义语音合成实现的一部分,并使用 TextFragmentSpeechEventInfoFragmentStateTtsEventId

的实现 Speak

  1. 接收实例数组TextFragment,并创建要传递到Speak基础合成引擎上的 方法的新实例数组TextFragment

    在新TextFragment实例上创建 TextToSpeak 时,特别要注意TextOffsetTextLength尊重原始 TextFragment 上的 。

  2. 如果从 Action 每个TextFragment实例SpeakTtsEngineAction 属性返回State的 上的 FragmentState 属性中找到 的枚举值为 ,则实现

  3. 然后,使用修改后的 TextFragment 数组调用语音呈现引擎。

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

}  

注解

此属性的默认值为 System.String.Empty

应用程序可以完全更改 的值 TextToSpeak

重置 的值TextToSpeak不会更改 和 TextLength的值TextOffset

适用于