SpeechSynthesizer.Speak Metodo

Definizione

Genera l'output vocale in modo sincrono da una stringa, un oggetto Prompt o un oggetto PromptBuilder.

Overload

Speak(Prompt)

In modo sincrono sul contenuto di un oggetto di Prompt.

Speak(PromptBuilder)

In modo sincrono sul contenuto di un oggetto di PromptBuilder.

Speak(String)

In modo sincrono legge il contenuto di una stringa.

Commenti

I Speak metodi generano la voce in modo sincrono. I metodi non restituiscono finché il contenuto dell'istanza Speak non è stato completamente parlato. Questo è il modo più semplice per generare la voce. Tuttavia, se l'applicazione deve eseguire attività durante la conversazione, ad esempio evidenziare testo, disegnare animazioni, monitorare controlli o altre attività, usare i metodi o il SpeakAsyncSpeakSsmlAsync metodo per generare la voce in modo asincrono.

Durante una chiamata a questo metodo, è SpeechSynthesizer possibile generare gli eventi seguenti:

  • StateChanged. Generato quando lo stato di parlato del sintetizzatore cambia.

  • SpeakStarted. Generato quando il sintetizzatore inizia a generare la voce.

  • PhonemeReached. Generato ogni volta che il sintetizzatore raggiunge una lettera o una combinazione di lettere che costituiscono un suono discreto di voce in una lingua.

  • SpeakProgress. Generato ogni volta che il sintetizzatore completa la parola.

  • VisemeReached. Ogni volta che l'output parlato richiede un cambiamento nella posizione della bocca o dei muscoli facciali usati per produrre voce.

  • BookmarkReached. Generato quando il sintetizzatore rileva un segnalibro in una richiesta.

  • VoiceChange. Generato quando la voce parlante per il sintetizzatore cambia.

L'oggetto SpeechSynthesizer non genera l'evento durante l'elaborazione SpeakCompleted di uno dei Speak metodi.

Speak(Prompt)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

In modo sincrono sul contenuto di un oggetto di Prompt.

public:
 void Speak(System::Speech::Synthesis::Prompt ^ prompt);
public void Speak (System.Speech.Synthesis.Prompt prompt);
member this.Speak : System.Speech.Synthesis.Prompt -> unit
Public Sub Speak (prompt As Prompt)

Parametri

prompt
Prompt

Il contenuto da leggere a voce.

Esempio

Nell'esempio seguente viene creato un Prompt oggetto da una stringa e viene passato l'oggetto come argomento al Speak metodo .

using System;
using System.Speech.Synthesis;

namespace SampleSynthesis
{
  class Program
  {
    static void Main(string[] args)
    {

      // Initialize a new instance of the SpeechSynthesizer.
      using (SpeechSynthesizer synth = new SpeechSynthesizer())
      {

        // Configure the audio output.
        synth.SetOutputToDefaultAudioDevice();

        // Create a prompt from a string.
        Prompt color = new Prompt("What is your favorite color?");

        // Speak the contents of the prompt synchronously.
        synth.Speak(color);
      }

      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

Commenti

Per parlare in modo asincrono il contenuto di un Prompt oggetto, usare SpeakAsync.

Si applica a

Speak(PromptBuilder)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

In modo sincrono sul contenuto di un oggetto di PromptBuilder.

public:
 void Speak(System::Speech::Synthesis::PromptBuilder ^ promptBuilder);
public void Speak (System.Speech.Synthesis.PromptBuilder promptBuilder);
member this.Speak : System.Speech.Synthesis.PromptBuilder -> unit
Public Sub Speak (promptBuilder As PromptBuilder)

Parametri

promptBuilder
PromptBuilder

Il contenuto da leggere a voce.

Esempio

Nell'esempio seguente viene creato un PromptBuilder oggetto da una stringa e viene passato l'oggetto come argomento al Speak metodo .

using System;
using System.Speech.Synthesis;

namespace SampleSynthesis
{
  class Program
  {
    static void Main(string[] args)
    {

      // Initialize a new instance of the SpeechSynthesizer.
      using (SpeechSynthesizer synth = new SpeechSynthesizer())
      {

        // Configure the audio output.
        synth.SetOutputToDefaultAudioDevice();

        // Create a PromptBuilder object and append a text string.
        PromptBuilder song = new PromptBuilder();
        song.AppendText("Say the name of the song you want to hear");

        // Speak the contents of the prompt synchronously.
        synth.Speak(song);
      }

      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

Commenti

Per parlare in modo asincrono il contenuto di un PromptBuilder oggetto, usare SpeakAsync.

Si applica a

Speak(String)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

In modo sincrono legge il contenuto di una stringa.

public:
 void Speak(System::String ^ textToSpeak);
public void Speak (string textToSpeak);
member this.Speak : string -> unit
Public Sub Speak (textToSpeak As String)

Parametri

textToSpeak
String

Testo da leggere a voce.

Esempio

Come illustrato nell'esempio seguente, il Speak metodo fornisce i mezzi più semplici per generare l'output vocale in modo sincrono.

using System;
using System.Speech.Synthesis;

namespace SampleSynthesis
{
  class Program
  {
    static void Main(string[] args)
    {

      // Initialize a new instance of the SpeechSynthesizer.
      using (SpeechSynthesizer synth = new SpeechSynthesizer())
      {

        // Configure the audio output.
        synth.SetOutputToDefaultAudioDevice();

        // Speak a string synchronously.
        synth.Speak("What is your favorite color?");
      }

      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

Commenti

Per parlare in modo sincrono una stringa contenente il markup SSML, usare il SpeakSsml metodo . Per parlare in modo asincrono il contenuto di una stringa, usare il SpeakAsync metodo .

Si applica a