Here is simple application which makes use of COM Library and
with some lines of code you can give any application a voice.
This example and the application explain three concepts.
1. Adding COM references to your Project.
2. Declaring and using relevant object.
3. Adding voice responses as your application.
1. Adding COM references to your Project.
Open a new windows form application and add Textbox and Button. To add link the relevant reference follow these steps
Right click your project node in solution explorer in which you want to add reference --> click Add Reference
In
the Add Reference explorer window select the COM component from the COM
tab or use browse option if you want to add specific dll from another
resource. For this example you can add sapi.dll following path below
%windows%/System32/Speech/Common/sapi.dll
you
may copy this dll into your bin folder which makes it easy to reference
and some times it is feasable to provide dll with your installation
package as your windows might lack it.
2. Declaring and using relevant object.
// add this reference to your assembly
using SpeechLib;
// Declare object in the class
SpVoice spVoice;
Use a button and add following code behind its OnClick Event
// textToSpeak = any string you want to listen
spvoice.Speak(textToSpeak, SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
3. Adding voice responses as your application.
You can add any voice play back at any of the biultin events as follows
// Speak when application starts
private void Pronouncer_Shown(object sender, EventArgs e)
{
spvoice.Speak("Hello and Welcome To the English Pronouncing application", SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
}
// Speak when application Closes
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
spvoice.Speak("Thank you for using Application, goodbye", SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
}