SpeechSynthesizer.Volume Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Get or sets the output volume of the SpeechSynthesizer object.

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

public int Volume { get; set; }

Property Value

Type: System.Int32

Returns the volume of the SpeechSynthesizer, from 0 through 100.

The following example sets the volume of the SpeechSynthesizer's audio output for the synthesized voice and the WAV file.

using System;
using System.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.SetOutputToDefaultAudioDevice();

        // Set the volume of the SpeechSynthesizer's ouput.
        synth.Volume = 60;

        // Build a prompt containing recorded audio and synthesized speech.
        PromptBuilder builder = new PromptBuilder(
          new System.Globalization.CultureInfo("en-US"));
        builder.AppendAudio("C:\\Test\\WelcomeToContosoRadio.wav");
        builder.AppendText(
          "The weather forecast for today is partly cloudy with some sun breaks.");

        // Speak the prompt.
        synth.Speak(builder);
      }

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

.NET Framework
Available since 3.0
Return to top
Show: