SpeechRecognizer Class and Exception 0x80045509

by Kevin June 26, 2013 22:40

In my game, Stroop Effect, I used the SpeechRecognizer class instead of the SpeechRecognizerUI class, because I needed a custom UI without the popup prompt. I was getting an exception that I didn't recognize while using the emulator, but the game worked fine on my Lumia 920, so I submitted it to beat the DVLUP Color Confusion challenge deadline. My game failed certification, because the tester had never used speech on the test device and he received an exception code of 0x80045509.

Speech Recognition Setting Speech Privacy Policy Prompt

While searching for the error code, I found that it was a speech privacy policy error, because the non-UI SpeechRecognizer class does not prompt the user if speech recognition is not enabled in the phone's settings. I decided to save a boolean setting to track whether speech is enabled and prompt the user using the SpeechRecognizerUI class in the main page when they first start a game. Once they reply yes to the speech prompt, I set the boolean setting to true and navigate the user to the game page. Be sure to include the 0x80045509 exception check whenever you use the SpeechRecognizer class, because the user may navigate back to the page after disabling speech recognition in the phone's settings.

Here is an example of the exception handling.

catch (Exception ex)
    const int privacyPolicyHResult = unchecked((int)0x80045509);
    const int networkNotAvailable = unchecked((int)0x80045504);

    if (ex.HResult == privacyPolicyHResult)
        // User has not accepted the speech privacy policy
    else if (ex.HResult == networkNotAvailable)
        this.Dispatcher.BeginInvoke(delegate { MessageBox.Show("Speech " +
            "recognition requires an active data connection. Please check " +
            "the data connection on your phone and try again.", "Error",
            MessageBoxButton.OK); });
        this.Dispatcher.BeginInvoke(delegate { MessageBox.Show(ex.Message); });

In Stroop Effect, I prompt the user on the game page only if the error occurs.

private async void PromptForSpeechRecognitionPermission()
    SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
    SpeechRecognizerUI speechRecognizerUI = new SpeechRecognizerUI();

    // Prompt the user using speech synthesis
    await speechSynthesizer.SpeakTextAsync("Please tap accept in the " +
        "following dialog box to enable speech recognition on your " +
        "phone, then say something to make sure the game can hear you.");

    // Required to get user's speech consent
    speechRecognizerUI.Settings.ExampleText = "Ex. \"Red\"";
    speechRecognizerUI.Settings.ListenText = "Listening...";
    speechRecognizerUI.Settings.ReadoutEnabled = true;
    speechRecognizerUI.Settings.ShowConfirmation = true;
    var result = await speechRecognizerUI.RecognizeWithUIAsync();

Tags: , , ,

Windows Phone

Comments (6) -

joe healy
joe healy United States
6/27/2013 8:52:32 AM #

great post


Kevin United States
6/27/2013 9:04:13 AM #

Thanks, Joe. If it helps at least one other developer, then it was worth it. Now I need to fix Ask a Wookie, because it has the same problem, even though it made it through testing.


Jay Kimble
Jay Kimble United States
7/9/2013 1:35:13 PM #

Good post.. You are reminding me that I need to blog about a weird situation I ran into with a Dev Device that could happen in the wild... Basically speech can be downloaded but not for your region (you get a weird error message).


Kevin United States
7/9/2013 1:43:56 PM #

Thanks. I'm waiting to see how many people complain about me only supporting English. I need to start adding alternate languages to some of my apps.


Rozy India
10/14/2013 11:19:42 PM #

I don't want to use speech UI. I require a functionality in which respective code execute automatically by recognize a speech but without speech UI. kindly suggest.


Kevin United States
12/4/2013 2:22:56 PM #

You can't make the app listen for speech without using the speech UI.


Pingbacks and trackbacks (1)+

Add comment

  Country flag

  • Comment
  • Preview

About the author


I work on .NET development by day; Windows PC & Windows Phone development by night.

Month List