我正在通过计算器项目学习C#,并且正在尝试添加一个可以将语音识别为计算器输入的很酷的功能。 System.Speech.Recognition库允许我使用一些基本的if语句代码轻松地为数字0-9添加语法选择。但是,我希望它能够识别用户可以说出的所有可能的数字组合...这是什么最好的方法,而不必将每个可能的数字组合作为句子/字符串进行编码(例如“五百三十”七千四百二十二“)?
这是我到目前为止所拥有的:
private void buttonListen_Click(object sender, EventArgs e)
{
SpeechRecognitionEngine speechRecognize = new SpeechRecognitionEngine();
Choices ones = new Choices();
ones.Add(new string[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" });
Grammar calculatorGrammerOnes = new Grammar(new GrammarBuilder(ones));
try
{
speechRecognize.RequestRecognizerUpdate();
speechRecognize.LoadGrammar(calculatorGrammerOnes);
speechRecognize.SpeechRecognized += speechRecognize_SpeechRecognized;
speechRecognize.SetInputToDefaultAudioDevice();
speechRecognize.RecognizeAsync(RecognizeMode.Multiple);
}
catch
{
return;
}
}
private void speechRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "one")
{
//Insert "1" as the operand
}
else if (e.Result.Text == "two")
{
//Insert "2" as the operand
}
etc...
}
答案 0 :(得分:0)
那将是非常复杂的
e.g。 “五十三万七千四百二十二”,
如果在同一场景中,则提供输入语音:
“五十三万七千四百二十二”您的算法无法找到结果。
如果输入如下:
会更容易例如。 “五三七零..等等”