SpeechSynthesizer.SpeakAsyncCancelAll Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Отменяет все асинхронные операции синтеза речи, в очереди.
public:
void SpeakAsyncCancelAll();
public void SpeakAsyncCancelAll ();
member this.SpeakAsyncCancelAll : unit -> unit
Public Sub SpeakAsyncCancelAll ()
Примеры
В следующем примере показано использование для отмены SpeakAsyncCancelAll асинхронного произнесения запроса, чтобы можно было произнести новый запрос. Обратите внимание, что SpeakCompleted событие возникает при отмене SpeakAsync операции.
using System;
using System.Speech.Synthesis;
using System.Threading;
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 StateChanged event.
synth.StateChanged += new EventHandler<StateChangedEventArgs>(synth_StateChanged);
// Subscribe to the SpeakProgress event.
synth.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);
// Subscribe to the SpeakCompleted event.
synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);
// Begin speaking a text string asynchronously.
synth.SpeakAsync("Speech is an effective and natural way for people to interact with applications, " +
"complementing or even replacing the use of mice, keyboards, controllers, and gestures.");
// Speak for four seconds.
Thread.Sleep(4000);
// Cancel the SpeakAsync operation and wait one second.
synth.SpeakAsyncCancelAll();
Thread.Sleep(1000);
// Speak a new text string.
synth.Speak("An urgent email message has arrived. Do you want to hear it?");
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
// Write to the console when the SpeakAsync operation has been cancelled.
static void synth_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
Console.WriteLine("\nThe SpeakAsync operation was cancelled!!");
}
// When it changes, write the state of the SpeechSynthesizer to the console.
static void synth_StateChanged(object sender, StateChangedEventArgs e)
{
Console.WriteLine("\nSynthesizer State: {0} Previous State: {1}\n", e.State, e.PreviousState);
}
// Write the text being spoken by the SpeechSynthesizer to the console.
static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
{
Console.WriteLine(e.Text);
}
}
}
Применяется к
GitHub сайтында бізбен бірлесіп жұмыс істеу
Бұл мазмұнның көзін GitHub сайтында табуға болады. Онда сонымен бірге мәселелер мен өзгертулерді енгізу сұрауларын жасауға және қарап шығуға болады. Қосымша ақпарат алу үшін қатысушы нұсқаулығын қараңыз.