C#Grammar& GrammarBuilder''规则引用未在此语法中定义

时间:2014-09-26 23:56:20

标签: c# voice-recognition speech

我试图重用一些单词,但是当我尝试重用一个Choices列表时,我收到了这个错误。除非我没有。 "''规则参考未在此语法中定义。"

我有两个程序:

List<string> words = new List<string>();
foreach (string line in File.ReadLines("wordsEnTest.txt"))
{
    if (line.Length > 0)
    {
        words.Add(line);
    }
    else { }
}
Choices omniChoices = new Choices(words.ToArray());
GrammarBuilder omniBuild = new GrammarBuilder(omniChoices);
for (int i = 1; i < 3; i++)
{
   omniBuild.Append(omniChoices, 0, 1);
}
Grammar grammar = new Grammar(omniBuild);
engine.LoadGrammar(grammar);

如果 i 转到 100 ,但是 3 ,则无效。这对我来说很奇怪。 我和#34;名词连词名词&#34;等模式有类似的问题。同样。 我不确定我忽视了什么。

e.g。

for (int i = 1; i < 100; i++)
{
   omniBuild.Append(omniChoices, 0, 1);
}

有效,但不是

for (int i = 1; i < 3; i++)
{
   omniBuild.Append(omniChoices, 0, 1);
}

阈值似乎是可选(0,1)选项中的四个。在此之上,它似乎并没有崩溃。或者,制作第一组选择0,1似乎也可以避免错误。

例外:

System.FormatException was unhandled
  HResult=-2146233033
  Message='' rule reference not defined in this grammar.
  Source=System.Speech
  StackTrace:
       at System.Speech.Internal.SrgsCompiler.GrammarElement.System.Speech.Internal.SrgsParser.IElement.PostParse(IElement parent)
       at System.Speech.Recognition.GrammarBuilder.InternalGrammarBuilder.CreateElement(IElementFactory elementFactory, IElement parent, IRule rule, IdentifierCollection ruleIds)
       at System.Speech.Recognition.GrammarBuilder.CreateGrammar(IElementFactory elementFactory)
       at System.Speech.Recognition.GrammarBuilder.Compile(Stream stream)
       at System.Speech.Recognition.Grammar.LoadCfg(Boolean isImportedGrammar, Boolean stgInit)
       at System.Speech.Recognition.Grammar.LoadAndCompileCfgData(Boolean isImportedGrammar, Boolean stgInit)
       at System.Speech.Recognition.Grammar.InitialGrammarLoad(String ruleName, Object[] parameters, Boolean isImportedGrammar)
       at System.Speech.Recognition.Grammar..ctor(GrammarBuilder builder)
       at VAI.Program.LoadWords() in C:\Users\Corbin\Desktop\VAI\VAI\Program.cs:line 71
       at VAI.Program.Main(String[] args) in C:\Users\Corbin\Desktop\VAI\VAI\Program.cs:line 34
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

0 个答案:

没有答案