[英]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的数字。
您可以为语法添加所有可能的单词,包括“百”,“百”,“七十”,“九十”,“千”,“千”作为原始选择。
期望语义键为您提供结果不是一个好主意,相反,您应该只分析可识别的字符串并尝试将其解析为数字。
输入时,您输入的字符串为“七千五百三十”。 要将其转换为数字,您可以执行以下操作:
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;
当然,语法将允许识别诸如“两千五十七”之类的内容,但是您必须在转换代码中进行处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.