SpeechSynthesizer.State 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 SpeechSynthesizer 物件目前的讀出狀態。
public:
property System::Speech::Synthesis::SynthesizerState State { System::Speech::Synthesis::SynthesizerState get(); };
public System.Speech.Synthesis.SynthesizerState State { get; }
member this.State : System.Speech.Synthesis.SynthesizerState
Public ReadOnly Property State As SynthesizerState
屬性值
傳回 SpeechSynthesizer 物件目前的讀出狀態。
範例
下列範例說明在 SpeechSynthesizer 說話提示之前、期間和之後的狀態。
using System;
using System.Threading;
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();
// Subscribe to the SpeakProgress event.
synth.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);
// Write the state of the SpeechSynthesizer to the console.
Console.WriteLine("Current Synthesizer state: " + synth.State + "\n");
// Speak a string asynchronously.
synth.SpeakAsync("What is your favorite color?");
// Write the state of the SpeechSynthesizer to the console while it is speaking.
Thread.Sleep(1000);
Console.WriteLine("\n - Current Synthesizer state: " + synth.State + " - \n");
// Write the state of the SpeechSynthesizer to the console after it is done speaking.
Thread.Sleep(2000);
Console.WriteLine("\nCurrent Synthesizer state: " + synth.State);
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
{
Console.WriteLine(e.Text);
}
}
}
備註
若要在變更之後取得的新狀態 SpeechSynthesizer ,請使用 State 類別的屬性 StateChangedEventArgs 。