Description
A speech recognizer calculator in Java Using Sphinx4 library exists.
The full code on github: here
The gram file i am using is the below(on github):
#JSGF V1.0;
/**
* JSGF Grammar
*/
grammar grammar;
public <syntax> = (one | two | three| four| five | six | seven | eight | nine | ten | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty)
(plus | minus | multiply | division)
(one | two | three| four| five | six | seven | eight | nine | ten | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty);
The problem:
I want the program to be able to recognize numbers from 0 to 1 million in English Language
.
In the current state as you can see it can recognize the numbers (one | two | three| four| five | six | seven | eight | nine | ten | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty)
, as i have written them manually into the gram file
.
I mean i have to write them all manually into the gram file
(i can create a program to produce that file) but again it is seems impossible(some pattern may exist),the file will be too much gigabytes.
Finally:
Is there any smart solution?Thanks for the effort :)
The new grammar after Nikolay
Solution is:
public <number> = (one | two | three | four | five | six | seven | nine | ten
| eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty
| thirty | forty | fifty | sixty | seventy | eighty | ninety | hundred | thousand | million | billion)+;
public <syntax> = <number>{1} (plus | minus | multiply | division){1} <number>{1};
The smartest solution is to recognize a text string first. Grammar should not be complex, it should just list the words used in numbers:
grammar number;
public <number> = (one | two | three | four | five | six | seven |
nine | ten | eleven | twelve | thirteen | fourteen | fifteen |
sixteen | seventeen | eighteen | nineteen | twenty | thirty | forty |
fifty | sixty | seventy | eighty | ninety | hundred | thousand |
million | and )*;
Once text is recognized, convert it to numbers. You can check How to convert words to a number? for details.