/// <summary> /// When activating the scenario, ensure we have permission from the user to access their microphone, and /// provide an appropriate path for the user to enable access to the microphone if they haven't /// given explicit permission for it. /// </summary> /// <param name="e">The navigation event details</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission(); if (permissionGained) { // Enable the recognition buttons. btnRecognizeWithUI.IsEnabled = true; btnRecognizeWithoutUI.IsEnabled = true; Language speechLanguage = SpeechRecognizer.SystemSpeechLanguage; speechContext = ResourceContext.GetForCurrentView(); speechContext.Languages = new string[] { speechLanguage.LanguageTag }; speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources"); PopulateLanguageDropdown(); await InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage); } else { resultTextBlock.Visibility = Visibility.Visible; resultTextBlock.Text = "Permission to access capture resources was not given by the user; please set the application setting in Settings->Privacy->Microphone."; btnRecognizeWithUI.IsEnabled = false; btnRecognizeWithoutUI.IsEnabled = false; cbLanguageSelection.IsEnabled = false; } }
/// <summary> /// Upon entering the scenario, ensure that we have permissions to use the Microphone. This may entail popping up /// a dialog to the user on Desktop systems. Only enable functionality once we've gained that permission in order to /// prevent errors from occurring when using the SpeechRecognizer. If speech is not a primary input mechanism, developers /// should consider disabling appropriate parts of the UI if the user does not have a recording device, or does not allow /// audio input. /// </summary> /// <param name="e">Unused navigation parameters</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; // Prompt the user for permission to access the microphone. This request will only happen // once, it will not re-prompt if the user rejects the permission. bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission(); if (permissionGained) { btnContinuousRecognize.IsEnabled = true; Language speechLanguage = SpeechRecognizer.SystemSpeechLanguage; string langTag = speechLanguage.LanguageTag; speechContext = ResourceContext.GetForCurrentView(); speechContext.Languages = new string[] { langTag }; speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources"); PopulateLanguageDropdown(); // Initialize the recognizer. Since the recognizer is disposed on scenario exit, we need to make sure we re-initialize it on scenario // entrance, as the xaml page may not get destroyed between openings of the scenario. await InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage); } else { resultTextBlock.Text = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone."; btnContinuousRecognize.IsEnabled = false; cbLanguageSelection.IsEnabled = false; } }
/// <summary> /// Upon entering the scenario, ensure that we have permissions to use the Microphone. This may entail popping up /// a dialog to the user on Desktop systems. Only enable functionality once we've gained that permission in order to /// prevent errors from occurring when using the SpeechRecognizer. If speech is not a primary input mechanism, developers /// should consider disabling appropriate parts of the UI if the user does not have a recording device, or does not allow /// audio input. /// </summary> /// <param name="e">Unused navigation parameters</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; // Prompt the user for permission to access the microphone. This request will only happen // once, it will not re-prompt if the user rejects the permission. bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission(); if (permissionGained) { btnContinuousRecognize.IsEnabled = true; // Initialize resource map to retrieve localized speech strings. Language speechLanguage = SpeechRecognizer.SystemSpeechLanguage; string langTag = speechLanguage.LanguageTag; speechContext = ResourceContext.GetForCurrentView(); speechContext.Languages = new string[] { langTag }; speechResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("LocalizationSpeechResources"); PopulateLanguageDropdown(); await InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage); } else { this.resultTextBlock.Visibility = Visibility.Visible; this.resultTextBlock.Text = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone."; btnContinuousRecognize.IsEnabled = false; cbLanguageSelection.IsEnabled = false; } }
/// <summary> /// Upon entering the scenario, ensure that we have permissions to use the Microphone. This may entail popping up /// a dialog to the user on Desktop systems. Only enable functionality once we've gained that permission in order to /// prevent errors from occurring when using the SpeechRecognizer. If speech is not a primary input mechanism, developers /// should consider disabling appropriate parts of the UI if the user does not have a recording device, or does not allow /// audio input. /// </summary> /// <param name="e">Unused navigation parameters</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; // Prompt the user for permission to access the microphone. This request will only happen // once, it will not re-prompt if the user rejects the permission. bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission(); if (permissionGained) { btnRecognize.IsEnabled = true; await InitializeRecognizer(); } else { resultTextBlock.Text = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone."; btnRecognize.IsEnabled = false; } }
/// <summary> /// Upon entering the scenario, ensure that we have permissions to use the Microphone. This may entail popping up /// a dialog to the user on Desktop systems. Only enable functionality once we've gained that permission in order to /// prevent errors from occurring when using the SpeechRecognizer. If speech is not a primary input mechanism, developers /// should consider disabling appropriate parts of the UI if the user does not have a recording device, or does not allow /// audio input. /// </summary> /// <param name="e">Unused navigation parameters</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { rootPage = MainPage.Current; // Prompt the user for permission to access the microphone. This request will only happen // once, it will not re-prompt if the user rejects the permission. bool permissionGained = await AudioCapturePermissions.RequestMicrophonePermission(); if (permissionGained) { btnContinuousRecognize.IsEnabled = true; PopulateLanguageDropdown(); await InitializeRecognizer(SpeechRecognizer.SystemSpeechLanguage); } else { this.dictationTextBox.Text = "Permission to access capture resources was not given by the user, reset the application setting in Settings->Privacy->Microphone."; btnContinuousRecognize.IsEnabled = false; cbLanguageSelection.IsEnabled = false; } }