我希望 UWP 中的语音识别即使应用程序未处于活动状态也能识别。
我目前有这些设置:
async void InitializeSpeechRecognizer()
{
SpeechRecognizer speechRecognizer = new SpeechRecognizer();
speechRecognizer.StateChanged += HandleSpeech_State;
speechRecognizer.ContinuousRecognitionSession.ResultGenerated += HandleSpeech;
StorageFile grammar = await Package.Current.InstalledLocation.GetFileAsync(@"Grammar.xml"); // file
SpeechRecognitionGrammarFileConstraint grammarContraint = new SpeechRecognitionGrammarFileConstraint(grammar);
speechRecognizer.Constraints.Add(grammarContraint);
SpeechRecognitionCompilationResult compilantResult = await speechRecognizer.CompileConstraintsAsync(); // compile grammar
if (compilantResult.Status == SpeechRecognitionResultStatus.Success)
await speechRecognizer.ContinuousRecognitionSession.StartAsync();
}
InitializeSpeechRecognizer 在 MainPage 中调用
当我激活应用程序时,我可以在调试窗口中看到状态变化。激活另一个应用程序后,没有任何反应:(
感谢您的任何想法!
您必须
使用 BackgroundWorker 线程才能使应用程序在不聚焦时工作。
backgroundWorker1.RunWorkerAsync(testFunction(;
https://msdn.microsoft.com/en-us/library/cc221403(v=vs.95(.aspx