TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) TtsEngineSsml.Speak(TextFragment[], IntPtr, ITtsEngineSite) Method

Definição

Renderiza a matriz TextFragment especificada no formato de saída especificado.Renders specified TextFragment array in the specified output format.

public:
 abstract void Speak(cli::array <System::Speech::Synthesis::TtsEngine::TextFragment ^> ^ fragment, IntPtr waveHeader, System::Speech::Synthesis::TtsEngine::ITtsEngineSite ^ site);
public abstract void Speak (System.Speech.Synthesis.TtsEngine.TextFragment[] fragment, IntPtr waveHeader, System.Speech.Synthesis.TtsEngine.ITtsEngineSite site);
abstract member Speak : System.Speech.Synthesis.TtsEngine.TextFragment[] * nativeint * System.Speech.Synthesis.TtsEngine.ITtsEngineSite -> unit
Public MustOverride Sub Speak (fragment As TextFragment(), waveHeader As IntPtr, site As ITtsEngineSite)

Parâmetros

fragment
TextFragment[]

Uma matriz de instâncias TextFragment contendo o texto a ser renderizado em fala.An array of TextFragment instances containing the text to be rendered into speech.

waveHeader
IntPtr IntPtr IntPtr IntPtr

Um IntPtr apontando para uma estrutura que contém o formato de saída de áudio.An IntPtr pointing to a structure containing audio output format.

site
ITtsEngineSite ITtsEngineSite ITtsEngineSite ITtsEngineSite

Uma referência a uma interface ITtsEngineSite passada pela infraestrutura de plataforma para permitir o acesso aos recursos de infraestrutura.A reference to an ITtsEngineSite interface passed in by the platform infrastructure to allow access to the infrastructure resources.

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,, eTtsEventIdThe 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.

  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 estrutura usada como waveHeader e retornada pelo método deve ser compatível com o WAVEFORMATEX disponível em SAPI.The structure used as waveHeader and returned by the method should compatible with the WAVEFORMATEX available under SAPI.

O struct deve fornecer a funcionalidade equivalente a:The struct must provide functionality equivalent to:

internal struct WaveFormat  
{  
    public Int16 FormatTag;  
    public Int16 Channels;  
    public int SamplesPerSec;  
    public int AvgBytesPerSec;  
    public Int16 BlockAlign;  
    public Int16 BitsPerSample;  
    public Int16 Size;  
}  

Notas aos Herdeiros

O sintetizador de fala personalizado TtsEngineSsml implementa Speak(TextFragment[], IntPtr, ITtsEngineSite) usando e trabalha como filtros ou intermediários entre os aplicativos do sintetizador construídos usando a infraestrutura da plataforma System.Speech.Synthesis por meio dos membros do namespace e do mecanismos subjacentes de síntese de fala do sistema.Custom speech synthesizer implements using TtsEngineSsml and Speak(TextFragment[], IntPtr, ITtsEngineSite) work as filters or intermediaries between synthesizer applications constructed using the platform infrastructure through the members of the System.Speech.Synthesis namespace and underlying system speech synthesis engines.

Uma Speak(TextFragment[], IntPtr, ITtsEngineSite) implementação:A Speak(TextFragment[], IntPtr, ITtsEngineSite) implementation: 1.1. Intercepta ou modifica aspectos dos objetos de TextFragment entradaTraps or modify aspects of the incoming TextFragment objects 2.2. Gera todos os eventos necessários usando a referência de site ITtsEngineSite para uma instânciaGenerates any necessary events using the site reference to a ITtsEngineSite instance 3.3. Gera a fala sintetizada real.Generates the actual synthesized speech.

A geração de fala geralmente é feita com a chamada de palestra em um dos mecanismos de renderização de fala fornecidos pelo sistema operacional.Generation of speech is most typically done by calling Speak on one of the speech rendering engines provided by the operating system.

Se um dos mecanismos de renderização de fala disponíveis não for usado, um objeto herdado TtsEngineSsml de deve criar seu próprio mecanismo de renderização de fala.If one of the available speech rendering engines is not used, a object inheriting from TtsEngineSsml must create its own speech rendering engine.

Acesso ao método Speak no obtido usando o registro e a reflexão.Access to the Speak method on obtained using the registry and reflection. ..

Ao herdar do TtsEngineSsml, você deve substituir os seguintes membros: TtsEngineSsml(String), AddLexicon(Uri, String, ITtsEngineSite) RemoveLexicon(Uri, ITtsEngineSite) GetOutputFormat(SpeakOutputFormat, IntPtr),, e Speak(TextFragment[], IntPtr, ITtsEngineSite).When you inherit from TtsEngineSsml, you must override the following members: TtsEngineSsml(String), AddLexicon(Uri, String, ITtsEngineSite), RemoveLexicon(Uri, ITtsEngineSite), GetOutputFormat(SpeakOutputFormat, IntPtr), and Speak(TextFragment[], IntPtr, ITtsEngineSite).

Aplica-se a