1
votes

Can i use two or more Microsoft Speech Recognition engines at the same machine (with same language)?

I have task on speech recognition and i try to recognize too big grammar (2000+ words).

So, i think to divide this big grammar on two grammars. One grammar load to first engine and other-at second.

But i do not know- is this SpeechRecognitinEngine instances referenced to 2 difference speech engines or it just linked to one engine?

Here is my code:

List<String> words1 = new List<string>();
words1.Add("one");

List<String> words2 = new List<string>();
words2.Add("two");

var gr1 = MakeGrammar("gr1", words1);
var gr2 = MakeGrammar("gr2", words2);

var gr3 = MakeGrammar("gr1", words1); // create new grammar with name gr1- to check on grammar unic name exception.

MicSpeechRecEngine1.LoadGrammar(gr1);  (where MicSpeechRecEngine is SpeechRecognitionEngine)

MicSpeechRecEngine2.LoadGrammar(gr2);
MicSpeechRecEngine2.LoadGrammar(gr3);

public static Grammar MakeGrammar(String name,List<String> words)
{
    Choices choises = new Choices();
    GrammarBuilder gb = new GrammarBuilder();
    gb.Culture = new CultureInfo("en-US");


    if (choises == null)
        throw new NullReferenceException("choises is null!");
    if (words == null)
        throw new NullReferenceException("Words is null!");
    choises.Add(words.ToArray());

    if (gb != null)
    {
        //gb.Append(choises); 
        gb.Append(choises, 0, 10);
    }

    Grammar g = new Grammar(gb);
    g.Name = name;
    g.Priority = 0;
    g.Weight = 1.0f;
    g.Enabled = true;

    return g;
}

This code works well- when i say -"one" - it types "one one"-from both engines.

My point is to make 2 or more engines, load two or more big grammar and if it is recognize on difference engines- get performance (and validate) recognition.

Thank you!

P.S. Thank you for responce!

Ok, i rewrite some piece of code:

var gr3 = MakeGrammar("gr3", words3);

So, at that line i create a new grammar. And i can load it to second engine.

So, gr1 will load to Engine1, gr2,g3- to Engine2.

I know,it is stupid question, but: Can be that Engine1 and Engine2 is just references to some Engine that recognize this grammars (grammars are big)? I hope that is not,because i want to create 1 to N engines at my machine, load 1 to N grammar (one big grammar to one engine) and try to recognize it. Thank you!

2
Seems to me that you just aren't allowed to reuse the grammar objects. Try creating separate objects.Chris
xm.. i do it like you say... use the same object to two engines...Admiral Land
@Chris , but how can i understand - i use the same engine,or two difference?Admiral Land
You're still passing gr1 to both engines. Try creating completely separate grammar objects.Chris
What's the exception? Also try giving them unique names, in case something is shared internally in the api.Chris

2 Answers

2
votes

Your problem lies in the following:

MicSpeechRecEngine1.LoadGrammar(gr1);  (where MicSpeechRecEngine is SpeechRecognitionEngine)

MicSpeechRecEngine2.LoadGrammar(gr2);
MicSpeechRecEngine2.LoadGrammar(gr3);

As Chris stated in the comment section you're loading the same grammar twice. In the part where you create grammar you're giving your grammars the same name as seen here:

var gr1 = MakeGrammar("gr1", words1);
var gr2 = MakeGrammar("gr2", words2);

var gr3 = MakeGrammar("gr1", words1);

Both gr3 and gr1 are the same to SAPI. So when you load them, you're loading "one" to both. Which is why you're getting "one one".

When you call LoadGrammar() I believe you're clearing the previous grammar. So the code:

MicSpeechRecEngine2.LoadGrammar(gr2);
MicSpeechRecEngine2.LoadGrammar(gr3);

Actually becomes:

MicSpeechRecEngine2.LoadGrammar(gr3);

As far as SAPI is concerned anyway.

From what I see, it does seem like you do infact have two recognizers running however.

-1
votes

You can certainly run two speech engines in one page of code. In fact, you could run numerous one's with different strings. I am inserting some snap-shots of mine. enter image description here