Tuesday, December 7, 2010

Text to Speech Application

Today we will make a text to speech application which will read aloud the the text we enter.

We will start by opening a new project in Visual Studio 2010(or previous versions). We will name our project "TextToSpeech" as shown in the picture below.


We will now add a Label, Text box and a button. Change the text property of label to "Please enter text and I will Speak it for you". Change the multiline property of the text box to true and change the text of the button to "Speak".
Now go to project menu and click Add Reference. Now navigate to the COM tab of the add reference dialog box and select "Microsoft Speech Object Library". Click OK.
Double click on the button to generate a default event handler. Now right code.

VB.net
Dim speech As New SpeechLib.SpVoice
speech.Speak(TextBox1.Text, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault)

C#
SpeechLib.SpVoice speech = New SpeechLib.SpVoice;
speech.Speak(TextBox1.Text, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);

Now Debug the the program to make sure it works properly. write any thing in the text box and click the speak button and the computer will speak what you enter.

No comments:

Share the Knowledge

My Card