About Me

My photo
Experienced software engineer with about 7 years of expertise in mobile application development. Specialized in Xamarin.Forms and Flutter. Recognized as an MVP at C-Sharp Corner, I actively contribute to the developer community through articles and a published e-book on Xamarin.Forms.

Saturday, 18 June 2016

Text to speech converter in C#



Text to speech converter in C#



Motivation comes to me when I am doing my project on Text to speech converter and it takes a lot of time to know about its syntax and libraries. So I decide to write on it so you can do conversion of text to speech with little effort by follow this pattern.

So don't worry if you doesn't know about:
1-      libraries to add.
2-      system reference to include in project.
3-      syntax of speech recognition and speech synthesis.

Starting from the very initial point


You must include this reference by right clicking on project name select reference
       Microsoft.system.speech;

Libraries to use in c-sharp:
    using System.Speech.Synthesis;
      using System.Speech.Recognition;




Syntax of Speech To Text


Public void SpeakText() {

PromptBuilder Pbuilder = new PromptBuilder();

SpeechSynthesizer synth = new SpeechSynthesizer();

Pbuilder.ClearContent();

Pbuilder.AppendText(“Text You want to speek”);


synth.Speak(Pbuilder); }





  Code for Desktop app:


   The form contains one textbox named textBox and a button named button1.
    Any thing you write in text box will be spoken by your computer when button1 is pressed.


using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Threading;



namespace Project_Name

{
public partial class Form1 : Form

{
public Form1()

{

InitializeComponent();

}

SpeechSynthesizer synth = new SpeechSynthesizer();

PromptBuilder Pbuilder = new PromptBuilder();

private void Form1_Load(object sender, EventArgs e)

{

}

private void button1_Click(object sender, EventArgs e)

{

Pbuilder.ClearContent();

Pbuilder.AppendText(textBox1.Text);

synth.Speak(Pbuilder);

}

}

}

  Now that's all you need.
  So, are you ready to give a try to build your own speaking app?
  *Comments and suggestions are valuable


No comments:

Post a Comment