SRGS语法根据GrammarValidator有效,但LoadGrammar抛出异常? [英] SRGS grammar valid according to GrammarValidator, but LoadGrammar throws exception?

查看:55
本文介绍了SRGS语法根据GrammarValidator有效,但LoadGrammar抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Microsoft Speech Server(即.NET下的Microsoft.Speech.Recognition),并且我的公司提供了语法。 当我通过GrammarValidator.exe运行它时,它报告没有错误。 当我尝试将其加载到语音识别
引擎时,它会抛出一个声明存在循环引用的异常。


我的代码非常简单 - 相关部分看起来像这样。  grammar.grxml是顶级文件;可执行文件目录中有几个外部文件,由grammar.grxml引用。

 SpeechRecognitionEngine oSpeechRecognizer 
= new SpeechRecognitionEngine(new System.Globalization.CultureInfo( "的en-US"));
SrgsDocument oSrgsDocument = new SrgsDocument(" grammar.grxml");
string strCurrentDir
= System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly()。Location);
Uri uriBase = new Uri(@" file://" + strCurrentDir +" /");
语法g =新语法(oSrgsDocument,"rootRule",uriBase);
oSpeechRecognizer.LoadGrammar(g);


抛出System.InvalidOperationException,消息为"语法导入规则中的循环引用",这里是堆栈跟踪:$

 at Microsoft.Speech.Recognition.RecognizerBase.ThrowIfSapiErrorCode(SAPIErrorCodes errorCode)
at Microsoft.Speech.Recognition.MemoryGrammarContent.Load(SapiGrammar sapiGrammar,Boolean启用,
单一权重,Int32优先级)
at Microsoft.Speech.Recognition.GrammarContent.Load(SapiGrammar sapiGrammar)
at Microsoft.Speech.Recognition.Grammar.Load(SapiGrammar sapiGrammar,IRecognizerInternal recognition )Microsoft.Speech.Recognition.RecognizerBase.LoadGrammarIntoSapi(语法语法)
Microsoft.Speech.Recognition.RecognizerBase.LoadGrammar(语法语法) >异常中似乎没有任何其他有用的信息。


那么如何确定语法的问题是什么?&nbs磷;为什么没有GrammarValidator.exe报告此问题?



解决方案

错误表示在语法中有循环引用。子语法正在引用父语法。您可以通过删除循环引用来解决此问题。


I'm just starting to use Microsoft Speech Server (i.e. Microsoft.Speech.Recognition under .NET), and have a grammar supplied by my company.  When I run it through GrammarValidator.exe, it reports no errors.  When I try to load it into the speech-recognition engine, it throws an exception claiming that there are circular references.

My code is pretty simple -- the relevant part looks like this.  grammar.grxml is the top-level file; there are several external files in the executable directory, referred to by grammar.grxml .

SpeechRecognitionEngine oSpeechRecognizer
    = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
SrgsDocument oSrgsDocument = new SrgsDocument("grammar.grxml");
string strCurrentDir
    = System.IO.Path.GetDirectoryName (
        System.Reflection.Assembly.GetExecutingAssembly().Location);
Uri uriBase = new Uri(@"file://" + strCurrentDir + "/");
Grammar g = new Grammar(oSrgsDocument, "rootRule", uriBase);
oSpeechRecognizer.LoadGrammar(g);

A System.InvalidOperationException is thrown, the message is "Circular reference in import rules of grammars.", and here's the stack trace:

at Microsoft.Speech.Recognition.RecognizerBase.ThrowIfSapiErrorCode(SAPIErrorCodes errorCode)
at Microsoft.Speech.Recognition.MemoryGrammarContent.Load(SapiGrammar sapiGrammar, Boolean enabled,
    Single weight, Int32 priority)
at Microsoft.Speech.Recognition.GrammarContent.Load(SapiGrammar sapiGrammar)
at Microsoft.Speech.Recognition.Grammar.Load(SapiGrammar sapiGrammar, IRecognizerInternal recognizer)
at Microsoft.Speech.Recognition.RecognizerBase.LoadGrammarIntoSapi(Grammar grammar)
at Microsoft.Speech.Recognition.RecognizerBase.LoadGrammar(Grammar grammar)

There doesn't seem to be any other useful information in the exception.

So how do I determine what the problem with the grammar is?  And why didn't GrammarValidator.exe report this problem?


解决方案

The error indicates that there is a circular reference in the grammars. A parent grammar is being referenced by a child grammar. You can resolve the issue by removing the circular reference.


这篇关于SRGS语法根据GrammarValidator有效,但LoadGrammar抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆