Semantic Interpretation in SRGS XML grammar

杀马特。学长 韩版系。学妹 提交于 2019-12-12 04:46:05

问题


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"


回答1:


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());
}



回答2:


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).



来源:https://stackoverflow.com/questions/8004390/semantic-interpretation-in-srgs-xml-grammar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!