相关文章推荐
笑点低的毛豆  ·  Jira ...·  1 年前    · 
玩足球的杯子  ·  vba textbox 输入-掘金·  1 年前    · 
奋斗的烤土司  ·  c# - Server execution ...·  1 年前    · 

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge
public ref class SpeechSynthesizer sealed : IDisposable
public sealed class SpeechSynthesizer : IDisposable
type SpeechSynthesizer = class
    interface IDisposable
Public NotInheritable Class SpeechSynthesizer
Implements IDisposable
Inheritance
SpeechSynthesizer

Examples

The following example is part of a console application that initializes a SpeechSynthesizer object and speaks a string.

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.SetOutputToDefaultAudioDevice();
      // Speak a string.
      synth.Speak("This example demonstrates a basic use of Speech Synthesizer");
      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
	

Remarks

When you create a new SpeechSynthesizer object, it uses the default system voice. To configure the SpeechSynthesizer to use one of the installed speech synthesis (text-to-speech) voices, use the SelectVoice or SelectVoiceByHints method. To get information about which voices are installed, use the GetInstalledVoices method and the VoiceInfo class.

This class also provides control over the following aspects of speech synthesis:

  • To configure the output for the SpeechSynthesizer object, use the SetOutputToAudioStream, SetOutputToDefaultAudioDevice, SetOutputToNull, and SetOutputToWaveFile methods.

  • To generate speech, use the Speak, SpeakAsync, SpeakSsml, or SpeakSsmlAsync method. The SpeechSynthesizer can produce speech from text, a Prompt or PromptBuilder object, or from Speech Synthesis Markup Language (SSML) Version 1.0.

  • To pause and resume speech synthesis, use the Pause and Resume methods.

  • To add or remove lexicons, use the AddLexicon and RemoveLexicon methods. The SpeechSynthesizer can use one or more lexicons to guide its pronunciation of words.

  • To modify the delivery of speech output, use the Rate and Volume properties.

    The SpeechSynthesizer raises events when it encounters certain features in prompts: (BookmarkReached, PhonemeReached, VisemeReached, and SpeakProgress). It also raises events that report on the start (SpeakStarted) and end (SpeakCompleted) of speak operations and on the change of the speaking voice (VoiceChange).

    Always call Dispose before you release your last reference to the SpeechSynthesizer. Otherwise, the resources it is using will not be freed until the garbage collector calls the SpeechSynthesizer object's Finalize method.

  •