SpeechSynthesizer demo : Speech Synthesis « Windows Presentation Foundation « C# / C Sharp






SpeechSynthesizer demo

SpeechSynthesizer demo
  
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Speech Synthesis" Height="300" Width="300"
    >
    <Grid>
        
    </Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Speech.Synthesis;

namespace WpfApplication1
{
    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();

            SpeechSynthesizer synthesizer = new SpeechSynthesizer();
            PromptBuilder promptBuilder = new PromptBuilder();

            promptBuilder.AppendTextWithHint("WPF", SayAs.SpellOut);
            promptBuilder.AppendText("sounds better than WPF.");

            // Pause for 2 seconds
            promptBuilder.AppendBreak(new TimeSpan(0, 0, 2));
            
            promptBuilder.AppendText("The time is");
            promptBuilder.AppendTextWithHint(DateTime.Now.ToString("hh:mm"), SayAs.Time);
            
            promptBuilder.StartVoice("this is a test");
            promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut);
            promptBuilder.EndVoice();
            
            promptBuilder.AppendText("Do it faster!");
            
            promptBuilder.StartVoice("Hi");
            promptBuilder.StartStyle(new PromptStyle(PromptRate.ExtraFast));
            promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut);
            promptBuilder.EndStyle();
            promptBuilder.EndVoice();
 
            synthesizer.SpeakAsync(promptBuilder);
        }
    }
}

   
    
  








Related examples in the same category

1.Speech Synthesis demoSpeech Synthesis demo