SpeechSynthesizer.Speak メソッド

定義

文字列、Prompt オブジェクト、または PromptBuilder オブジェクトから同期で出力される音声を生成します。

オーバーロード

Speak(Prompt)

非同期的に Prompt オブジェクトのコンテンツを指示します。

Speak(PromptBuilder)

非同期的に PromptBuilder オブジェクトのコンテンツを指示します。

Speak(String)

同期的に文字列のコンテンツを指示します。

注釈

メソッドは Speak 音声を同期的に生成します。 メソッドは、インスタンスの Speak 内容が完全に読み上げられるまで戻りません。 これは、音声を生成する最も簡単な方法です。 ただし、テキストの強調表示、アニメーションの描画、コントロールの監視、その他のタスクなど、読み上げ中にアプリケーションでタスクを実行する必要がある場合は、 メソッドまたは メソッドをSpeakSsmlAsync使用SpeakAsyncして非同期的に音声を生成します。

このメソッドの呼び出し中に、 は SpeechSynthesizer 次のイベントを発生させることができます。

  • StateChanged. シンセサイザーの読み上げ状態が変化したときに発生します。

  • SpeakStarted. シンセサイザーが音声の生成を開始したときに発生します。

  • PhonemeReached. シンセサイザーが文字または単語で目立たない音声を構成する文字の組み合わせに達するたびに発生します。

  • SpeakProgress. シンセサイザーが単語を話すたびに発生します。

  • VisemeReached. 音声出力を毎回発生させるには、音声の生成に使用される口または顔の筋肉の位置を変更する必要があります。

  • BookmarkReached. シンセサイザーがプロンプトでブックマークを検出したときに発生します。

  • VoiceChange. シンセサイザーの話し声が変わると発生します。

SpeechSynthesizer 、メソッドの処理中に SpeakCompleted イベントを Speak 発生させません。

Speak(Prompt)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

非同期的に 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)

パラメーター

prompt
Prompt

話すコンテンツ。

次の例では、 Prompt 文字列から オブジェクトを作成し、 オブジェクトを 引数として メソッドに Speak 渡します。

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

注釈

オブジェクトの内容を非同期的に読み上げるには Prompt 、 を使用 SpeakAsyncします。

適用対象

Speak(PromptBuilder)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

非同期的に 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)

パラメーター

promptBuilder
PromptBuilder

話すコンテンツ。

次の例では、 PromptBuilder 文字列から オブジェクトを作成し、 オブジェクトを 引数として メソッドに Speak 渡します。

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

注釈

オブジェクトの内容を非同期的に読み上げるには PromptBuilder 、 を使用 SpeakAsyncします。

適用対象

Speak(String)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

同期的に文字列のコンテンツを指示します。

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

パラメーター

textToSpeak
String

読み上げるテキスト。

次の例に示すように、 メソッドは Speak 音声出力を同期的に生成する最も簡単な手段を提供します。

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

注釈

SSML マークアップを含む文字列を同期的に読み上げるには、 メソッドを使用します SpeakSsml 。 文字列の内容を非同期的に読み上げるには、 メソッドを使用します SpeakAsync

適用対象