简体   繁体   中英

Numbers Recognition in Microsoft Speech Recognition

I want to transform any spoken number into integers so that I can perform operation on them for example:

twenty-one >> 21 

I managed to do the calculation on small range of numbers I am using.

I am following this strategy (but its not going to work because I need the user to say any number):

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));

because I am not going to write down all the numbers... so is there any smart way to do that ??

Update 1:

I tried the following:

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);

now I can have 100 numbers, but if i make it a Million, it takes pretty much time loading, and it takes more than 2GB of the memory and it does not finish the load in real time. Working with the 100 numbers, the accuracy is terrible, it does not recognize twelve correctly and sometimes numbers lower than 10.

You can add all possible words to the grammar including "hundred", "hundreds", "seventy", "ninety", "thousand", "thousands" as raw choices.

It is not a good idea to expect a semantic key to give you the result, instead you should just analyze recognized string and try to parse it in a number.

On input you have a string like "seven million five thousand three". To convert it to number you do something like:

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;

Of course grammar would allow to recognize something like "twenty thousand five seven", but you have to handle that in your conversion code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM