HomeWindowsSpeech Recognition in Windows Phone 8 – Built In and Phrase List Grammars

Speech Recognition in Windows Phone 8 – Built In and Phrase List Grammars

This article will explain in simple steps on how to use the Speech Recognition in the Windows Phone App using different built-in and phrase list grammars.

Speech Recognition is one of the important component of the Speech API in Windows Phone 8. It is also known as Speech to Text. The Speech recognition depends on 3 different types of grammars which includes

  • Built-In Grammars which includes dictation grammar and web search grammar. The speech is sent to the cloud service and processed in the server. It is ideal for recognizing short phrase lists. It also relies on the network connection.
  • Phrase List Grammars – The Phrase List grammar allows the developers to define the grammar Programatically in their app
  • XML Grammars based on the Speech Recognition Grammar Specification.

The usage or selection of the grammars for the app depends purely on the complexity of the app and kind of speech recognition needed.

Capabilities Needed for the Speech Recognition in your App.

To use the speech recognition in your windows phone app, it is necessary to define the below capabilities in the WMAppManifest.xml file.

<Capability Name=”ID_CAP_NETWORKING” />

<Capability Name=”ID_CAP_MICROPHONE” />

<Capability Name=”ID_CAP_SPEECH_RECOGNITION” />

Speech Recognition in Windows Phone 8 - Built In and Phrase List Grammars

How to use Speech Recognition in Windows Phone 8 with Dictation Grammar?

It is easy to use the speech recognition in the Windows Phone App. Just instantiate the SpeechRecognizerUI and call its RecognizeWithUIAsync method. When the RecognizeWithUIAsync method is called, the SpeechRecognizerUI displays a dialog which allows the user to speak to the app. below is a sample code snippet demonstrating the usage of the SpeechRecognizerUI for speech recognition in the windows phone app.

async private void AddSpeech()

{

SpeechRecognizerUI speech = new SpeechRecognizerUI();

SpeechRecognitionUIResult result = await speech.RecognizeWithUIAsync();

MessageBox.Show(result.RecognitionResult.Text);

}

Speech Recognition in Windows Phone 8 - Built In and Phrase List Grammars

How to use Speech Recognition in Windows Phone 8 with Web Search Grammar?

By default the speech recognizer API uses the dictation grammar when the grammar is not specified for the SpeechRecognizerUI. You can add the web search grammar to the grammar set of the SpeechRecognizerUI using the Recognizer.Grammars.AddGrammarFromPredefinedType method of the SpeechRecognizerUI object.

async private void AddSpeech()

{

SpeechRecognizerUI speech = new SpeechRecognizerUI();

speech.Recognizer.Grammars.AddGrammarFromPredefinedType("Web Search Grammar", SpeechPredefinedGrammar.WebSearch);

SpeechRecognitionUIResult result = await speech.RecognizeWithUIAsync();

MessageBox.Show(result.RecognitionResult.Text);

}

Speech Recognition in Windows Phone 8 - Built In and Phrase List Grammars

How to use Speech Recognition in Windows Phone 8 with Phrase List Grammars?

The Phrase List grammar lets the developers to add the custom grammars to the speech recognition. Multiple list grammars can be added via the AddGrammarFromList method. Note that when the grammar set contains built-in dictation grammar, it cannot contain other grammars like phrase list grammars etc.

async private void AddSpeech()

{

SpeechRecognizerUI speech = new SpeechRecognizerUI();

List<string> ListGrammars = new List<string>() { "BDotnet", "SQLBangalore", "ITPro" };

speech.Recognizer.Grammars.AddGrammarFromList("List Grammars", ListGrammars);

SpeechRecognitionUIResult result = await speech.RecognizeWithUIAsync();

MessageBox.Show(result.RecognitionResult.Text);

}

Speech Recognition in Windows Phone 8 - Built In and Phrase List Grammars

How to enable or Disable Grammar List in Windows Phone when using the Phrase List Grammars?

You can enable or disable a particular Phrase List using the Key that is used when adding the Grammar from List. For example, in the below code snippet , we have added 2 phrase list to the grammar with the names Active and InActive. We can simple disable the Inactive one’s by setting the Enabled = false.

async private void AddSpeech()

{

SpeechRecognizerUI speech = new SpeechRecognizerUI();

List<string> ListGrammars1 = new List<string>() { "BDotnet", "SQLBangalore", "ITPro" };

speech.Recognizer.Grammars.AddGrammarFromList("Active", ListGrammars1);

List<string> ListGrammars2 = new List<string>() { "Test User Group" };

speech.Recognizer.Grammars.AddGrammarFromList("InActive", ListGrammars2);

// Disable the InActive Grammar

speech.Recognizer.Grammars["InActive"].Enabled = false;

SpeechRecognitionUIResult result = await speech.RecognizeWithUIAsync();

MessageBox.Show(result.RecognitionResult.Text);

}

    1 Comment

  1. Harshal
    October 21, 2013
    Reply

    Great article! Please a sample app I developed regarding same topic earlier this year. The most important feature of Windows Phone 8 is that it supports the offline speech recognition when phrase list or the XML grammars are provided.

Leave a Reply

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...