1

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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Kasparov92
  • 1,365
  • 4
  • 14
  • 39
  • First you should edit and add some more tags like what programming language you are using. Also provide us some code. What you provide is not helping or even a try. – Tom-Oliver Heidel May 29 '15 at 01:45
  • Related questions http://stackoverflow.com/questions/23635802/microsoft-speech-recognition-numbers-only and http://stackoverflow.com/questions/23503496/microsoft-speech-recognition-numbers-navigation and http://stackoverflow.com/questions/6493143/problem-in-recognition-of-numbers-in-system-speech – Nikolay Shmyrev May 29 '15 at 07:00

1 Answers1

2

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.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • Yeah that's what I was thinking at .. but I needed a confirmation it is not good to do it the way I did because I saw other people doing it – Kasparov92 May 29 '15 at 11:28
  • I am trying to make it accept saying 2 numbers, but I meet this exception.http://stackoverflow.com/questions/30531288/c-sharp-microsoft-speech-recognition-for-numbers Any Ideas ? – Kasparov92 May 29 '15 at 13:58