解释

2011-11-04 134 views
0

我有以下XML语法检测像1000或2200等解释

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

一批然而,当用户说,例如2100年,我获得“2000 100”,而不是2100年。似乎out =部分不起作用。我在网上看到了几个例子,不知道是否还有其他东西需要添加来完成这项工作。我正在使用tag-format =“semantics/1.0”

+0

这取决于你正在使用的引擎,不是吗?它可能不支持标签。你正在使用哪一个?同样为了完整性,我会在第二和第三种情况下添加引号。 –

+0

我在C#中使用SpeechRecognitionEngine来加载语法。我已经尝试过,没有引号。 – kr13

回答

2

我解决这个问题的方法是只使用一个规则并使用out.start,out.end等属性,然后将它们连接起来。

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

要检索C#您可以使用类似

private void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
{ 
    MessageBox.Show(e.Results.Semantics.Value.ToString()); 
} 
2

Microsoft Speech SDK附带了可以处理的数字相当不错的样本SRGS语义值。例如,“红衣主教”规则可以处理高达1,000,000的数字。它可以在Samples目录下以各种语言提供(例如C:\ Program Files \ Microsoft SDKs \ Speech \ v11.0 \ Samples \ Sample Grammars \ en-US.grxml)。