Speech recognition 如何在CMUSphinx中为StreamSpeechRecognizer配置语法

Speech recognition 如何在CMUSphinx中为StreamSpeechRecognizer配置语法,speech-recognition,speech-to-text,cmusphinx,Speech Recognition,Speech To Text,Cmusphinx,我的语法是这样的: #JSGF V1.0; grammar music; public <command> = play | pause | next | previous; JSGF V1.0; 语法音乐; 公共=播放|暂停|下一个|上一个; 当我在LiveSpeechRegconizer中使用这个语法时,它工作得很好 现在我想在StreamSpeechRegconizer中使用这个。在github上的源CMUSphinx示例上的转录器演示中,它使用了StreamSpeec

我的语法是这样的:

#JSGF V1.0;

grammar music;

public <command> = play | pause | next | previous;
JSGF V1.0; 语法音乐; 公共=播放|暂停|下一个|上一个; 当我在LiveSpeechRegconizer中使用这个语法时,它工作得很好


现在我想在StreamSpeechRegconizer中使用这个。在github上的源CMUSphinx示例上的转录器演示中,它使用了StreamSpeechRecognitizer,它只展示了使用整个字典检测语音的方法。有没有办法只配置我自己的语法?

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

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