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

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.

%d bloggers like this: