SpeechSynthesizer 类
定义
提供对已安装的语音合成引擎的功能的访问。Provides access to the functionality of an installed speech synthesis engine.
public ref class SpeechSynthesizer sealed : IDisposable
public sealed class SpeechSynthesizer : IDisposable
type SpeechSynthesizer = class
interface IDisposable
Public NotInheritable Class SpeechSynthesizer
Implements IDisposable
- 继承
-
SpeechSynthesizer
- 实现
示例
下面的示例是一个控制台应用程序的一部分,该应用程序初始化 SpeechSynthesizer 对象并讲述一个字符串。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();
}
}
}
注解
当你创建新的 SpeechSynthesizer 对象时,它将使用默认系统声音。When you create a new SpeechSynthesizer object, it uses the default system voice. 若要将配置 SpeechSynthesizer 为使用其中一个安装的语音合成 (文本到语音) 声音,请使用 SelectVoice 或 SelectVoiceByHints 方法。To configure the SpeechSynthesizer to use one of the installed speech synthesis (text-to-speech) voices, use the SelectVoice or SelectVoiceByHints method. 若要获取有关已安装的声音的信息,请使用 GetInstalledVoices 方法和 VoiceInfo 类。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:
若要为对象配置输出 SpeechSynthesizer ,请使用 SetOutputToAudioStream 、、 SetOutputToDefaultAudioDevice SetOutputToNull 和 SetOutputToWaveFile 方法。To configure the output for the SpeechSynthesizer object, use the SetOutputToAudioStream, SetOutputToDefaultAudioDevice, SetOutputToNull, and SetOutputToWaveFile methods.
若要生成语音,请使用 Speak 、 SpeakAsync 、 SpeakSsml 或 SpeakSsmlAsync 方法。To generate speech, use the Speak, SpeakAsync, SpeakSsml, or SpeakSsmlAsync method. SpeechSynthesizer可以从文本、 Prompt 或 PromptBuilder 对象或语音合成标记语言( (SSML) 版本 1.0)生成语音。The SpeechSynthesizer can produce speech from text, a Prompt or PromptBuilder object, or from Speech Synthesis Markup Language (SSML) Version 1.0.
若要暂停和继续语音合成,请使用 Pause 和 Resume 方法。To pause and resume speech synthesis, use the Pause and Resume methods.
若要添加或删除字典,请使用 AddLexicon 和 RemoveLexicon 方法。To add or remove lexicons, use the AddLexicon and RemoveLexicon methods. SpeechSynthesizer可以使用一个或多个词典来指导其单词的发音。The SpeechSynthesizer can use one or more lexicons to guide its pronunciation of words.
若要修改语音输出的传送,请使用 Rate 和 Volume 属性。To modify the delivery of speech output, use the Rate and Volume properties.
在出现 SpeechSynthesizer 提示时,引发事件时引发事件: (BookmarkReached 、 PhonemeReached 、 VisemeReached 和 SpeakProgress) 。The SpeechSynthesizer raises events when it encounters certain features in prompts: (BookmarkReached, PhonemeReached, VisemeReached, and SpeakProgress). 它还会引发报告开始 (的事件 SpeakStarted) 和结束 (SpeakCompleted 说话操作的) ,并在说话语音 (VoiceChange) 。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).
备注
每次释放对 Dispose 的最后一个引用前,均应调用 SpeechSynthesizer。Always call Dispose before you release your last reference to the SpeechSynthesizer. 否则,在垃圾回收器调用 SpeechSynthesizer 对象的 Finalize 方法之前,该对象正在使用的资源不会被释放。Otherwise, the resources it is using will not be freed until the garbage collector calls the SpeechSynthesizer object's Finalize method.
构造函数
| SpeechSynthesizer() |
初始化 SpeechSynthesizer 类的新实例。Initializes a new instance of the SpeechSynthesizer class. |
属性
| Rate |
获取或设置 SpeechSynthesizer 对象的语速。Gets or sets the speaking rate of the SpeechSynthesizer object. |
| State |
获取 SpeechSynthesizer 对象的当前语速。Gets the current speaking state of the SpeechSynthesizer object. |
| Voice |
获取有关当前 SpeechSynthesizer 对象的语音的信息。Gets information about the current voice of the SpeechSynthesizer object. |
| Volume |
获取或设置 SpeechSynthesizer 对象的输出量。Get or sets the output volume of the SpeechSynthesizer object. |
方法
| AddLexicon(Uri, String) |
将 SpeechSynthesizer 添加到该对象的词典中。Adds a lexicon to the SpeechSynthesizer object. |
| Dispose() |
处置 SpeechSynthesizer 对象并释放会话期间使用的资源。Disposes the SpeechSynthesizer object and releases resources used during the session. |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| Finalize() |
方法在未能调用 Dispose() 的情况下的事件中充当防护措施来清理资源。Acts as a safeguard to clean up resources in the event that the Dispose() method is not called. |
| GetCurrentlySpokenPrompt() |
获取 SpeechSynthesizer 正在讲话的提示。Gets the prompt that the SpeechSynthesizer is speaking. |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetInstalledVoices() |
返回所有安装的语音合成(文字到语音)语音。Returns all of the installed speech synthesis (text-to-speech) voices. |
| GetInstalledVoices(CultureInfo) |
返回支持特定区域设置的所有安装的语音合成(文字到语音)语音。Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale. |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| Pause() |
暂停 SpeechSynthesizer 对象。Pauses the SpeechSynthesizer object. |
| RemoveLexicon(Uri) |
从 SpeechSynthesizer 对象中移除词典。Removes a lexicon from the SpeechSynthesizer object. |
| Resume() |
继续 SpeechSynthesizer 对象(在它暂停后)。Resumes the SpeechSynthesizer object after it has been paused. |
| SelectVoice(String) |
通过名称选择特定语音。Selects a specific voice by name. |
| SelectVoiceByHints(VoiceGender) |
选择具有特定性别的语音。Selects a voice with a specific gender. |
| SelectVoiceByHints(VoiceGender, VoiceAge) |
选择具有特定性别和年龄的语音。Selects a voice with a specific gender and age. |
| SelectVoiceByHints(VoiceGender, VoiceAge, Int32) |
根据语音的排序位置选择具有特定性别和年龄的语音。Selects a voice with a specific gender and age, based on the position in which the voices are ordered. |
| SelectVoiceByHints(VoiceGender, VoiceAge, Int32, CultureInfo) |
根据语音的排序位置选择具有特定性别、年龄和区域设置的语音。Selects a voice with a specific gender, age, and locale, based on the position in which the voices are ordered. |
| SetOutputToAudioStream(Stream, SpeechAudioFormatInfo) |
配置 SpeechSynthesizer 对象以追加输出到音频流。Configures the SpeechSynthesizer object to append output to an audio stream. |
| SetOutputToDefaultAudioDevice() |
配置 SpeechSynthesizer 对象以发送输出到默认音频设备。Configures the SpeechSynthesizer object to send output to the default audio device. |
| SetOutputToNull() |
配置 SpeechSynthesizer 对象以不从对设备、文件或流的聚合操作中发送输出。Configures the SpeechSynthesizer object to not send output from synthesis operations to a device, file, or stream. |
| SetOutputToWaveFile(String) |
配置 SpeechSynthesizer 对象以追加输出到包含波形格式音频的文件。Configures the SpeechSynthesizer object to append output to a file that contains Waveform format audio. |
| SetOutputToWaveFile(String, SpeechAudioFormatInfo) |
配置 SpeechSynthesizer 对象以追加输出到指定格式中的波形音频格式文件。Configures the SpeechSynthesizer object to append output to a Waveform audio format file in a specified format. |
| SetOutputToWaveStream(Stream) |
配置 SpeechSynthesizer 对象以追加输出到包含波形格式音频的流。Configures the SpeechSynthesizer object to append output to a stream that contains Waveform format audio. |
| Speak(Prompt) |
同步使用 Prompt 对象内容的语言。Synchronously speaks the contents of a Prompt object. |
| Speak(PromptBuilder) |
同步使用 PromptBuilder 对象内容的语言。Synchronously speaks the contents of a PromptBuilder object. |
| Speak(String) |
同步使用字符串内容的语言。Synchronously speaks the contents of a string. |
| SpeakAsync(Prompt) |
异步使用 Prompt 对象内容的语言。Asynchronously speaks the contents of a Prompt object. |
| SpeakAsync(PromptBuilder) |
异步使用 PromptBuilder 对象内容的语言。Asynchronously speaks the contents of a PromptBuilder object. |
| SpeakAsync(String) |
异步使用字符串内容的语言。Asynchronously speaks the contents of a string. |
| SpeakAsyncCancel(Prompt) |
取消一个排队的提示的异步合成操作。Cancels the asynchronous synthesis operation for a queued prompt. |
| SpeakAsyncCancelAll() |
取消所有排队、异步、语音合成操作。Cancels all queued, asynchronous, speech synthesis operations. |
| SpeakSsml(String) |
同步包含 SSML 标记的 String 的语言。Synchronously speaks a String that contains SSML markup. |
| SpeakSsmlAsync(String) |
异步使用包含 SSML 标记的 String 的语言。Asynchronously speaks a String that contains SSML markup. |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
事件
| BookmarkReached |
SpeechSynthesizer 在提示中遇到书签时引发。Raised when the SpeechSynthesizer encounters a bookmark in a prompt. |
| PhonemeReached |
当音素达到时引发。Raised when a phoneme is reached. |
| SpeakCompleted |
当 SpeechSynthesizer 完成提示的讲话的时候引发。Raised when the SpeechSynthesizer completes the speaking of a prompt. |
| SpeakProgress |
在 SpeechSynthesizer 使用提示的每个单词后引发。Raised after the SpeechSynthesizer speaks each individual word of a prompt. |
| SpeakStarted |
当 SpeechSynthesizer 开始提示的讲话的时候引发。Raised when the SpeechSynthesizer begins the speaking of a prompt. |
| StateChanged |
当 SpeechSynthesizer 的状态更改的时候引发。Raised when the state of the SpeechSynthesizer changes. |
| VisemeReached |
当 viseme 达到时引发。Raised when a viseme is reached. |
| VoiceChange |
当 SpeechSynthesizer 的语音更改的时候引发。Raised when the voice of the SpeechSynthesizer changes. |