【问题标题】:Numbers Recognition in Microsoft Speech RecognitionMicrosoft 语音识别中的数字识别
【发布时间】:2023-04-05 06:48:01
【问题描述】:

我想将任何语音数字转换为整数,以便我可以对它们执行操作,例如:

twenty-one >> 21 

我设法对我正在使用的小范围数字进行了计算。

我正在遵循这个策略(但它不起作用,因为我需要用户说出任何数字):

string[] numberString =
{
    "zero", "one", "two", "three", "four", "five",
    "six", "seven", "eight", "nine", "ten",
    "eleven", "twelve", "thirteen", "fourteen", "fifteen",
    "sixteen", "seventeen", "eighteen", "nineteen", "twenty"
};

Choices numberChoices = new Choices();

for (int i = 0; i < numberString.Length; i++)
{
    numberChoices.Add(new SemanticResultValue(numberString[i], i));
}

gb[1].Append(new SemanticResultKey("number1", (GrammarBuilder)numberChoices));

因为我不会写下所有的数字...所以有什么聪明的方法可以做到这一点吗?

更新 1:

我尝试了以下方法:

Choices numberChoices = new Choices();

for (int i = 0; i <= 100; i++)
{
    numberChoices.Add(i.ToString());
}

gb[1].Append(new SemanticResultKey("op1", (GrammarBuilder)numberChoices));

Choices choices = new Choices(gb);

现在我可以拥有 100 个数字,但如果我将其设为 100 万,则加载需要相当长的时间,并且需要超过 2GB 的内存,并且无法实时完成加载。 使用 100 个数字,准确度很差,不能正确识别 12 个数字,有时甚至低于 10 个数字。

【问题讨论】:

标签: c# .net speech-recognition


【解决方案1】:

您可以将所有可能的单词添加到语法中,包括“百”、“百”、“七十”、“九十”、“千”、“千”作为原始选择。

期望语义键为您提供结果不是一个好主意,相反,您应该只分析识别的字符串并尝试将其解析为数字。

在输入时,您有一个类似“七百万五千三”的字符串。要将其转换为数字,您可以执行以下操作:

int result = 0;
int final_result = 0;
for (String word : words) {
     if (word == "one") {
         result = 1;
     }
     if (word == "two") {
         result = 2;
     }    
     if (word == "twelve") {
         result = 12;
     }    
     if (word == "thousand") {
         // Get what we accumulated before and add with thousands
         final_result = final_result + result * 1000;
     }    
}
final_result = final_result + result;

当然,语法允许识别“20057”之类的内容,但您必须在转换代码中处理它。

【讨论】:

  • 是的,我就是这么想的......但我需要确认这样做不好,因为我看到其他人这样做
  • 我试图让它接受说 2 个数字,但我遇到了这个例外。stackoverflow.com/questions/30531288/… 任何想法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
  • 2018-04-17
  • 2018-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多