SpeechSynthesizer.SetOutputToWaveFile Methode

Definitie

Hiermee configureert u het SpeechSynthesizer object om uitvoer toe te voegen aan een Waveform-audiobestand.

Overloads

Name Description
SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Hiermee configureert u het SpeechSynthesizer object om uitvoer toe te voegen aan een Waveform-audiobestand in een opgegeven indeling.

SetOutputToWaveFile(String)

Hiermee configureert u het SpeechSynthesizer object om uitvoer toe te voegen aan een bestand met Waveform-indeling audio.

Opmerkingen

Als u de SpeechSynthesizerverwijzing naar het bestand wilt vrijgeven, configureert u de uitvoer van het bestand opnieuw door bijvoorbeeld aan SpeechSynthesizerte roepen SetOutputToNull.

Zie voor andere uitvoerconfiguratieopties de SetOutputToAudioStreammethoden , SetOutputToDefaultAudioDeviceen SetOutputToNullSetOutputToWaveStream de methoden.

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Bron:
SpeechSynthesizer.cs
Bron:
SpeechSynthesizer.cs
Bron:
SpeechSynthesizer.cs
Bron:
SpeechSynthesizer.cs

Hiermee configureert u het SpeechSynthesizer object om uitvoer toe te voegen aan een Waveform-audiobestand in een opgegeven indeling.

public:
 void SetOutputToWaveFile(System::String ^ path, System::Speech::AudioFormat::SpeechAudioFormatInfo ^ formatInfo);
public void SetOutputToWaveFile(string path, System.Speech.AudioFormat.SpeechAudioFormatInfo formatInfo);
member this.SetOutputToWaveFile : string * System.Speech.AudioFormat.SpeechAudioFormatInfo -> unit
Public Sub SetOutputToWaveFile (path As String, formatInfo As SpeechAudioFormatInfo)

Parameters

path
String

Het pad naar het bestand.

formatInfo
SpeechAudioFormatInfo

De informatie over de audio-indeling.

Voorbeelden

In het volgende voorbeeld wordt de indeling van de uitvoer van spraaksynthese opgegeven en verzonden naar een WAV-bestand.

using System;
using System.IO;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;

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",
          new SpeechAudioFormatInfo(32000, AudioBitsPerSample.Sixteen, AudioChannel.Mono));

        // Create a SoundPlayer instance to play 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.
        synth.Speak(builder);
        m_SoundPlayer.Play();
      }

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

Zie ook

Van toepassing op

SetOutputToWaveFile(String)

Bron:
SpeechSynthesizer.cs
Bron:
SpeechSynthesizer.cs
Bron:
SpeechSynthesizer.cs
Bron:
SpeechSynthesizer.cs

Hiermee configureert u het SpeechSynthesizer object om uitvoer toe te voegen aan een bestand met Waveform-indeling audio.

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

Parameters

path
String

Het pad naar het bestand.

Voorbeelden

In het volgende voorbeeld wordt een exemplaar gebruikt om SoundPlayer een prompt af te spelen die is uitgevoerd naar een .wav-bestand. Omdat de SpeakAsync aanroep asynchroon is, wordt het SoundPlayer exemplaar gemaakt (en de Play methode die wordt aangeroepen) in de handler voor de SpeakCompleted gebeurtenis.

using System;
using System.Speech.Synthesis;

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

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

      // Configure the audio output.
      synth.SetOutputToWaveFile(@"C:\Test\Sample.wav");

      // Register for the SpeakCompleted event.
      synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);

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

      // Speak the string asynchronously.
      synth.SpeakAsync(builder);

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

    // Handle the SpeakCompleted event.
    static void synth_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
    {

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

      //  Play the output file.
      m_SoundPlayer.Play();
    }
  }
}

Opmerkingen

Als u de uitvoer wilt configureren en de audio-indeling wilt opgeven, gebruikt u de SetOutputToWaveFile methode.

Zie ook

Van toepassing op