How to Use SpeechRecognizer in Windows Phone App using C#?

Published on October 1, 2013 by abundantcode

Filed under Windows Phone

Last modified October 1, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 5201 times

Below is a sample code snippet demonstrating how to use the SpeechRecognizerUI in your Windows Phone app using C#.

Note that by default the speech recognizer API uses the default speech grammar accessed via the Microsoft cloud service and hence requires the network connection to be available for the below code snippet to work.

How to Use SpeechRecognizer in Windows Phone App using C#?

async private void Button_Click_1(object sender, RoutedEventArgs e)

{

SpeechRecognizerUI speech = new SpeechRecognizerUI();

await speech.Recognizer.PreloadGrammarsAsync();

SpeechRecognitionUIResult result = await speech.RecognizeWithUIAsync();

if (result.ResultStatus == SpeechRecognitionUIStatus.Succeeded)

{

MessageBox.Show(result.RecognitionResult.Text);

}

}

When the speech.RecognizeWithUIAsync is called, the SDK provides a dialog which will prompt the user to speak.

Once the SpeechRecognitionUIResult returns the SpeechRecognitionUIStatus.Succeeded, the RecognitionResult.Text will contain the text that was spoken.

1 Comment

  1. Nasir

    Sir I has a problem
    when i run the same code in my project (windows phone 8.1) it redirects me to App.xaml.cs class and points to

    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
    if (Debugger.IsAttached)
    {
    // An unhandled exception has occurred; break into the debugger
    Debugger.Break(); // this line
    }
    }
    can you please help me out ?
    thanks

    October 30, 2014 - 11:05 pm – Reply

Leave a Comment


x

You might be Interested in these Posts

How to download a file from a URL using C#?

You can use the WebClient class in C# to download a file. How to download a file from a URL using C...

How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below. String[] st...

C++ Program to display "Hello, World!"

Problem Write a program in C++ to display "Hello, World!" on the screen. C++ Program to...