0

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}; 
GOXR3PLUS
  • 6,877
  • 9
  • 44
  • 93

1 Answers1

2

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.

Community
  • 1
  • 1
Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • Nikolay i have done the second part for converting words to number or number to words . The problem i have is that the grammar file only recognizes the numbers i have written.... , `(one | two | three| four| five | six | seven | eight | nine | ten | eleven | twelve | thirteen | fourteen | fifteen | sixteen | seventeen | eighteen | nineteen | twenty)` , i want it to recognize every number ...Since i can't use a `language model` with a `grammar` i have stacked here ... Is there any special word `` that i can use into the `grammar file` ? – GOXR3PLUS Nov 20 '16 at 16:05
  • There are no special words. – Nikolay Shmyrev Nov 20 '16 at 22:01
  • Is there a way then to recognize all the numbers using a grammar(As string format)? :) Only that i want , nothing more , i can do the other stuff. – GOXR3PLUS Nov 20 '16 at 22:26
  • Thanks! . Your pattern works although `spinhx4` has very big problems, simply it doesn't recognize for example `one thousand twenty four` or things like that... I have edited the question containing the grammar i use after your answer. If you want have a look to say me if i am doing something wrong or just simply `sphinx4-5` needs more improvement or training. – GOXR3PLUS Nov 22 '16 at 08:37