TextFragment TextFragment TextFragment TextFragment Class

Definição

Contém informações de atributo de texto e fala para consumo de um mecanismo de sintetizador de voz.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
Herança
TextFragmentTextFragmentTextFragmentTextFragment

Exemplos

O exemplo a seguir faz parte de uma implementação de síntese de fala personalizada TtsEngineSsmlque herda de e usando o TextFragmentuso SpeechEventInfode FragmentState,, TtsEventIde.The example below is part of a custom speech synthesis implementation inheriting from TtsEngineSsml, and using the use of TextFragment, SpeechEventInfo, FragmentState, and TtsEventId.

A implementação deSpeakThe implementation of Speak

  1. Recebe uma matriz de TextFragment instâncias e cria uma nova matriz de TextFragment instâncias a ser passada para o Speak método em um mecanismo de síntese subjacente.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.

    O cuidado específico é usado para respeitar TextOffseto TextLength , no original TextFragment , ao criar TextToSpeak o nas novas TextFragment instâncias.Particular care is used to respect the TextOffset, TextLength on the original TextFragment when creating the TextToSpeak on the new TextFragment instances.

  2. Se o TtsEngineAction valor de enumeração encontrado Action na propriedade State no FragmentState retornado pela propriedade de cada TextFragment instância for Speak, a implementaçãoIf 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

    • Traduz o American Britishisms no texto a ser falado.Translates Americanism to Britishisms in the text to be spoken.

    • Se a EventInterest ITtsEngineSite Propriedade nas interfaces fornecidas para a implementação oferecer suporte ao WordBoundary tipo de evento, SpeechEventInfo uma instância será usada para criar um evento para gerar um medidor de progresso do sintetizador criado.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. Um mecanismo de renderização de fala é chamado com a TextFragment matriz modificada.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);  

}  

Comentários

A infraestrutura da plataforma de fala desempacota a estrutura baseada em XML da entrada SSML e constrói TextFragment objetos.The Speech platform infrastructure unpacks the XML based structure of the SSML input and constructs TextFragment objects.

O TextLengthconteúdo de fala está disponível por TextOffsetmeio das TextToSpeak Propriedades, e TextFragment de uma instância do.Speech content is available through the TextLength, TextOffset, and TextToSpeak properties of a TextFragment instance.

As informações de atributo de fala, como ênfase, densidade e taxa, são obtidas FragmentState do objeto retornado TextFragment State pela propriedade.Speech attribute information, such as emphasis, pitch, and rate, are obtained from the FragmentState object returned by the TextFragmentState property.

Construtores

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

Constrói uma nova instância de TextFragment.Constructs a new instance of TextFragment.

Propriedades

State State State State

Obtém ou define informações de atributo de fala de um TextFragment.Gets or sets speech attribute information for a TextFragment.

TextLength TextLength TextLength TextLength

Obtém ou define o comprimento do texto fala no fragmento.Gets or sets the length of the speech text in the fragment.

TextOffset TextOffset TextOffset TextOffset

Obtém ou define o local inicial do texto no fragmento.Gets or sets the starting location of the text in the fragment.

TextToSpeak TextToSpeak TextToSpeak TextToSpeak

Define ou obtém o texto em fala do fragmento.Sets or gets the speech text of the fragment.

Métodos

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

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

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

Serve como a função de hash padrão.Serves as the default hash function.

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

Obtém o Type da instância atual.Gets the Type of the current instance.

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

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

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

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Inherited from Object)

Aplica-se a