Posts Tagged ‘Windows Forms’

How to make your application speak…using microsoft’s speech object library in C#

Open VS2008…
# Create new windows form project (I have named it talker here).

# Now right click on your Project(Talker in this case) and select add reference.

# Now under COM select Microsoft Speech Object Library and press Ok.

MS speed lib1

#Now in your win form add 1 menu strip,1 text box and 1 Button(change text property to Talk).

# Now in the menu strip add 2 menus File and Help.Under file add exit.

MS speech lib2

# Now in the properties of TextBox change the MultiLine property to true.

# Now your form should look somewhat like this.

MS speech lib3

# Lets add functionality to our form.

# Double click on exit menu in your menu strip.
Now add the following code in the click event handler.

this.Close();

# Now add this at the top of your code

using SpeechLib;

# Now double click on the Talk button in your design. Add the following code

SpVoice voice = new SpVoice(); voice.Speak(textBox1.Text,SpeechVoiceSpeakFlags.SVSFDefault);

# You can add anything you like in the Help menu strip. item. I have added the following

MessageBox.Show(“Just enter the text and press talk”);

# Now press F5 and enter any text and press talk. You will hear your system speaking out the text you entered.

MS speech lib4

Download the source files here