我可以使用两个或更多Microsoft语音识别引擎吗?

时间:2015-07-03 10:12:32

标签: c# speech-recognition microsoft-speech-platform

我可以在同一台机器上使用两个或多个Microsoft语音识别引擎(使用相同的语言)吗?

我有语音识别的任务,我试图识别太大的语法(2000+个单词)。

所以,我想把这个大语法分成两个语法。一个语法加载到第一个引擎,另一个加载到第二个引擎。

但我不知道 - 这个SpeechRecognitinEngine实例引用了2个不同的语音引擎,还是只链接到一个引擎?

这是我的代码:

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

这段代码效果很好 - 当我说 - &#34;一个&#34; - 它从两个引擎中键入&#34;一个&#34;

我的观点是制作2个或更多引擎,加载两个或更多大语法,如果在不同引擎上识别,则获得性能(和验证)识别。

谢谢!

P.S。谢谢你的回应!

好的,我重写了一段代码:

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

所以,在那一行,我创建了一个新的语法。 我可以将它加载到第二个引擎。

因此,gr1将加载到Engine1,gr2,g3-到Engine2。

我知道,这是一个愚蠢的问题,但是: 可以说Engine1和Engine2只是引用了一些识别这种语法的引擎(语法很大)吗? 我希望不是,因为我想在我的机器上创建1到N个引擎,加载1到N语法(一个大语法到一个引擎)并尝试识别它。 谢谢!

2 个答案:

答案 0 :(得分:2)

您的问题在于:

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

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

正如Chris在评论部分中所说,你加载了两次相同的语法。 在您创建语法的部分中,您将为语法提供与此处相同的名称:

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

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

gr3和gr1都与SAPI相同。因此,当您加载它们时,您将两者都加载“一”。这就是为什么你得到“一个人”。

当你调用LoadGrammar()时,我相信你正在清除以前的语法。所以代码:

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

实际上变成:

MicSpeechRecEngine2.LoadGrammar(gr3);

至于SAPI无论如何。

从我看到的情况来看,似乎你确实有两个识别器正在运行。

答案 1 :(得分:-1)

您当然可以在一页代码中运行两个语音引擎。事实上,您可以使用不同的字符串运行多个字符串。我正在插入一些我的快照。 enter image description here