Design:
![textspeaker1.JPG](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_s4tpjjj4-7VYYAxzyZNN9yGlvUA4DWudhzala9HSrEEzLRP_u9ppHzWBWd-sWfQKsNccsrYAQ2wSXfSPKKlIkttq9Skft0K3jzM3H6CkyF_-6DZA649XTTtMMTQ6gOvsk5_M_8mgzOwfHjBzhywv9L-IO2_GUoXaUUr0jK2UwRtePdQZlYDgYaz_b1SeAmXu4GsqGFUQod-D-ikOFPawXS37bI-2XkJyc=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_t4q-xSuIjkJKXeUlgzxlZ8Lm_sktUKHlpp3oLJ0tifikEywiy5o-6bPMnh7RRuVzg32c2Ca01rklw7buXHfN_1fiYhxPa9Wz9Rm7B8htEXZ8zC8ErPyg31riDQVHJbqFfPMnjmbSAByBcoIvbZS-lANXXoHPKdxC3--k5PPkntqoR7h64IodCqwS73JGB03EGtmVBj5ymTjLc_sCkLNWtdlZHNc0k6wIcb=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_uQzyjVzbE5sJbmxacJucv9uMUw0_pXpNFC3O7jjlSbdZxOc8p1rUZCZRWZo7pU482dZd56ds2t8ouAmodx2CdFGSwbhpIjNuBwC3Kdz43DQl0xMuOnYasTozjUWgS2HWIjXjoceTJgMrNisfJqYpM7LE4L1nbO9uYWvZqPaToLC8rKdHQv2oiwUzo58vlVdPwm5LC_DrTChSoWF3qURRK17g6K-WoM9t2m=s0-d)
{
this.Close();
}
}
}
Output:
Write some text in the textbox and press 'speak' button