如何在CMUSphinx中为StreamSpeechRecognizer配置语法

时间:2015-06-08 14:51:20

标签: speech-recognition speech-to-text cmusphinx

我有这样的语法:

#JSGF V1.0;

grammar music;

public <command> = play | pause | next | previous;

当我将此语法用于LiveSpeechRegconizer时,它可以正常工作。

现在我想在StreamSpeechRegconizer中使用它。在使用StreamSpeechRecognizer的github上的源CMUSphinx示例的Transcriber Demo中,它仅显示了使用整个字典检测语音的方法。有没有办法配置我自己的语法?

1 个答案:

答案 0 :(得分:2)

要使用语法,您需要正确创建配置对象:

Configuration configuration = new Configuration();

configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");

 // a folder in classpath or in filesystem containing the grammars
configuration.setGrammarPath("resource:/com/example/grammars");
// A grammar name corresponding to a file music.jsgf
configuration.setGrammarName("music"); 
configuration.setUseGrammar(true);

StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(configuration);