Design:
![textspeaker1.JPG](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tlHmiZarm4_iXwtMMYC5-B1PzC6oGFidaNxv4sG--BSZSC8ckCjUCTDmv8UJaAZEiRmEGQmtIDjzJ5cUasI5x3PNG4so9IfTB3FKy5yJTjAJKAyQXg3yLvi7FXnWMb-vFc5eFaCbVz3NnnGj62GR_GW7_APXAHb66JojkeCx5vpND8gLkupGR1434OJdgREFVo8e6pJP0-sRHFTXUeRlCuP2MbMgcGvSI=s0-d)
Design the form as shown above with one TextBox and three Buttons, Set the 'textBox1' Properties as follows:
Dock: Top,
Multiline: True.
Now goto 'Project' Menu -> Select 'AddReference'-> Click on 'COM' tab.
Select 'Microsoft Speech Object Library' COM component -> OK
![textspeaker2.JPG](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_uylzJwZHrxMYADgrv06LpHtaam4_KVFBOISeFHWw5bHOw5OnrNcsHiiEUuXfCrrIGVVDf29UAxVzg0sjAcf7lOP0nNMwG4YcKLxMpkLoDezHn7YAnPsFSqQHY98CGWvmQcH67JWjwRiE73sFDImRln-3toxaSu8Cx5nEz2K_nLFYkDaEG-OYvOpaqC-84WXrX2FVA8wddIiieZqVoA7IE1ltKfui5zCi0X=s0-d)
Now goto code window and include 'using SpeechLib' namespace
Code:
using System;
using System.Windows.Forms;
using SpeechLib;//include this namespace
Design the form as shown above with one TextBox and three Buttons, Set the 'textBox1' Properties as follows:
Dock: Top,
Multiline: True.
Now goto 'Project' Menu -> Select 'AddReference'-> Click on 'COM' tab.
Select 'Microsoft Speech Object Library' COM component -> OK
Now goto code window and include 'using SpeechLib' namespace
Code:
using System;
using System.Windows.Forms;
using SpeechLib;//include this namespace
namespace TextSpeaker
{
public partialclass TextSpeakerForm : Form
{
public TextSpeakerForm()
{
InitializeComponent();
}
{
public partialclass TextSpeakerForm : Form
{
public TextSpeakerForm()
{
InitializeComponent();
}
private void btnSpeak_Click(object sender,EventArgs e)
{
if (textBox1.Text.Trim().Length > 0)
{
SpVoice obj = newSpVoice();
obj.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault);
}
MessageBox.Show("Plz. write some text in the TextBox","Info.",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
{
if (textBox1.Text.Trim().Length > 0)
{
SpVoice obj = newSpVoice();
obj.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault);
}
MessageBox.Show("Plz. write some text in the TextBox","Info.",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void btnClear_Click(object sender,EventArgs e)
{
textBox1.Text = "";
}
{
textBox1.Text = "";
}
private void btnExit_Click(object sender,EventArgs e)
{
this.Close();
}
}
}
Output:
Write some text in the textbox and press 'speak' button
![textspeaker3.JPG](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_t6b5nDBrdt_Uex07cltQVY5E0XRIbRMNir3kNkW9q9FGL1xfYHGcWM1PXjYkXS_uur3VAMpFvWuN-rm1GxdgGlzmSXWslPi0hPDHRytulnAA329k0SnEgx6X0dFQhxPubraJ-FaIO9uCSA6ZB4wG9IhcfsajLwY86MktXgmGFFPf5rBPjqYgmAime8mmgrZKjXFBZTrWlCmhQY5gCqGnfeaMydRP5zJ8Wi=s0-d)
{
this.Close();
}
}
}
Output:
Write some text in the textbox and press 'speak' button
![](http://1.bp.blogspot.com/_b0xJ7qk6DTc/TG90pU_i9JI/AAAAAAAAA4A/3TSvL5japaI/s1600/tag_blue.png)
Responses
0 Respones to "Application to speak the text in the textbox using C#.Net"
Post a Comment