语音识别程序随机显示预定义的单词(在“ GramarBuilder()”中定义)以显示语法中不存在的那些已说出的单词
作者:互联网
我是C#的新手,我不确定是否在正确的论坛上写作.我正在构建简单的语音识别程序,该程序将语音命令作为输入,执行语音到文本的翻译,然后搜索与该文本匹配的视频.
I am using
grammarBuider()
and define my own grammar for more
accurate speech recognition. But the problem is: when any word that
doesn’t exit in grammar is spoken, the program starts
any displaying/writing existing word randomly which were defined in
grammar.
所以,
What I want is: If any word that doesn’t exist in my grammar
Grammarbuilder
is spoken, the program should not write any or any random word from grammar on screen. Instead, it should display a message to user i.e. “word you spoke doesn’t exist in program’s grammar OR no video found matching to your voice search”
谁能告诉我如何解决此问题?
这是我的代码.
public Form1()
{
InitializeComponent();
}
private void btnStart_Click(object sender, EventArgs e)
{
btnStart.Enabled = false;
btnStop.Enabled = true;
clist.Add(new string[] { "go away", "able", "active", "actual", "afraid", "busy", "casual" });
Grammar gr = new Grammar(new GrammarBuilder(clist));
try
{
sre.RequestRecognizerUpdate();
sre.LoadGrammar(gr);
sre.SpeechRecognized+= sre_SpeechRecognized;
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
textBoxContent.Text += e.Result.Text.ToString() + Environment.NewLine;
}
private void btnStop_Click(object sender, EventArgs e)
{
sre.RecognizeAsyncStop();
btnStart.Enabled = true;
btnStop.Enabled = false;
}
}
解决方法:
每个识别结果都有一个confidence score-正确识别短语的确定性的相对度量.无论您的置信度是高还是低,您的SpeechRecognitionEngine看起来都会引发SpeechRecognized事件,从而提供最佳匹配.识别语法中未包含的单词时,请尝试检查这些分数.如果我是对的,这就是问题所在,那么您可以使用以下选项:
>在sre_SpeechRecognized处检查e.Result.Confidence,如果分数太低,则向用户显示一条消息
>尝试为SpeechRecognitionEngine设置置信度阈值并处理SpeechRecognitionRejected事件. MSDN声称
If your application is using a SpeechRecognitionEngine instance, you can modify the confidence level at which speech input is accepted or rejected with one of the UpdateRecognizerSetting methods.
尝试调用SpeechRecognitionEngine.UpdateRecognizerSetting进行设置.我不知道此设置的确切名称,但是this outdated documentation指出它是“ CFGConfidenceRejectionThreshold”.
祝好运!
标签:speech-recognition,visual-studio-2017,c 来源: https://codeday.me/bug/20191108/2009812.html