I am trying to get a certain grammar working in my speech recognition.
My grammar definition is as follows:
<rule id="showFlight">
<example>Show me Alaska Airlines flight number 2117</example>
<example>Where is US Airways flight 45</example>
<item>
<one-of>
<item>show me</item>
<item>where is</item>
</one-of>
</item>
<item>
<ruleref uri="#airline" />
<tag>out.Carrier = rules.airline;</tag>
</item>
flight
<item repeat="0-1">number</item>
<item repeat="1-">
<ruleref uri="#digit" />
<tag>out.Number = rules.digit;</tag>
</item>
</rule>
My problem resides with the very last -- the digits. I define that 1-or-more digits can exist in the grammer, and this works. But when I go to extract the value in my OnSpeechRecognized callback, I only get the last digit spoken.
public override bool OnSpeechRecognized(object sender, Microsoft.Speech.Recognition.SpeechRecognizedEventArgs e)
{
String output = String.Format("Recognition Summary:\n" +
" Recognized phrase: {0}\n" +
" Confidence score {1}\n" +
" Grammar used: {2}\n",
e.Result.Text, e.Result.Confidence, e.Result.Grammar.Name);
Console.WriteLine(output);
// Display the semantic values in the recognition result.
Console.WriteLine(" Semantic results:");
//Console.WriteLine(e.Result.Semantics["Flight"].Value);
foreach (KeyValuePair<String, SemanticValue> child in e.Result.Semantics["ShowFlight"])
{
Console.WriteLine(" {0} is {1}",
child.Key, child.Value.Value ?? "null");
}
Console.WriteLine();
...
Or, more directly:
e.Result.Semantics["ShowFlight"]["Number"].Value.ToString()
If I say "two-one-one-seven", the only digit in ["Number"] is 7. Likewise, if I say "four-five" the only digit I get returned is 5.
How can I extract all the numbers that are spoken that are part of the flight number?
Also, is there a secret internal grammar I can load that will allow me to recognize both "four-five" and "fortyfive" easily?
You can simply replace the last 'item' element with the following:
<tag>out.Number = ""</tag>
<item repeat="1-">
<ruleref uri="#digit" />
<tag>out.Number += rules.digit;</tag>
</item>
This will concatenate all the recognized digits to out.Number
.
Regarding the second question, there is no such "secret internal grammar", unfortunately. You will have to code it yourself.