私の最初のUWPアプリケーションプロジェクトでは、音声認識を使用した小さなテストプログラムを構築したかったのです。私は、次のコードを思い付いたいくつかのチュートリアルを通じてSearchさらに後UnauthorizedAccessExceptionまたはUWPアプリケーション用にMicrofoneを有効にする方法
:
SpeechRecognitionResult speechRecognitionResult = await _recognizer.RecognizeWithUIAsync();
私は常に取得:
private async void initSpeechParts() {
try {
if (_recognizer == null) {
_recognizer = new SpeechRecognizer();
var lang= _recognizer.CurrentLanguage;
var functionGrammar = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.Dictation, "Functioncall");
_recognizer.UIOptions.AudiblePrompt = "Give me the name of a Function";
_recognizer.UIOptions.ExampleText = "Function A";
_recognizer.Constraints.Add(functionGrammar) ;
await _recognizer.CompileConstraintsAsync();
}
try {
// Start recognition.
SpeechRecognitionResult speechRecognitionResult = await _recognizer.RecognizeWithUIAsync();
var recognizedText = speechRecognitionResult.Text;
recognizedText = removetokens(recognizedText);
callTestfunction(recognizedText);
} catch (Exception ex2) {
var ee = ex2.Message;
throw;
}
} catch (Exception ex) {
//Check if user has approved the privacy policy
const uint HresultPrivacyStatementDeclined = 0x80045509;
if ((uint)ex.HResult == HresultPrivacyStatementDeclined)
{
var messageDialog = new Windows.UI.Popups.MessageDialog(
"You must accept the speech privacy policy to continue", "Speech Exception");
messageDialog.ShowAsync().GetResults();
}
}
}
このコードの私の現在の問題は、それが言うの行にということですUnauthorizedAccess例外。 Googleの一部の投稿を読んだ後、私のマイクで問題が発生している可能性があると考えました。だから私のアプリケーションのマイクを有効にすることができますか?