SpeechSynthesizer.Speak 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从字符串、 Prompt 对象或 PromptBuilder 对象同步生成语音输出。
重载
| 名称 | 说明 |
|---|---|
| Speak(Prompt) |
以同步方式表示对象的内容 Prompt 。 |
| Speak(PromptBuilder) |
以同步方式表示对象的内容 PromptBuilder 。 |
| Speak(String) |
以同步方式表示字符串的内容。 |
注解
这些 Speak 方法以同步方式生成语音。 在完全朗读实例的内容 Speak 之前,这些方法不会返回。 这是生成语音的最简单方法。 但是,如果应用程序需要在说话时执行任务,例如突出显示文本、画图动画、监视控件或其他任务,请使用 SpeakAsync 方法或 SpeakSsmlAsync 方法异步生成语音。
在调用此方法期间, SpeechSynthesizer 可以引发以下事件:
StateChanged。 合成器说话状态更改时引发。
SpeakStarted。 合成器开始生成语音时引发。
PhonemeReached。 每次合成器到达一个字母或字母组合时引发,这些字母构成语言中谨慎的语音声音。
SpeakProgress。 每次合成器完成说话时引发。
VisemeReached。 每次说出输出时引发都需要改变用于生成语音的嘴或面部肌肉的位置。
BookmarkReached。 当合成器在提示中遇到书签时引发。
VoiceChange。 合成器语音更改时引发。
处理任何SpeechSynthesizer方法时,不会SpeakCompleted引发Speak事件。
Speak(Prompt)
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
以同步方式表示对象的内容 Prompt 。
public:
void Speak(System::Speech::Synthesis::Prompt ^ prompt);
public void Speak(System.Speech.Synthesis.Prompt prompt);
member this.Speak : System.Speech.Synthesis.Prompt -> unit
Public Sub Speak (prompt As Prompt)
参数
- prompt
- Prompt
要说的内容。
示例
以下示例从字符串创建一个 Prompt 对象,并将该对象作为参数传递给 Speak 该方法。
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();
// Create a prompt from a string.
Prompt color = new Prompt("What is your favorite color?");
// Speak the contents of the prompt synchronously.
synth.Speak(color);
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
注解
若要异步朗讲对象的内容 Prompt ,请使用 SpeakAsync。
适用于
Speak(PromptBuilder)
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
以同步方式表示对象的内容 PromptBuilder 。
public:
void Speak(System::Speech::Synthesis::PromptBuilder ^ promptBuilder);
public void Speak(System.Speech.Synthesis.PromptBuilder promptBuilder);
member this.Speak : System.Speech.Synthesis.PromptBuilder -> unit
Public Sub Speak (promptBuilder As PromptBuilder)
参数
- promptBuilder
- PromptBuilder
要说的内容。
示例
以下示例从字符串创建一个 PromptBuilder 对象,并将该对象作为参数传递给 Speak 该方法。
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();
// Create a PromptBuilder object and append a text string.
PromptBuilder song = new PromptBuilder();
song.AppendText("Say the name of the song you want to hear");
// Speak the contents of the prompt synchronously.
synth.Speak(song);
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
注解
若要异步朗讲对象的内容 PromptBuilder ,请使用 SpeakAsync。
适用于
Speak(String)
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
- Source:
- SpeechSynthesizer.cs
以同步方式表示字符串的内容。
public:
void Speak(System::String ^ textToSpeak);
public void Speak(string textToSpeak);
member this.Speak : string -> unit
Public Sub Speak (textToSpeak As String)
参数
- textToSpeak
- String
要说的文本。
示例
如以下示例所示,该方法 Speak 提供了同步生成语音输出的最简单方法。
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();
// Speak a string synchronously.
synth.Speak("What is your favorite color?");
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
注解
若要同步朗讲包含 SSML 标记的字符串,请使用该方法 SpeakSsml 。 若要异步朗讲字符串的内容,请使用 SpeakAsync 该方法。