我正在开发UWP,并想使用SpeechRecognizer。它应该仅对单词“ Next”和“ Back”作出反应。但通常,它会将“ NExt”识别为“后退”。我的代码如下。如何解决呢?
var defaultLanguage = SpeechRecognizer.SystemSpeechLanguage;
_speechRecognizer = new SpeechRecognizer(defaultLanguage);
_coreDispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
var constraintList = new SpeechRecognitionListConstraint(new List<string>() { "Next", "Back" });
_speechRecognizer.Constraints.Add(constraintList);
var result = await _speechRecognizer.CompileConstraintsAsync();
if (result.Status == SpeechRecognitionResultStatus.Success)
{
_speechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;
_speechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
await _speechRecognizer.ContinuousRecognitionSession.StartAsync();
}
这是ResultGeneratedEvent:
private async void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
{
{
await _coreDispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
string command = args.Result.Text;
Messenger.Default.Send(new VoiceReactMessage(command));
switch (command)
{
case "Next":
SetHorizontalOffset(-ItemsPanelRoot.ActualWidth);
break;
case "Back":
SetHorizontalOffset(ItemsPanelRoot.ActualWidth);
break;
}
});
}
不幸的是,您在使用语音识别方面遇到了很多困难,并且有时它无法准确识别您所说的内容。
我建议的一件事是利用作为结果一部分的置信度级别。使用置信度,您可以决定是要接受结果还是要要求用户重复他们说的话。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句