Understand and Read It! – Visual C# API
Here, we will develop an application in Visual C# called "Understand and Read It!". Mohammad Elsheimy's blog is the source of this article. Why? Because, Mohammad Elsheimy has already written it. It is in here (Building Applications that Can Talk). So special thanks to Mohammed Elsheimy.
What is this about?
The Speech API library that we are going to use today is represented by the file sapi.dll which is located in %windir%\System32\Speech\Common. This library is not part of the .NET BCL and it’s not even a .NET library, so we’ll use interoperability to communicate with it (don't worry, when using Visual Studio, it is just a matter of adding a reference to the application)
Here We Go!
Now, in this step, we add a reference of the Speech Library to the project and design our Windows form. Look at the following figure 1:
After this process comes step 2. Design our form as in figure 2:
As shown in the form, I have got one
Buttons and one
TextBox. Now, we go to the third and final step!
Write Code For Yourself!
This is the final step. Write code for ourselves as shown in figure 3:
private void button2_Click(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
if (textBox1.Text == "")
string msgeror = "Text box must not null! Please try again.";
SpVoice erspeak = new SpVoiceClass();
SpVoice speak = new SpVoiceClass();
If you are using Visual Studio 2010 and .NET 4 Framework, the application will fail to run because of Interop problems. So you must select "false" to Embed Interop Types property of Speech Reference.
- To download the Word document file of this article, please Click here.
- For download Visual Studio project file, please Click here.
Thanks to Mohammad Elsheimy who inspired me. Also, if you want to visit the "Building Applications that Can Talk" article, please click here.