C # convert text into sound,

Source: Internet
Author: User

C # convert text into sound,

In the System. Speech namespace, The SpeechSynthesizer class can read the text and play it together ~~

First, introduce System. Speech in the Windows Forms project. Interface section:

 

The background code is also very simple, but some methods of the SpeechSynthesizer class are called:

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 ("complete recording ~~ "," Prompt ");
        }
 
        private void buttonClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.