Get the list of recognized words from Kinect speech commands

Get the list of recognized words from Kinect speech commands

When a speech is recognized by the Speech Recognizer engine, the Speech Recognizer returns the recognized words as collection of the type RecognizedWordUnit class.  This set of words are extremely useful to deal with any sentences. In my previous post, I discussed about recognizing a statement like “draw a read circle” or “draw a green circle”; where we had to identify the sentences from the Kinect captured audio and then splitting it in a series of words.
With Microsoft Speech API, the SpeechRecognitionEngine class handles all the operation related with the speech. You can then attach an event handler to the SpeechRecognized event, which will fire whenever the audio is internally converted into text and identified by the recognizer. The following code shows how you can create an instance of SpeechRecognitionEngine and register the Speech Recognized event handler.

SpeechRecognitionEngine speechRecognizer = new SpeechRecognitionEngine();
speechRecognizer.SpeechRecognized += speechRecognizer_SpeechRecognized;

Once the speech is recognized, you can perform the required operation using the SpeechRecognizedEventArgs.Result property as follows:

void speechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Recognized Text {0} ", e.Result.Text);
}

The SpeechRecognizer event handler has a Result property of type RecognitionResult class. The Result property contains what has been identified and the quality in terms of confidence level.
So if you speak “draw a green cirecle” , the Text value of the Result will be the “Draw a green Circle” . Whereas the “Words”, class will contains the list of all identified words as a collection.
Words from Speech Command in Kinect
You write following code snippet to get the list of identified words

private void GetListOfWords(RecognitionResult result)
{
StringBuilder sb = new StringBuilder();
foreach (var word in result.Words)
{
Console.Write(word.Text);
}
}

Here is how you can get the list of words while debugging

List of Words

 

 

 

 

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

One Comment to “Get the list of recognized words from Kinect speech commands”

Comments are closed.