ARTICLE

Application to speak the text in the textbox using C#.Net

Posted by Prashanth Chindam Articles | Current Affairs September 28, 2010
In this article you will learn how to use application to speak the text in the textbox using C#.Net.
Reader Level:
Download Files:
 

Design:

textspeaker1.JPG

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

Now goto code window and include 'using SpeechLib' namespace

Code: 


using
System;
using
System.Windows.Forms;
using
SpeechLib;//include this namespace

 namespace TextSpeaker
{
    public partial class TextSpeakerForm : Form
    {
        public TextSpeakerForm()
        {
            InitializeComponent();
        }

        private void btnSpeak_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length > 0)
            {
                SpVoice obj = new SpVoice();
                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 = "";
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


Output:

Write some text in the textbox and press 'speak' button

textspeaker3.JPG

Login to add your contents and source code to this article
post comment
     
Posted by navatha rao Oct 07, 2010

Hey Prashnath,
Nice code, i was just wondering where is the business implementation for the same.

Posted by Yatin Choubal Sep 29, 2010
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts