I'm learning C# through a calculator project, and am trying to add a cool feature that can recognize voice as calculator input. The System.Speech.Recognition library has allowed me to easily add grammar choices for numbers 0-9 with some basic if statement code. However, I want it to be able to recognize all possible combinations of numbers that a user could say...what's the best approach for this without having to hand code every possible combination of numbers as a sentence/string (e.g. "five hundred thirty seven thousand four hundred twenty two")?
Here's what I have so far:
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...
}