C#文本朗读

C#文本朗读

在这里记录一下C#如何将文本转换为语音,以备以后使用。
主要用到的是SpeechSynthesizer这一个类,要使用首先引入System.Speech

using System.Speech.Synthesis;
namespace Apps
{
    class SpeechHelper
    {
        private SpeechSynthesizer voice;

        public SpeechHelper(int rate, int volume)
        {
            voice.Rate = rate; // 设置语速
            voice.Volume = volume; // 设置音量
        }
        /// <summary>
        /// 异步朗读内容
        /// </summary>
        /// <param name="context">内容</param>
        public void ReadContext(string context)
        {
            voice.SpeakAsync(context);
        }

        /// <summary>
        /// 取消异步朗读
        /// </summary>
        public void CancelSpeech()
        {
            voice.SpeakAsyncCancelAll();
        }

    }
}
发布了26 篇原创文章 · 获赞 41 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/anonymous_qsh/article/details/78633680