C# UWP SpeechRecognizer 问题
C# UWP SpeechRecognizer problems
我正在开发 UWP 并想使用 SpeechRecognizer。它应该只对单词 "Next" 和 "Back" 做出反应。但通常,它会将 "NExt" 识别为 "Back"。我的代码如下。如何解决?
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;
}
});
}
不幸的是,您在使用语音识别方面遇到了困难,有时它无法准确识别您所说的内容。
我建议的其中一件事是利用作为结果一部分的 Confidence level。使用置信度,您可以决定是要接受结果还是尝试让用户重复他们所说的话。
我正在开发 UWP 并想使用 SpeechRecognizer。它应该只对单词 "Next" 和 "Back" 做出反应。但通常,它会将 "NExt" 识别为 "Back"。我的代码如下。如何解决?
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;
}
});
}
不幸的是,您在使用语音识别方面遇到了困难,有时它无法准确识别您所说的内容。
我建议的其中一件事是利用作为结果一部分的 Confidence level。使用置信度,您可以决定是要接受结果还是尝试让用户重复他们所说的话。