我正在使用语音识别语法规范(SRGS)命名空间开发一个C#.net应用程序。我喜欢捕捉外卡词。我看过一些使用GrammarBuilder捕获通配符的例子,但我使用的是SRGS命名空间。我找不到使用这个SRGS命名空间捕获的任何方法。
我编写了以下代码来捕获通配符。下面的代码应该识别像"执行E080755事件编号的报告调用统计信息:
SrgsOneOf reportsList = new SrgsOneOf();
reportsList.Add(new SrgsItem("Call Statistics"));
SrgsRule reportName = new SrgsRule("ReportName");
reportName.Add(reportsList);
reportName.Scope = SrgsRuleScope.Public;
SrgsRule executeReportRule = new SrgsRule("ExecuteReport");
SrgsItem executeReportWord = new SrgsItem("Execute report");
executeReportRule.Scope = SrgsRuleScope.Public;
SrgsItem forWord = new SrgsItem("for");
SrgsRule wildCardRule = new SrgsRule("WildCardRule");
wildCardRule.Scope = SrgsRuleScope.Public;
wildCardRule.Add(SrgsRuleRef.Garbage);
SrgsRuleRef wildCardRuleref = new SrgsRuleRef(wildCardRule, "WildCardWord");
SrgsItem eventNumberWord = new SrgsItem("event number");
executeReportRule.Add(executeReportWord);
executeReportRule.Add(new SrgsRuleRef(reportName, "ReportName"));
executeReportRule.Add(forWord);
executeReportRule.Add(wildCardRuleref);
executeReportRule.Add(eventNumberWord);
SrgsDocument document = new SrgsDocument();
document.Rules.Add(new SrgsRule[] { reportName, executeReportRule, wildCardRule });
document.Root = executeReportRule;
Grammar grammar = new Grammar(document, "ExecuteReport");
// Write the completed grammar to an XML-format SRGS grammar file.
System.Xml.XmlWriter writer =
System.Xml.XmlWriter.Create("c:\\Temp\\EventNumberGrammar.grxml");
document.WriteSrgs(writer);
writer.Close();
尝试使用" WildCardWord"捕获通配符。 semanti钥匙。但我只能得到" ..."而不是原始的口语。
谢谢, Vamshi Epuri