//-------------------------------------------------- // TrySpeech.cs (c) 2006 by Charles Petzold //-------------------------------------------------- using System; using System.Speech.Synthesis; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace Petzold.TrySpeech { public class TrySpeech : Window { SpeechSynthesizer speech = new SpeechSynthesizer(); [STAThread] public static void Main() { Application app = new Application(); app.Run(new TrySpeech()); } public TrySpeech() { Title = "Try Speech"; Button btn = new Button(); btn.Content = "Click me, please"; btn.FontSize = 24; btn.HorizontalAlignment = HorizontalAlignment.Center; btn.VerticalAlignment = VerticalAlignment.Center; btn.Click += ButtonOnClick; Content = btn; speech.SpeakTextAsync("Today is " + DateTime.Now.ToLongDateString() + ". " + "My name is " + speech.Voice.Name.ToString() + ". " + "Click the button, please"); } void ButtonOnClick(object sender, RoutedEventArgs args) { speech.SpeakTextAsync("Thank you for clicking the button."); } } }