TargetInvocationException when using SemanticResultKey

I want my grammar to accept multiple numbers. I have a mistake when I repeat the number, for example, "twenty one." So I kept reducing my code to find the problem. I got the following code snippet for a grammar creator:

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", he still gives me this exception

enter image description here

That when I go to Google for this, it claims that this is an exception outside my code, I wonder if it is a bug in the Microsoft.Speech dll or I am missing something

Change 1:

I played with the code and made Async recognition as follows:

 sre.RecognizeAsync(RecognizeMode.Multiple); 

instead

 sre.Recognize(); 

now when I say "twenty-one", for example, this is the exception: base = {"Duplicate semantic key 'op1' in the root rule.}}

I know that the problem is related to grammar, but I repeated it for "op1". What am I missing?

+8
c # speech-recognition speech-to-text
source share
1 answer

I ended up using the text recognized for parsing it in

 void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 

I parsed a recognized string:

 e.Result 

Instead

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

because the .Semantics object throws the exception mentioned above.

I really want to know the solution if someone comes across it

+1
source share

All Articles