Speech Recognition in Windows Phone 8- SRGS Grammars

In one of my previous blog post, we learnt how to implement the speech recognition in Windows Phone 8 using the Built-in grammars and the List Grammars. This blog post will explain in simple steps on how to integrate the speech to text feature in Windows Phone 8 using the SRGS Grammars.

SRGS stands for Speech Recognition Grammar Specification where the phrases for the speech includes rules and semantics. The SRGS file is a simple XML file with predefined tags that conforms to the SRGS v1.0 specification.

Speech Recognition in Windows Phone 8- SRGS Grammars

To Add a new SRGS grammars to the windows phone project, follow the below steps

  1. In the Windows Phone Project, right click on the project and select “Add” -> “New Item”. This will display the “Add New Item” Dialog. Select the “SRGS Grammar” template, provide a proper name for the file “SRGSGrammar1” and click “OK”. This will add the XML file to the project as per the SRGS specification with the sample data.

    Speech Recognition in Windows Phone 8- SRGS Grammars

Below is a sample specification file which will be used in this example

<?xml version="1.0" encoding="utf-8" ?>

<grammar version="1.0" xml:lang="en-US" root="Actors" tag-format="semantics/1.0"

xmlns="http://www.w3.org/2001/06/grammar"

xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions">

<rule id="Actors" scope="public">

<one-of>

<item> Rajnikanth </item>

<item> Dr. Raj Kumar </item>

<item> Amitabh </item>

<item> Vijay </item>

</one-of>

</rule>

</grammar>

The grammar element includes the attributes

  • version – specifies the version of the SRGS
  • xml:lang – specifies the language for the content
  • root – optional attribute to specify the name of the rule which will be active
  • xmlns – for specifying the namespace

The “rule” element defines the text that the user can say. The grammar should have alteast one rule. It can contain the elements “item” or “ruleref” elements.

  1. The next step is to integrate the SRGS xml file to the windows phone project and set it to the speech recognizer’s grammar as shown below

     

async private void Button_Click_1(object sender, RoutedEventArgs e)

{

SpeechRecognizerUI speech = new SpeechRecognizerUI();

// Get the path of the file

string path = "ms-appx:///SRGSGrammar1.xml";

speech.Recognizer.Grammars.AddGrammarFromUri("SRGSGrammar", new Uri(path, UriKind.RelativeOrAbsolute));

SpeechRecognitionUIResult result = await speech.RecognizeWithUIAsync();

if (result.ResultStatus == SpeechRecognitionUIStatus.Succeeded)

{

MessageBox.Show(result.RecognitionResult.Text);

}

}
  1. That’s it. We are ready to run the app and test our simple SRGS grammar. When the SpeechRecognizerUI dialog is shown, speak one of the items defines in the rule “Actors” of the SRGS grammar that we created above and you should see the sample result as shown below.

     

Speech Recognition in Windows Phone 8- SRGS Grammars

No Responses

Leave a Reply