SpeechSynthesizer.SetOutputToWaveFile メソッド

定義

SpeechSynthesizer オブジェクトを、WAVE 形式のオーディオ形式ファイルに出力を追加するように構成します。

オーバーロード

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

SpeechSynthesizer のオブジェクトを、指定された形式で WAVE 形式のオーディオ形式ファイルに出力を追加するように構成します。

SetOutputToWaveFile(String)

SpeechSynthesizer オブジェクトを、WAVE 形式のオーディオを含むファイルに出力を追加するように構成します。

注釈

ファイルへの 参照をSpeechSynthesizer解放するには、 を呼び出SetOutputToNullして、 の出力を再構成SpeechSynthesizerします。

その他の出力構成オプションについては、、および の各メソッドを参照してくださいSetOutputToAudioStreamSetOutputToNullSetOutputToDefaultAudioDeviceSetOutputToWaveStream

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

ソース:
SpeechSynthesizer.cs
ソース:
SpeechSynthesizer.cs
ソース:
SpeechSynthesizer.cs

SpeechSynthesizer のオブジェクトを、指定された形式で WAVE 形式のオーディオ形式ファイルに出力を追加するように構成します。

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)

パラメーター

path
String

ファイルへのパス。

formatInfo
SpeechAudioFormatInfo

オーディオ形式の情報。

次の例では、音声合成の出力の形式を指定し、WAV ファイルに送信します。

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

こちらもご覧ください

適用対象

SetOutputToWaveFile(String)

ソース:
SpeechSynthesizer.cs
ソース:
SpeechSynthesizer.cs
ソース:
SpeechSynthesizer.cs

SpeechSynthesizer オブジェクトを、WAVE 形式のオーディオを含むファイルに出力を追加するように構成します。

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

パラメーター

path
String

ファイルへのパス。

次の例では、 の SoundPlayer インスタンスを使用して、.wav ファイルに出力されたプロンプトを再生します。 呼び出し SpeakAsync は非同期であるため、 イベントの SoundPlayer ハンドラーにインスタンス (および Play 呼び出されたメソッド) が SpeakCompleted 作成されます。

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

注釈

出力を構成し、オーディオ形式を指定するには、 メソッドを使用します SetOutputToWaveFile

こちらもご覧ください

適用対象