共用方式為


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

SpeechSynthesizer.Speak Method (String)

Synchronously speaks the contents of a string.

Namespace:  Microsoft.Speech.Synthesis
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)

Syntax

'Declaration
Public Sub Speak ( _
    textToSpeak As String _
)
'Usage
Dim instance As SpeechSynthesizer
Dim textToSpeak As String

instance.Speak(textToSpeak)
public void Speak(
    string textToSpeak
)

Parameters

Remarks

To synchronously speak a string that contains SSML markup, use the SpeakSsml(String) method. To asynchronously speak the contents of a string, use the SpeakAsync(String) method.

Examples

As shown in the following example, the Speak(String) method provides the simplest means to generate speech output synchronously.

using System;
using Microsoft.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.SetOutputToWaveFile(@"C:\Test\Color.wav");

        // Create a SoundPlayer instance to play the output audio file.
        System.Media.SoundPlayer m_SoundPlayer =
          new System.Media.SoundPlayer(@"C:\Test\Color.wav");

        // Speak the string synchronously and play the output file.
        synth.Speak("What is your favorite color?");
        m_SoundPlayer.Play();
      }

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

See Also

Reference

SpeechSynthesizer Class

SpeechSynthesizer Members

Speak Overload

Microsoft.Speech.Synthesis Namespace