Microsoft 语音识别中的数字识别

Numbers Recognition in Microsoft Speech Recognition

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

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 个数字,但如果我把它变成一百万,加载需要相当多的时间,并且需要超过 2GB 的内存并且它不会实时完成加载。 使用 100 个数字时,准确度很糟糕,它无法正确识别 12 个数字,有时会识别出小于 10 的数字。

您可以将所有可能的单词添加到语法中,包括 "hundred"、"hundreds"、"seventy"、"ninety"、"thousand"、"thousands"作为原始选择。

期望语义键给你结果不是一个好主意,相反你应该只分析识别的字符串并尝试用数字解析它。

在输入时你有一个像 "seven million five thousand three" 这样的字符串。要将其转换为数字,您可以执行以下操作:

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;

当然语法可以识别像 "twenty thousand five seven" 这样的东西,但你必须在你的转换代码中处理它。