Text to speech conversion in c#
C Sharp

Text to speech conversion in c#

Editorial Team
Editorial Team

Follow us on Discord or Telegram to get access to free tutorials and updates.

This article provides some information about how to perform text to speech (TTS) conversion using c#.

1) Open Visual Studio and create a new Windows Forms application.

2) Now add a textbox and a button to the form.

3) Go to Project -> Add Reference

4) Click on Assemblies and search System.speech. From the result, select System.speech and click OK.

5) Add the following namespace.

using System.Speech; using System.Speech.Synthesis;

6) In the Click event handler (double clock on the button to create) of the button, write the following code.

SpeechSynthesizer speak = new SpeechSynthesizer(); speak.SpeakAsync(textBox1.Text);

7) Your code will be:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Speech; 
using System.Speech.Synthesis;  

namespace TextToSpeech {  
	public partial class Form1 : Form
    {
    	public Form1()
        {
        	InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        { 
        	SpeechSynthesizer speak = new SpeechSynthesizer();
            speak.SpeakAsync(textBox1.Text);
        }
    }
}

This is how you can make simple text to speech conversion using c#.