解釋

2011-11-04 37 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)。