使用 SemanticResultKey 时出现 TargetInvocationException
TargetInvocationException when using SemanticResultKey
我想构建我的语法来接受多个数字。当我重复 'twenty-one' 之类的数字时,它有一个错误。所以我不断地减少我的代码来找到问题。我为语法构建器找到了以下代码:
string[] numberString = { "one" };
Choices numberChoices = new Choices();
for (int i = 0; i < numberString.Length; i++)
{
numberChoices.Add(new SemanticResultValue(numberString[i], numberString[i]));
}
gb[1].Append(new SemanticResultKey("op1", (GrammarBuilder)numberChoices), 1, 2);
现在当我发音 "one one" 时它仍然给我这个例外
当我用谷歌搜索时,它指出这是我代码之外的异常,我想知道这是 Microsoft.Speech dll 中的错误还是我遗漏了什么
编辑 1:
我玩弄了代码,并将识别设为异步如下:
sre.RecognizeAsync(RecognizeMode.Multiple);
而不是
sre.Recognize();
现在当我说 'twenty-one'例如它得到这个例外:
基数 = {"Duplicated semantic key 'op1' in rule 'root."}
我知道问题出在语法上,但我确实为 'op1' 重复了一遍。我错过了什么??
最后我用识别出来的文字自己解析
在
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
我解析识别出的字符串:
e.Result
而不是
recoResult.Semantics["op1"].Value.ToString())
因为 .Semantics 对象抛出上述异常。
我真的很想知道解决方案,如果有人对此有经验的话
我想构建我的语法来接受多个数字。当我重复 'twenty-one' 之类的数字时,它有一个错误。所以我不断地减少我的代码来找到问题。我为语法构建器找到了以下代码:
string[] numberString = { "one" };
Choices numberChoices = new Choices();
for (int i = 0; i < numberString.Length; i++)
{
numberChoices.Add(new SemanticResultValue(numberString[i], numberString[i]));
}
gb[1].Append(new SemanticResultKey("op1", (GrammarBuilder)numberChoices), 1, 2);
现在当我发音 "one one" 时它仍然给我这个例外
当我用谷歌搜索时,它指出这是我代码之外的异常,我想知道这是 Microsoft.Speech dll 中的错误还是我遗漏了什么
编辑 1:
我玩弄了代码,并将识别设为异步如下:
sre.RecognizeAsync(RecognizeMode.Multiple);
而不是
sre.Recognize();
现在当我说 'twenty-one'例如它得到这个例外: 基数 = {"Duplicated semantic key 'op1' in rule 'root."}
我知道问题出在语法上,但我确实为 'op1' 重复了一遍。我错过了什么??
最后我用识别出来的文字自己解析 在
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
我解析识别出的字符串:
e.Result
而不是
recoResult.Semantics["op1"].Value.ToString())
因为 .Semantics 对象抛出上述异常。
我真的很想知道解决方案,如果有人对此有经验的话