UWP应用使用语音识别功能运行报错如何解决
UWP语音搜索应用开发运行异常求助
我正在开发一款集成了语音搜索功能的UWP应用,参考了以下两段公开代码,但运行时均抛出错误,自行检索网络资源未找到对应解决方案,恳请各位提供可行的解决方法。
参考代码
代码段1(来源:Windows官方博客语音识别相关内容)
var speechRecognizer = new Windows.Media.SpeechRecognition.SpeechRecognizer(); //speechRecognizer.RecognitionQualityDegrading += speechRecognizer_RecognitionQualityDegrading; // Add a web search grammar to the recognizer. var webSearchGrammar = new Windows.Media.SpeechRecognition.SpeechRecognitionTopicConstraint(Windows.Media.SpeechRecognition.SpeechRecognitionScenario.WebSearch, "webSearch"); speechRecognizer.UIOptions.AudiblePrompt = "Say what you want to search for..."; speechRecognizer.UIOptions.ExampleText = @"Ex. 'weather for London'"; speechRecognizer.Constraints.Add(webSearchGrammar); // Compile the constraint. await speechRecognizer.CompileConstraintsAsync(); // Start recognition. Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = await speechRecognizer.RecognizeWithUIAsync(); await speechRecognizer.RecognizeWithUIAsync(); // Do something with the recognition result. var messageDialog = new Windows.UI.Popups.MessageDialog(speechRecognitionResult.Text, "Text spoken"); await messageDialog.ShowAsync();
代码段2(来源:第三方技术站点)
async void Button_Click_2(object sender, RoutedEventArgs e) { this.recognizer = new SpeechRecognizer(); await this.recognizer.CompileConstraintsAsync(); this.recognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(5); this.recognizer.Timeouts.EndSilenceTimeout = TimeSpan.FromSeconds(20); this.recognizer.UIOptions.AudiblePrompt = "Say whatever you like, I'm listening"; this.recognizer.UIOptions.ExampleText = "The quick brown fox jumps over the lazy dog"; this.recognizer.UIOptions.ShowConfirmation = true; this.recognizer.UIOptions.IsReadBackEnabled = true; this.recognizer.Timeouts.BabbleTimeout = TimeSpan.FromSeconds(5); var result = await this.recognizer.RecognizeWithUIAsync(); if (result != null) { StringBuilder builder = new StringBuilder(); builder.AppendLine( $"I have {result.Confidence} confidence that you said [{result.Text}] " + $"and it took {result.PhraseDuration.TotalSeconds} seconds to say it " + $"starting at {result.PhraseStartTime:g}"); var alternates = result.GetAlternates(10); builder.AppendLine( $"There were {alternates?.Count} alternates - listed below (if any)"); if (alternates != null) { foreach (var alternate in alternates) { builder.AppendLine( $"Alternate {alternate.Confidence} confident you said [{alternate.Text}]"); } } this.txtResults.Text = builder.ToString(); } } SpeechRecognizer recognizer;
错误截图

内容的提问来源于stack exchange,提问作者Levi Israel
相关产品推荐
相关产品推荐

