Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TargetInvocationException when using SemanticResultKey

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

enter image description here

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 ??

like image 471
Kasparov92 Avatar asked May 29 '15 13:05

Kasparov92


1 Answers

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

like image 102
Kasparov92 Avatar answered Oct 24 '22 01:10

Kasparov92