一个基于c#3.0的开发基于vista下语音朗读的通用类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;
using System.Speech;


namespace [email protected]
{
    public class SpeechSpeak
    {
        public SpeechSynthesizer synth;
        public SpeechSpeak()
        {

            synth = new SpeechSynthesizer();

        }
        // public SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
     
        public SpeechSpeak(int m, int n)
        {
          
            //使用 synth 设置朗读音量 [范围 0 ~ 100]
            synth.Volume = m;
            //使用 synth 设置朗读频率 [范围 -10 ~ 10]
            synth.Rate = n;
        }


        public void SpeakChina(string ggg)
        {

            //SpVoice Voice = new SpVoice();
            synth.SelectVoice("Microsoft Lili");


            //Voice.Speak(ggg, SpFlags);
            synth.SpeakAsync(ggg);

 

            //String speechPeople = synth.Voice;
            //使用 synth 设置朗读音量 [范围 0 ~ 100]
            // synth.Volume = 80;
            //使用 synth 设置朗读频率 [范围 -10 ~ 10]
            //      synth.Rate = 0;

            //使用synth 合成 wav 音频文件:
            //synth.SetOutputToWaveFile(string path);

        }

 

        public void SpeakEnglish(string ggg)
        {

            //SpVoice Voice = new SpVoice();
            synth.SelectVoice("Microsoft Anna");

            synth.Speak(ggg);


        }
        public int m
        {
            get
            {
                return synth.Volume;

            }
            set
            {

                synth.Volume = value;
            }

 

        }


        public int n
        {
            get
            {
                return synth.Rate;

            }
            set
            {

                synth.Rate = value;
            }

 

        }

 

 


        public void Pause()
        {

            synth.Pause();


        }
        public void Goon()
        {

            synth.Resume();


        }
        public void Cancel()
        {


            synth.SpeakAsyncCancelAll();
        }
    }
}

需要源码的请留下Email

你可能感兴趣的:(C#)