为什么 Microsoft 语音识别系统匹配语法,即使没有说出该语法的单词?
Why is Microsoft Speech Recognition system matching grammars even though no word of that grammar has been said?
我正在使用 c# 和 System.Speech.Recognition 加载我定义的几个简单语法。当我说出与语法匹配的短语时,引擎以大约 0.95 的置信度正确识别语法。
但是当我发出甚至不在语法中的单词时(即使来自不同的语言或乱码),引擎会随机 returns 与语法匹配,随机文本从未发音并且仍然具有很高的信心,例如0.92.
我是否需要在 SpeechRecognitionEngine 对象或每个 Grammar 对象中设置一些东西来避免这个问题?
我想我找到了一个适合我的解决方案,但如果能找到一个更优雅的解决方案(如果存在的话)仍然会很好:
我定义了一个听写语法和一个"placeholder"。然后我加载我的语法并立即禁用它们。
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);
}
}
然后在 speechRecognized 事件上,我放置了如果识别了占位符则启用命令的逻辑。如果命令被识别,则重新启用听写并禁用所有命令:
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# 和 System.Speech.Recognition 加载我定义的几个简单语法。当我说出与语法匹配的短语时,引擎以大约 0.95 的置信度正确识别语法。
但是当我发出甚至不在语法中的单词时(即使来自不同的语言或乱码),引擎会随机 returns 与语法匹配,随机文本从未发音并且仍然具有很高的信心,例如0.92.
我是否需要在 SpeechRecognitionEngine 对象或每个 Grammar 对象中设置一些东西来避免这个问题?
我想我找到了一个适合我的解决方案,但如果能找到一个更优雅的解决方案(如果存在的话)仍然会很好:
我定义了一个听写语法和一个"placeholder"。然后我加载我的语法并立即禁用它们。
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);
}
}
然后在 speechRecognized 事件上,我放置了如果识别了占位符则启用命令的逻辑。如果命令被识别,则重新启用听写并禁用所有命令:
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}
}