共用方式為


Note

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

SpeechSynthesizer.SetOutputToWaveFile Method (String)

Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio.

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

Syntax

'Declaration
Public Sub SetOutputToWaveFile ( _
    path As String _
)
'Usage
Dim instance As SpeechSynthesizer
Dim path As String

instance.SetOutputToWaveFile(path)
public void SetOutputToWaveFile(
    string path
)

Parameters

Remarks

To configure the output and specify the audio format, use the SetOutputToWaveFile(String, SpeechAudioFormatInfo) method.

Examples

The following example uses an instance of SoundPlayer to play a prompt that has been output to a .wav file.

using System;
using System.IO;
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:\temp\test.wav");

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

        // Build a prompt.
        PromptBuilder builder = new PromptBuilder();
        builder.AppendText("This is sample output to a WAVE file.");

        // Speak the prompt and play the output file.
        synth.Speak(builder);
        m_SoundPlayer.Play();
      }

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

See Also

Reference

SpeechSynthesizer Class

SpeechSynthesizer Members

SetOutputToWaveFile Overload

Microsoft.Speech.Synthesis Namespace