PromptBuilder.AppendText Method (String, PromptVolume)

 
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.

Appends text to the PromptBuilder object and specifies the volume to speak the text.

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

public void AppendText(
	string textToSpeak,
	PromptVolume volume
)

Parameters

textToSpeak
Type: System.String

A string containing the text to be spoken.

volume
Type: System.Speech.Synthesis.PromptVolume

The value for the speaking volume (loudness) to apply to the text.

The Default setting for PromptVolume is full volume, which is the same as ExtraLoud. The other settings decrease the volume of speech output relative to full volume.

The following example uses the AppendText method to specify volume settings that the SpeechSynthesizer should apply to speech output.

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

        // Build a prompt that applies different volume settings.
        PromptBuilder builder = new PromptBuilder();
        builder.AppendText("This is the default speaking volume.", PromptVolume.Default);
        builder.AppendBreak();
        builder.AppendText("This is the extra loud speaking volume.", PromptVolume.ExtraLoud);
        builder.AppendBreak();
        builder.AppendText("This is the medium speaking volume.", PromptVolume.Medium);

        // 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: