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.Rate = 2;
            _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.Rate = int.Parse(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();
        }
    }
}

  

posted @ 2022-03-23 11:50  iDEAAM  阅读(58)  评论(0编辑  收藏  举报