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.
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