Alen Liu

人生最重要的不是过得怎样,而是懂得怎样过。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

一个有趣的东西,今后可能用得上。

C#语音识别:在命名空间 System.Speech下SpeechSynthesizer可以将文字转换成语音

 

贴出代码:

public partial class Form1 : Form
    {
        private SpeechSynthesizer ss;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ss = new SpeechSynthesizer();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ss.Rate = trackbarSpeed.Value;
            ss.Volume = trackbarVoice.Value;
            ss.SpeakAsync(txtSpeechText.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ss.Pause();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ss.Resume();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            SpeechSynthesizer ss = new SpeechSynthesizer();
            ss.Rate = trackbarSpeed.Value;
            ss.Volume = trackbarVoice.Value;
            SaveFileDialog savefd = new SaveFileDialog();
            savefd.Filter = "wave Files|*.wav";
            ss.SetOutputToWaveFile(savefd.FileName);
            ss.Speak(txtSpeechText.Text);
            ss.SetOutputToDefaultAudioDevice();
            MessageBox.Show("完成录音~~~", "提示");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }

 

posted on 2014-09-05 15:41  Alen Liu  阅读(1364)  评论(0编辑  收藏  举报