Exception: The speech privacy policy was not accepted prior to attempting a speech recognition
Asked Answered
R

2

8

From where do I have to accept the speech recognition policy?

Here is the code

public async void display()
{
    SpeechRecognizer rec = new SpeechRecognizer();
    await rec.CompileConstraintsAsync();
    rec.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(5);
    rec.Timeouts.EndSilenceTimeout = TimeSpan.FromSeconds(20);
    rec.UIOptions.AudiblePrompt = "I am listening";
    rec.UIOptions.ShowConfirmation = true;
    rec.UIOptions.IsReadBackEnabled = true;
    rec.Timeouts.BabbleTimeout = TimeSpan.FromSeconds(5);
    SpeechRecognitionResult result = await rec.RecognizeAsync(); // Error here

    if (result!=null)
    {
        textBlock.Text= result.Text;
    }
}
Resound answered 22/2, 2017 at 12:28 Comment(1)
In addition to HappyPig's answer, you might need to address this error too: https://mcmap.net/q/1324923/-uwp-speech-recognitionHookup
P
15

It is a setting under Speech, Inking and Typing. First, go to Settings and click "Time & Language". Settings app Next, select "Speech" from the menu on the left.Select from the menu After that, press "Speech, inking & typing privacy settings".Go to the real setting Just press the button called "Get to know me". The setting Then, click the popup to turn the setting on. One more step After that, any software that uses the Speech Recognition API will work.

A helpful way to tell users to turn on would be...

catch (System.Runtime.InteropServices.COMException e) when (e.HResult == unchecked((int)0x80045509))
//privacyPolicyHResult
//The speech privacy policy was not accepted prior to attempting a speech recognition.
{
    ContentDialog Dialog = new ContentDialog()
    {
        Title = "The speech privacy policy was not accepted",
        Content = "You need to turn on a button called 'Get to know me'...",
        PrimaryButtonText = "Shut up",
        SecondaryButtonText = "Shut up and show me the setting"
    };
    if (await Dialog.ShowAsync() == ContentDialogResult.Secondary)
    {
        const string uriToLaunch = "ms-settings:privacy-speechtyping";
        //"https://mcmap.net/q/1275732/-exception-the-speech-privacy-policy-was-not-accepted-prior-to-attempting-a-speech-recognition" + 
        //"was-not-accepted-prior-to-attempting-a-spee/43083877#43083877";
        var uri = new Uri(uriToLaunch);

        var success = await Windows.System.Launcher.LaunchUriAsync(uri);

        if (!success) await new ContentDialog
        {
            Title = "Oops! Something went wrong...",
            Content = "The settings app could not be opened.",
            PrimaryButtonText = "Shut your mouth up!"
        }.ShowAsync();
    }
}

More ways to launch the Settings app

Peskoff answered 29/3, 2017 at 3:42 Comment(0)
R
0

Open this setting in ShellExecute as url "ms-settings:privacy-speech".

Ritualist answered 29/9, 2023 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.