SpeakProgressEventArgs 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳事件 SpeakProgress 資料。
public ref class SpeakProgressEventArgs : System::Speech::Synthesis::PromptEventArgs
public class SpeakProgressEventArgs : System.Speech.Synthesis.PromptEventArgs
type SpeakProgressEventArgs = class
inherit PromptEventArgs
Public Class SpeakProgressEventArgs
Inherits PromptEventArgs
- 繼承
範例
以下範例展示了從 SpeakProgressEventArgs中可獲得的資訊。 請注意 、 StartParagraph、 EndParagraph和 StartSentence 方法如何EndSentence透過在生成的 SSML 中加入 >、>、> 和 > 標籤來影響 。 此外,輸出中「30%」有兩個項目,分別代表每個說出此數字字串的詞(30%)。 CharacterCount和 CharacterPosition 對每個條目相同,代表字元「30%。 然而, AudioPosition 為了反映「三十」和「百分比」這兩個詞的發音,這些變化會被 SpeechSynthesizer。
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.SetOutputToWaveFile(@"C:\test\weather.wav");
// Create a SoundPlayer instance to play the output audio file.
System.Media.SoundPlayer m_SoundPlayer =
new System.Media.SoundPlayer(@"C:\test\weather.wav");
// Build a prompt containing a paragraph and two sentences.
PromptBuilder builder = new PromptBuilder(
new System.Globalization.CultureInfo("en-US"));
builder.StartParagraph();
builder.StartSentence();
builder.AppendText(
"The weather forecast for today is partly cloudy with some sun breaks.");
builder.EndSentence();
builder.StartSentence();
builder.AppendText(
"Tonight's weather will be cloudy with a 30% chance of showers.");
builder.EndSentence();
builder.EndParagraph();
// Add a handler for the SpeakProgress event.
synth.SpeakProgress +=
new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);
// Speak the prompt and play back the output file.
synth.Speak(builder);
m_SoundPlayer.Play();
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
// Write each word and its character position to the console.
static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
{
Console.WriteLine("CharPos: {0} CharCount: {1} AudioPos: {2} \"{3}\"",
e.CharacterPosition, e.CharacterCount, e.AudioPosition, e.Text);
}
}
}
備註
當SpeakProgressEventArgs物件提出事件時SpeechSynthesizer,會產生一個SpeakProgress實例。 該SpeechSynthesizer詞會根據提示詞中用任一Speak、SpeakAsyncSpeakSsml或SpeakSsmlAsync方法,每說出一個新詞就觸發此事件。
回傳的資料是基於程式碼產生的語音合成標記語言(SSML)。 回傳的 CharacterCount 值包含空格,以及由程式碼產生的 SSML 標籤的字元和內容。
屬性
| 名稱 | Description |
|---|---|
| AudioPosition |
取得事件的音訊位置。 |
| Cancelled |
會得到一個值,表示非同步操作是否已被取消。 (繼承來源 AsyncCompletedEventArgs) |
| CharacterCount |
取得事件被提出前剛說出的字元數。 |
| CharacterPosition |
取得從提示開始到剛說出的單字第一個字母前的字元數和空格。 |
| Error |
會獲得一個值,表示非同步操作中發生了哪個錯誤。 (繼承來源 AsyncCompletedEventArgs) |
| Prompt |
會收到與事件相關的提示。 (繼承來源 PromptEventArgs) |
| Text |
剛剛被提及事件時說出的簡訊。 |
| UserState |
取得非同步任務的唯一識別碼。 (繼承來源 AsyncCompletedEventArgs) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| RaiseExceptionIfNecessary() |
若非同步操作失敗,則會觸發使用者提供的例外。 (繼承來源 AsyncCompletedEventArgs) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |