TargetInvocationException在使用SemanticResultKey [英] TargetInvocationException when using SemanticResultKey

查看:284
本文介绍了TargetInvocationException在使用SemanticResultKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立我的语法接受多个号码。它有一个错误,当我重复数好像是说'21'。所以,我一直在降低我的code,以发现问题。我到了下面这段code的语法生成器:

 的String [] numberString = {一};
选择numberChoices =新的选择();

的for(int i = 0; I< numberString.Length;我++)
{
numberChoices.Add(新SemanticResultValue(numberString [I],numberString [I]));
}

GB [1] .Append(新SemanticResultKey(OP1,(GrammarBuilder)numberChoices),1,2);
 

现在,当我发音一对一它仍然给了我这个异常

,当我用Google搜索它,它说这是超出了我的code异常,我想知道这是Microsoft.Speech DLL中的错误或我失去了一些东西。

修改1:

我的code发挥各地,并取得认可是异步如下:

  sre.RecognizeAsync(RecognizeMode.Multiple);
 

而不是

  sre.Recognize();
 

现在,当我说'二十one'for例如它得到这个异​​常: 基地= {语义重复的关键OP1在规则根}

我知道这个问题是与语法,但我没做这重复了OP1。我在想什么?

解决方案

我最终通过识别分析它的文字由我自己 在

 无效sre_SpeechRecognized(对象发件人,SpeechRecognizedEventArgs E)
 

我分析识别字符串:

  e.Result
 

相反

  recoResult.Semantics [OP1。Value.ToString())
 

作为.Semantics对象抛出上述异常。

我真的想知道解决的办法,如果有人经历过与它

I want to build my grammar to accept multiple number. It has a bug when I repeat the number like saying 'twenty-one'. So I kept reducing my code to find the problem. I reached the following piece of code for the grammar builder:

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);

Now when I pronounce "one one" it still gives me this exception

Which when I googled for it, it states that this is an exception outside my code, I am wondering is this a bug in Microsoft.Speech dll or I am missing something

Edit 1:

I played around with the code, and made the recognition to be Async as follow:

sre.RecognizeAsync(RecognizeMode.Multiple);

instead of

sre.Recognize();

now when I say 'twenty-one'for example it gets this exception: base = {"Duplicated semantic key 'op1' in rule 'root."}

I know the problem is with the grammar, but I did made it repeated for the 'op1'. What am I missing ??

解决方案

I ended by using the text recognized to parse it by myself in

void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)

I parsed the string recognized:

e.Result

Instead of

recoResult.Semantics["op1"].Value.ToString())

as the .Semantics object throws the exception mentioned above.

I really want to know the solution, if anyone is experienced with it

这篇关于TargetInvocationException在使用SemanticResultKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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