Today we are not posting any reviews, technology gadgets or any tips and tricks, we have introduced a new category called Programming with thenerdjob and we hope that our reader and software developers will enjoy. Working on Visual Studio 2012 we will make small application program which can make a text to speak.
I will guide you how to make an application in Visual Studio 2012 (previous version also works), follow below steps to successfully execute the application which can actually speaks from what is written in the text box.
Step 1: Start Visual Studio 2012 (or any version), Create a new project and name it accordingly, I have named it ‘Text2Speech’.
Step 2: You will be displayed with a Form1, now add a Label, a Text Box and a Button from the toolbox.
Change Label property to “Enter Text and I will Speak”. Also change the Multiline property of the text box to True and rename the Button text to “Speak”.
Step 3: Now right click on the project name from right sidebar and click on Add Reference link. Navigate to the COM tab and select “Microsoft Speech Library” from the list and click OK.
Step 4: After adding the speech reference to your project, now double click on the button to fire the event handler function when the user press Speak button, now write the code as shown below:
For C Sharp (C#)If you have create your project under C# environment then use this code:
SpeechLib.SpVoice speech=new SpeechLib.SpVoice();
For VB.NETIf you have create your project under VB.NET environment then use this code:
Dim speech As New SpeechLib.SpVoice
Now debug your program and execute it with the help of play button on the top, enter any sentence in the text box and press speak button, you will hear the sound.