I have got the following XML grammar to detect a number like 1000 or 2200 etc.
<rule id="rule1" scope="public">
<one-of>
<item>1</item>
<item>2</item>
<item>3</item>
</one-of>
<ruleref uri="#rule2"/>
</rule>
<rule id="rule2" scope="public">
<one-of>
<item>thousand<tag>out="000";</tag></item>
<item>thousand 100<tag>out=100;</tag></item>
<item>thousand 200<tag>out=200;</tag></item>
</one-of>
</rule>
However when the user says for example 2100, I get "2 thousand 100" instead of 2100. It seems like the out= part is not working. I have seen several examples online and don't know if there is something else I need to add to make this work. I am using tag-format="semantics/1.0"
The way I solved this was to use just one rule and use properties like out.start, out.end and then concatenate them.
<rule id="rule1" scope="public">
<one-of>
<item>1<tag>out.start="1";</tag></item>
<item>2<tag>out.start="2";</tag></item>
<item>3<tag>out.start="3";</tag></item>
</one-of>
<one-of>
<item>thousand<tag>out.end="000";</tag></item>
<item>thousand 100<tag>out.end="100";</tag></item>
<item>thousand 200<tag>out.end="200";</tag></item>
</one-of>
<tag>out=out.start+out.end;</tag>
</rule>
To retrieve the semantic value from C# you can use something like
private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show(e.Results.Semantics.Value.ToString());
}
The Microsoft Speech SDK comes with a sample SRGS that can handle numbers quite well. For instance the "Cardinal" rule can handle numbers up to 1,000,000. It's available in a variety of languages in the Samples directory (e.g. C:\Program Files\Microsoft SDKs\Speech\v11.0\Samples\Sample Grammars\en-US.grxml).