【问题标题】:C# Speech: Recognize multiple words?C# Speech:识别多个单词?
【发布时间】:2014-10-16 15:11:08
【问题描述】:

我如何识别,假设:一组给定选项中的 2 个单词?在 SO 上找不到此问题的答案。

这是我的识别码:

GrammarBuilder questionType = new Choices(new string[] { "The" });

GrammarBuilder connector = new Choices(new string[] { "cat", "dog" });

GrammarBuilder connector2 = new Choices(new string[] { "jumped"});

GrammarBuilder connector3 = new Choices(new string[] { "over", "on", "under", "in" });

GrammarBuilder graBui5 = new GrammarBuilder();
graBui3.Append(questionType, 1, 1); //min repeat = 1 and max repeat = 1
graBui3.Append(connector, 1, 1);
graBui3.Append(connector2, 1, 1);
graBui3.Append(connector3, 1, 2); //Tried adding 2 for maxRepeat but didn't work

Grammar Gra5 = new Grammar(graBui5);

比如参考上面的代码:我怎么识别这个?

猫跳过去

我需要从“connector3”GrammarBuilder 中识别 2 个单词。我该怎么做?谢谢!

【问题讨论】:

  • 你之前已经问过这个问题了。
  • errrr 那是完全不同的 o.O 你有没有读过这个问题
  • 我确实做到了,但您仍然不了解基础知识。如果你想识别序列,你根本不需要选择,你只需要序列“over on”,“over in”,“under on”,“under in”
  • 而不是 GrammarBuilder connector2 = new Choices(new string[] { "jumped"});您只需创建新的 GrammarBuilder("jumped");没有选择 1 个元素。

标签: c# speech-recognition grammar speech


【解决方案1】:

在附加文本之前使用哈希集集合。

因此,在您的方法 Append() 中,将附加文本存储到哈希集中以防止出现多个文本。但请注意,这样做会阻止像 The 这样的单词,因此在这种情况下,这种方法会失败。

在此处了解 HashSet:HashSet

编辑:

如果您想查看重复的单词,我会使用 Distinct 和 except 来获取集合中重复的单词。

假设您要存储附加的文本,使用 distinct 使所有记录唯一,然后将其与原始记录除外以从 distinct 中删除单词,其余的应该是重复的。

在此处阅读更多信息:DistinctExcept

【讨论】:

  • 实际上这与我想要的相反 :) 我想从选择中识别多个单词 :)
猜你喜欢
  • 1970-01-01
  • 2022-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 1970-01-01
相关资源
最近更新 更多