C#UWP SpeechRecognizer问题(C# UWP SpeechRecognizer problems)

编程入门 行业动态 更新时间:2024-10-25 15:20:38
C#UWP SpeechRecognizer问题(C# UWP SpeechRecognizer problems)

我正在开发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; } }); }

I am developing UWP and want to use SpeechRecognizer. It should react only to words "Next" and "Back". But often, it recognizes "NExt" as "Back". My code is below. How to solve this?

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(); }

Here is 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; } }); }

最满意答案

不幸的是,你已经遇到了使用语音识别的困难,有时候它无法准确识别出你所说的内容。

我建议的一件事就是利用您获得的置信水平作为结果的一部分。 使用置信度,您可以决定是否要接受结果或尝试要求用户重复他们所说的内容。

Unfortunately you've hit the struggles of working with speech recognition and there will be times when it can't recognize exactly what you've said.

One of the things I would recommend is taking advantage of the the Confidence level which you get as part of the result. Using the confidence, you can decide whether you want to accept the result or attempt to ask the user to repeat what they said.

更多推荐

本文发布于:2023-07-31 01:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UWP   SpeechRecognizer   problems

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!