Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

Do you want to add a functionality in your Windows Phone device which can actually listen to users voice or commands? Do you want the app to record the speech or convert the speech into a text string which you can save as a document?

 

Okay, this blog post will cover that topic for you today. Here we will discuss how to use the API to enable the speech recognition in your WP device.

 

The sealed class named “SpeechRecognizerUI”, comes under the namespace “Windows.Phone.Speech.Recognition” enables your Windows Phone device to enable speech recognition functionality. You can control whether to display a graphical user interface or not by modifying few properties.

 

 

The class provides a property named “Settings” of type “SpeechRecognizerUISettings”, which you can modify to show or hide the following items during speech recognition:

    • ExampleText - The example text that is shown on the Listening page.
    • ListenText - The heading text that displays on the Listening page, above the example text.
    • ReadoutEnabled - Indicates if the successfully recognized text will be spoken back to the user on the confirmation page.
    • ShowConfirmation - Indicates if a confirmation page is shown to the user after speech recognition is successful.

 

 

Speech Recognition with UI

The method “RecognizeWithUIAsync()” begins a speech recognition session for a SpeechRecognizerUI object and returns the result of the speech recognition session that was initiated by that SpeechRecognizerUI object. If you want to show the default speech recognition UI in the screen, call this method which will show in the screen as shown below:

 

Windows Phone 8 "SpeechRecognizerUI" started listening to users voiceWindows Phone 8 "SpeechRecognizerUI" started recognizing the users voiceWindows Phone 8 "SpeechRecognizerUI" returns the text recognized from users voice

 

The first screenshot is where the phone device will start listening to the users speech, then it starts recognizing the voice and returns an equivalent text string to the caller which we displayed by calling the MessageBox.Show() method. By default, it uses the current grammar settings file from the device.

 

 

Here is the code snippet of what we demonstrated above:

 

private async void StartListening()
{
    // Create an instance of SpeechRecognizerUI.
    var speechRecognizerUI = new SpeechRecognizerUI();
    speechRecognizerUI.Settings.ReadoutEnabled = false;
    speechRecognizerUI.Settings.ShowConfirmation = false;

    // Start recognition (load the dictation grammar by default).
    var recoResult = await speechRecognizerUI.RecognizeWithUIAsync();
    MessageBox.Show(recoResult.RecognitionResult.Text);
}

 

If you set “speechRecognizerUI.Settings.ShowConfirmation = true” above, you will see a confirmation screen like the first image shown below. In case it misses to recognize, it shows a message “Sorry, didn’t catch that” in the screen as shown in the second image below:

 

wp_ss_20131003_0004wp_ss_20131003_0005

 

 

Speech Recognition without UI

In case you don’t want to show any of the above UI in the screen and want to go with your own custom UI (like the one shown here. Did you recognize the character of the girl here?) to recognize users voice/speech and convert them to a recorded message to play or a text message string to save as a document file, then you need to use some other API call of the SpeechRecognizerUI class.

 

Call to “speechRecognizerUI.Recognizer.RecognizeAsync()” asynchronous method will help you to recognize and capture voice silently, without showing the Speech Recognition UI. The method returns the result of the speech recognition session that was initiated by the SpeechRecognizer object.

 

 

Here is the code snippet of the same:

 

private async void StartListening()
{
    // Create an instance of SpeechRecognizerUI.
    var speechRecognizerUI = new SpeechRecognizerUI();
    speechRecognizerUI.Settings.ReadoutEnabled = false;
    speechRecognizerUI.Settings.ShowConfirmation = false;

    // Start recognition (load the dictation grammar by default).
    var recoResult = speechRecognizerUI.Recognizer.RecognizeAsync().GetResults();
    MessageBox.Show(recoResult.Text);
}

 

I hope the post was easy to read and helped you to learn how to capture speech recognition in Windows Phone 8 devices by writing a small piece of code. Now you will be able to use that quickly and easily in your phone applications. Check out the other properties like Grammars etc. part of the API.

 

Please drop a line below if you have any questions. I am also available on Twitter and Facebook. So, connect with me for any queries and to get regular technical and/or article updates.

 

Have a question? Or, a comment? Let's Discuss it below...

dhgate

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.