我的问题是如何加载使用他们在 MSDN 文档中列出的标签的语法文件?我想使用 MSDN 中标题语法格式标签 (SAPI 5.3) 下记录的格式标签。
http://msdn.microsoft.com/en-us/library/ms723634(VS.85).aspx
它在那里列出了 DEFINE、LIST、OPT 等标签。但是,每当我尝试在 Grammar.xml 文件中使用这些标签时,我都会收到一条错误消息,指出不支持该标签。
如果使用仅使用标签 one-of、item 等的语法文件,则在 MSDN 中列出;语法文件加载。
http://msdn.microsoft.com/en-us/library/ms870140.aspx
我知道这可能很简单,但我似乎无法弄清楚......
语法文件...有效
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="en-US" version="1.0" root="command">
<rule id="command" scope="public">
<one-of>
<item>nail</item>
<item>hammer</item>
<item>saw</item>
</one-of>
</rule>
</grammar>
代码清单-------------------
public Form1()
{
InitializeComponent();
// set up the recognizer
_speechRecognizer = new SpeechRecognizer();
_speechRecognizer.Enabled = false;
_speechRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_speechRecognizer_SpeechRecognized);
// set up the command and control grammar
Grammar commandGrammar = new Grammar(@"grammar.xml");
commandGrammar.Name = "main command grammar";
commandGrammar.Enabled = true;
// activate the command grammer
_speechRecognizer.LoadGrammar(commandGrammar);
_speechRecognizer.Enabled = true;
}