C#3.0基于Speech.Synthesis调整语音朗读语调范例

来源:互联网 发布:淘宝商品短链接怎么做 编辑:程序博客网 时间:2024/04/30 19:07

using System;
using System.Speech.Synthesis;

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

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

            promptBuilder.AppendTextWithHint("尹成", SayAs.SpellOut);
            promptBuilder.AppendText("尹成大哥毕业于清华大学.");

           
            promptBuilder.AppendBreak(new TimeSpan(0, 0, 2));
           
            promptBuilder.AppendText("尹成大哥是谁");
            promptBuilder.AppendTextWithHint(DateTime.Now.ToString("hh:mm"), SayAs.Time);
           
            // Pause for 2 seconds
            promptBuilder.AppendBreak(new TimeSpan(0, 0, 2));
           
            promptBuilder.AppendText("尹成大哥硕士毕业于中科院?");
           
            promptBuilder.StartVoice("Microsoft Sam");
            promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut);
            promptBuilder.EndVoice();
           
            promptBuilder.AppendText("Do it faster!");
           
            promptBuilder.StartVoice("Microsoft Sam");
            promptBuilder.StartStyle(new PromptStyle(PromptRate.ExtraFast));
            promptBuilder.AppendTextWithHint("queue", SayAs.SpellOut);
            promptBuilder.EndStyle();
            promptBuilder.EndVoice();
 
            // Speak all the content in the PromptBuilder
            synthesizer.SpeakAsync(promptBuilder);
        }
    }
}