Make Sphinx4 Recognize all the numbers using custom .gram file

天涯浪子 提交于 2019-12-12 03:56:13

问题


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

回答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.



来源:https://stackoverflow.com/questions/40691518/make-sphinx4-recognize-all-the-numbers-using-custom-gram-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!