【发布时间】:2021-07-30 21:19:39
【问题描述】:
我可以在同一台机器上使用两个或多个 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;
}
这段代码运行良好——当我说“一个”时——它从两个引擎中输入“一个”。
我的意思是制作 2 个或更多引擎,加载两个或更多大语法,如果它在不同的引擎上被识别 - 获得性能(并验证)识别。
谢谢!
附:感谢您的回复!
好的,我重写一段代码:
var gr3 = MakeGrammar("gr3", words3);
所以,在那一行我创建了一个新语法。 我可以将它加载到第二个引擎。
因此,gr1 将加载到 Engine1,gr2,g3- 到 Engine2。
我知道,这是个愚蠢的问题,但是: 可能是 Engine1 和 Engine2 只是对一些识别这种语法的引擎的引用(语法很大)吗? 我希望不是这样,因为我想在我的机器上创建 1 对 N 引擎,加载 1 对 N 语法(一个大语法到一个引擎)并尝试识别它。 谢谢!
【问题讨论】:
-
在我看来,您只是不允许重用语法对象。尝试创建单独的对象。
-
xm..我按照你说的做...对两个引擎使用同一个对象...
-
@Chris ,但我怎么能理解 - 我使用相同的引擎,还是两个不同的引擎?
-
您仍在将
gr1传递给两个引擎。尝试创建完全独立的语法对象。 -
有什么例外?还可以尝试给它们起唯一的名称,以防在 api 内部共享某些内容。
标签: c# speech-recognition microsoft-speech-platform