我正在使用 C# 和 System.Speech.Recognition 来加载我定义的几个简单语法。当我说出与语法匹配的短语时,引擎会正确识别语法,置信度约为 0.95。
但是,当我说出语法中不存在的单词时(即使来自不同的语言或乱码),引擎会随机返回与语法的匹配项,其中随机文本从未发音过,但仍然具有很高的置信度,如 0.92。
我需要在 SpeechRecognitionEngine 对象或每个 Grammar 对象中设置一些内容来避免此问题吗?
最佳答案
我想我找到了一个适合我的解决方案,但如果存在的话,找到一个更优雅的解决方案仍然会很好:
我定义了听写语法和“占位符”。然后我加载语法并立即禁用它们。
using System.Speech.Recognition;
...
private DictationGrammar dictationGrammar;
private Grammar placeholderGrammar;
private List<Grammar> commands;
public void Initialize()
{
dictationGrammar = new DictationGrammar();
recognizer.LoadGrammarAsync(dictationGrammar);
var builder = new GrammarBuilder();
builder.Append("MYPLACEHOLDER");
placeholderGrammar = new Grammar(builder);
recognizer.LoadGrammarAsync(placeholderGrammar);
commands = new List<Grammar>();
foreach (var grammar in grammarManager.GetGrammars())
{
commands.Add(grammar);
grammar.Enabled = false;
recognizer.LoadGrammarAsync(grammar);
}
}
然后在 voiceRecognized 事件上,我放置了这样的逻辑:如果占位符被识别,则启用命令。如果识别到命令,则重新启用听写并禁用所有命令:
private async void speechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Grammar == placeholderGrammar)
{
//go to command mode
placeholderGrammar.Enabled = false;
dictationGrammar.Enabled = false;
foreach (var item in commands)
item.Enabled = true;
}
else if (commands.Any(x => e.Result.Grammar == x))
{
Do_something_with_recognized_command("!!");
//go back in normal mode
placeholderGrammar.Enabled = true;
dictationGrammar.Enabled = true;
}else {//this is dictation.. nothing to do}
}
关于c# - 为什么 Microsoft 语音识别系统会匹配语法,即使没有说出该语法的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43203524/