win7 C# 利用windows自帶語音類庫讀書 spvoice,電腦端 讀書-摘自網絡

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private SpeechVoiceSpeakFlags _spFlags;
        private SpVoice _voice;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _voice = new SpVoice();
            _spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            _voice.Voice = _voice.GetVoices("", "").Item(comboBox2.SelectedIndex);
            _voice.Voice.GetDescription(comboBox2.SelectedIndex);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //if(_voice.Status.RunningState == SpeechRunState.SRSEIsSpeaking)
               _voice.Speak(textBox1.Text, _spFlags);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //其中3爲中文,024爲英文
            //_voice.Voice = _voice.GetVoices(string.Empty, string.Empty).Item(comboBox1.SelectedIndex == 0 ? 3 : 24);
        }

        /// <summary>
        /// Stop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            _voice.Speak(string.Empty, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
        }

        private void Pause_Click(object sender, EventArgs e)
        {
            _voice.Pause();
        }

        private void Resume_Click(object sender, EventArgs e)
        {
            _voice.Resume();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            //_voice.Voice = _voice.GetVoices("", "").Item(comboBox2.SelectedIndex);
            _voice.Voice.GetDescription(comboBox2.SelectedIndex);
        }
    }
}


-摘自網絡


2 摘自網絡

using System.Windows.Forms;
using System.Speech;
using System.Speech.Synthesis;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private SpeechSynthesizer ss;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ss = new SpeechSynthesizer();
        }
        private void buttonRead_Click(object sender, EventArgs e)
        {
            ss.Rate = trackBarSpeed.Value;
            ss.Volume = trackBarVolumn.Value;
            ss.SpeakAsync(txtMsg.Text);
        }
        private void buttonPause_Click(object sender, EventArgs e)
        {
            ss.Pause();
        }
        private void buttonContinue_Click(object sender, EventArgs e)
        {
            ss.Resume();
        }
        private void buttonRecord_Click(object sender, EventArgs e)
        {
            SpeechSynthesizer ss = new SpeechSynthesizer();
            ss.Rate = trackBarSpeed.Value;
            ss.Volume = trackBarVolumn.Value;
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Wave Files|*.wav";
            ss.SetOutputToWaveFile(sfd.FileName);
            ss.Speak(txtMsg.Text);
            ss.SetOutputToDefaultAudioDevice();
            MessageBox.Show("完成錄音~~", "提示");
        }
        private void buttonClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章