[英]c# speech recognition part of phrase - windows.speech
I am using Windows.Speech API What I am trying to do is get the system to recognize part of a phrase rather than look for the whole thing. 我正在使用Windows.Speech API,我要做的是让系统识别词组的一部分,而不是查找全部内容。 For instance, if I load the the string with: "How are you", it requires the user to say exactly, how are you.
例如,如果我用以下字符串加载字符串:“你好吗”,则要求用户确切说出你好。 ultimately, I would like Windows.Speech to recognize something like this too: "Hey How are you today".
最终,我希望Windows.Speech也能识别以下内容:“嘿,今天好吗”。
Here is what I currently have: 这是我目前拥有的:
//This is used for Building the recognizer engine.
Choices commands = new Choices();
commands.Add(new string[] { Question5,
Question1,Question3,Question2,Question4});
GrammarBuilder gBuilder = new GrammarBuilder();
gBuilder.Append(commands);
Grammar grammar = new Grammar(gBuilder);
//Loading the Grammar engine
recEngine.LoadGrammarAsync(grammar);
recEngine.SetInputToDefaultAudioDevice();
recEngine.SpeechRecognized += recEngine_SpeechRecognized;
Then for display: 然后显示:
void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == Question1)
{
richTextBox1.Text += "\nYou have Asked Question 1";
chkBoxQ1.Checked = true;
agentScore = agentScore + 1;
stopCussing = Response1;
Form2 responseForm = new Form2();
responseForm.Show();
Question1Answer = "Question Asked";
txtBoxAnswer1.Enabled = true;
}
else if (e.Result.Text == Question2)
{
richTextBox1.Text += "\nYou have now asked Question 2";
chkQuestion2.Checked = true;
stopCussing = Response2;
Form2 responseForm = new Form2();
responseForm.Show();
agentScore = agentScore + 1;
Question2Answer = "Question Asked";
txtAnswer2.Enabled = true;
}
else if (e.Result.Text == Question3)
{
richTextBox1.Text += "\nYou have now asked Question 3";
chkQuestion3.Checked = true;
stopCussing = Response3;
Form2 responseForm = new Form2();
responseForm.Show();
agentScore = agentScore + 1;
Question3Answer = "Question Asked";
txtAnswer3.Enabled = true;
}
else if (e.Result.Text == Question4)
{
richTextBox1.Text += "\nYou have now asked Question 4";
chkQuestion4.Checked = true;
stopCussing = Response4;
Form2 responseForm = new Form2();
responseForm.Show();
agentScore = agentScore + 1;
Question4Answer = "Question Asked";
txtAnswer4.Enabled = true;
}
else if (e.Result.Text == Question5)
{
richTextBox1.Text += "\nYou have now asked Question 5";
chkQuestion5.Checked = true;
stopCussing = Response5;
Form2 responseForm = new Form2();
responseForm.Show();
agentScore = agentScore + 1;
Question5Answer = "Question Asked";
txtAnswer5.Enabled = true;
}
Any Insight here would be great! 这里的任何见解都会很棒! FYI, I have thought of using cognitive services -- But if I can make windows.speech do what I need, I'd rather not rewrite.
仅供参考,我曾考虑过使用认知服务-但是,如果我可以使windows.speech满足我的需要,我宁愿不重写。
I'm going to answer my own question. 我要回答我自己的问题。 The comments here were helpful, but they didn't do the trick for partials.
此处的评论很有帮助,但并没有解决偏partial问题。 I actually found that if you add .contains, it will accept approximates - only caveat is that the statement being said has to start with the same word.
我实际上发现,如果添加.contains,它将接受近似值-唯一需要注意的是,要说的语句必须以相同的单词开头。 Example code below:
下面的示例代码:
void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text.Contains( Question1)) //This did the trick here
{
richTextBox1.Text += "\nYou have Asked Question 1";
questionCode = "Question1";
chkBoxQ1.Checked = true;
agentScore = agentScore + 1;
stopCussing = Response1;
//Form2 responseForm = new Form2();
//responseForm.Show();
FurtherResponse further = new FurtherResponse(questionCode, programcode);
further.Show();
Question1Answer = "Question Asked";
txtBoxAnswer1.Enabled = true;
}
else if (e.Result.Text.Contains(Question2))
{
richTextBox1.Text += "\nYou have now asked Question 2";
chkQuestion2.Checked = true;
stopCussing = Response2;
//Form2 responseForm = new Form2();
//responseForm.Show();
agentScore = agentScore + 1;
Question2Answer = "Question Asked";
txtAnswer2.Enabled = true;
questionCode = "Question2";
FurtherResponse further = new FurtherResponse(questionCode, programcode);
further.Show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.