可直接拿来用的文本转语音的代码

using DotNetSpeech;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YLSoft.Pola.Utils.Common
{
    public class VoiceHelper
    {
        private int _volume=100;
        /// <summary>
        /// 音量(从0到100的整数)
        /// </summary>
        public int Volume
        {
            get
            {
                if (_volume < 0)
                    _volume= 0;
                else if(_volume>100)
                {
                    _volume = 100;
                }
                return _volume;
            }
            set { _volume = value; }
        }

        private int _rate=0;

        public int Rate
        {
            get { return _rate; }
            set { _rate = value; }
        }
        public  void ProduceVoice(string strContent)
        {
            DotNetSpeech.SpeechVoiceSpeakFlags SSF = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;
            DotNetSpeech.SpVoice vo = new SpVoiceClass();
            vo.Volume = Volume;
            vo.Rate = Rate;
            vo.Speak(strContent, SSF);
        }
    }
}

 

posted @ 2016-05-22 18:32  ChineseMoonGod  阅读(659)  评论(0编辑  收藏  举报