SpeechAudioFormatInfo Constructor (Int32, AudioBitsPerSample, AudioChannel)

 

Initializes a new instance of the SpeechAudioFormatInfo class and specifies the samples per second, bits per sample, and the number of channels.

Namespace:   System.Speech.AudioFormat
Assembly:  System.Speech (in System.Speech.dll)

public SpeechAudioFormatInfo(
	int samplesPerSecond,
	AudioBitsPerSample bitsPerSample,
	AudioChannel channel
)

Parameters

samplesPerSecond
Type: System.Int32

The value for the samples per second.

bitsPerSample
Type: System.Speech.AudioFormat.AudioBitsPerSample

The value for the bits per sample.

channel
Type: System.Speech.AudioFormat.AudioChannel

A member of the AudioChannel enumeration (indicating Mono or Stereo).

The following example shows a typical use of SpeechAudioFormatInfo to specify the format of audio to output to a WAV file. The SpeechAudioFormatInfo instance is an argument to the SetOutputToWaveFile method.

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

.NET Framework
Available since 3.0
Return to top
Show: