.NET [C#] Speech Recognition Tutorial

Speech Recognition Tutorial

Their are an uncountable amount of uses for speech recognition. Today's computers all have speech recognition built in. With speech recognition I can make my program much more user friendly and more efficient in numerous ways. Making your own word processor for your family or even as a side job? Why not add speech recognition as a main feature. Not only does it add value to your windows applications, it will add sophistication. In this tutorial we will cover the basics of getting setup.

Warning - This tutorial is not recommended for inexperienced C# programmers. This tutorial will leave small details out that experienced C# programmers will already know.


Project Setup


Lets begin by creating a new Windows Forms Application. Now over in our projects references, lets add a new .Net System.Speechlibrary. After this, add two buttons and one rich text box to your form. Name the buttons as follows on the image below.

[​IMG]


Speech Engine Setup


Double click the main form. This will create a Form_Load function and bring us to the code window. First thing is to declare ourSystem.Speech and System.Threading references to the Form1 class.

At the beginning of our Form1 class. Lets declare a few classes.

Code (Text):
SpeechRecognitionEngine - Speech engine that translates human speech to a digital text format.
Choices - Selective grammar conditions.
Grammar - The complete set of grammar rules for the speech engine to go by.
Thread - A system thread.
GrammarBuilder - Builds all of our grammar rules.

[​IMG]


Loading Speech Engine


Then setup our Grammar rules. The GrammarBuilder is going to build our selective grammar choices with our dictated grammar.

Dictation Grammar - A set of rules used to translate all human speech in to digital text. Unlike selective grammar choices, dictation grammar is for non-specific grammar choices.

Now we need to initialize the speech recognizer and setup a few properties and events.

[​IMG]


Recognizing Speech


First lets focus on Looping our Receiving calls. We do this too accept new speech input after another speech input has been received. Under our RecThreadFunction:

[​IMG]

Now under the function raised by the recognizer when speech has been understood, we want to handle our selective grammar choices we set and any dictated grammar. Take note how we invoke the main thread using an anonymous method. We do this so we can call functions parent to the main thread without cross threading.

[​IMG]


Final Steps


The last thing we need to do is to dispose of the recognizer on form exit. We also need to setup our enable and disable button functions. These steps are self explanatory. 

[​IMG]


Results


[​IMG]



I hope you enjoyed this tutorial. Please keep in mind this is the basics of getting started. Their are many more options and stages of post processing to come. Thank you.

If you have any questions or comments, please post below.

1 comment:

  1. My ex ruined my credit due to his incessant extravagant spending spree, I found myself in a big mess. I talked to a credit repair company and I was told that it would take me non less than a year to fix my credit. I was devastated, that's a very long time which I can't cope with. I looked online and came across Credit Doctor's contact, hit him up and to my greatest surprise, my credit was repaired in 4 working days from 486 -810. I was so amazed and it didn't cost me too much really. I implore you to contact him on for all credit issues and hacking issues. No doubt that he's the best out there and your problems will be solved!
    HACKINTECHNOLOGY@GMAIL.COM
    +16692252253

    ReplyDelete