2017-02-22 26 views
3

どこから音声認識ポリシーを受け入れる必要がありますか?ここで例外:音声認識を試行する前に音声プライバシーポリシーが受け入れられていません

それはスピーチ、インキングやタイピングの下に設定されたコード

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; 
    } 
} 

答えて

6

です。 まず、設定に行き、「時間&言語」をクリックしてください。 Settings app 次に、左側のメニューから[音声]を選択します。 Select from the menu その後、「音声、&入力プライバシー設定」を押してください。 Go to the real setting "Get me know to"というボタンを押してください。 The setting 次に、ポップアップをクリックして設定を有効にします。 One more step その後、音声認識APIを使用するすべてのソフトウェアが動作します。

だろうオンにユーザーに伝えるための便利な方法...

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"; 
     //"http://stackoverflow.com/questions/42391526/exception-the-speech-privacy-policy-" + 
     //"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