From where do I have to accept the speech recognition policy?
This is the code
publicasyncvoiddisplay(){SpeechRecognizerrec=newSpeechRecognizer();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);SpeechRecognitionResultresult=await rec.RecognizeAsync();// Error hereif(result!=null){textBlock.Text=result.Text;}}
There's a setting underSpeech, Inking, and Typing.To get there,
1. First, go to Settings and click "Time & Language".
2. Select the "Speech" option.
3. Go to the "Speech, Inking & Typing privacy settings".
4. Then, click on the pop-up and turn the setting ON.
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.COMExceptione)when(e.HResult==unchecked((int)0x80045509))//privacyPolicyHResult//The speech privacy policy was not accepted prior to attempting a speech recognition.{ContentDialogDialog=newContentDialog(){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(awaitDialog.ShowAsync()==ContentDialogResult.Secondary){conststringuriToLaunch="ms-settings:privacy-speechtyping";//"http://stackoverflow.com/questions/42391526/exception-the-speech-privacy-policy-" +//"was-not-accepted-prior-to-attempting-a-spee/43083877#43083877";varuri=newUri(uriToLaunch);varsuccess=awaitWindows.System.Launcher.LaunchUriAsync(uri);if(!success)awaitnewContentDialog{Title="Oops! Something went wrong...",Content="The settings app could not be opened.",PrimaryButtonText="Shut your mouth up!"}.ShowAsync();}}