8

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

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
Kasparov92
  • 1,365
  • 4
  • 14
  • 39
  • 1
    Have a look through the inner exceptions on the TargetInvocationException. That usually tells you what went wrong on the other side. – Sploofy May 29 '15 at 14:44
  • I cant do that as the source code is locked.. its Microsoft.Speech dll – Kasparov92 May 29 '15 at 14:46
  • 1
    What I mean is that the Exception class has a property called InnerExeception. When a TargetInvocationException is thrown, the exception that occurred on the other side will usually be contained in that property. So if you catch the TargetInvocationException in your code and put a break point there, you should get some clue into what went wrong in Microsoft.Speech. – Sploofy May 29 '15 at 14:51
  • Yeah I know that, but in this exception it opens another page where it mention that its not accessible, and there is no inner exception to click on it and view what is the exception. – Kasparov92 May 29 '15 at 15:03
  • it does not even get caught in the try and catch – Kasparov92 May 29 '15 at 15:04
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders May 29 '15 at 16:20
  • ohh okay .. i willt ake that into considerations in the next questions :D – Kasparov92 May 29 '15 at 16:42
  • I believe the problem you have is outside the code you posted. For example you are using gb[1] and it is not clear what is gb[0]. It might cause a problem. You need to post more complete example to get help. – Nikolay Shmyrev May 29 '15 at 23:11
  • the problem is in gb[1] , I want to say that this grammar can contain one or multiple number. – Kasparov92 May 30 '15 at 01:24

1 Answers1

1

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

Kasparov92
  • 1,365
  • 4
  • 14
  • 39
  • Are you using alternates ? Because I have the same error when I use Semantic consctructs and I try to iterate throught alternates. It seems to be provoked by a exception when building alternates where it tries to add semantic result key that altready exists in the dictionnary.... – Bruno Feb 15 '17 at 09:37