CMU sphinx livespeech 示例
CMU sphinx livespeech example
我的目标是让用户通过点击一个按钮来说话,然后当他们点击停止按钮时,控制台输出结果。
我尝试套用了CMU sphinx官网写的代码,如下代码:
LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
// Start recognition process pruning previously cached data.
recognizer.startRecognition(true);
SpeechResult result = recognizer.getResult();
// Pause recognition process. It can be resumed then with startRecognition(false).
recognizer.stopRecognition();
这是我用 zk-maven 项目实现的方式:
public class SphinxSpeechRecog extends SelectorComposer<Component> {
Configuration configuration = new Configuration();
private LiveSpeechRecognizer recognizer;
private SpeechResult result;
public SphinxSpeechRecog() {
// TODO Auto-generated constructor stub
}
@Listen("onClick=#speakbtn")
public void startSpeaking() throws IOException, InstantiationException {
//System.out.println("hi");
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
recognizer = new LiveSpeechRecognizer(configuration);
recognizer.startRecognition(true);
result = recognizer.getResult();
recognizer.stopRecognition();
}
@Listen("onClick=#stopspeakbtn")
public void stopSpeaking() {
System.out.print("result: "+result);
}
}
前端(.zul 文件):
<?page title="sphinx speech recognition" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="sphinx speech recognition" border="normal" apply="sphinx.SphinxSpeechRecog">
<button id="speakbtn" label="speak"/>
<button id="stopspeakbtn" label="stop speaking"/>
</window>
</zk>
java(eclipse) 控制台输出一些像这样的奇怪结果(这么多分钟后):
result: edu.cmu.sphinx.api.SpeechResult@3be41473
我可以做些什么来优化我的代码?以及如何得到我真正想看的口语?
for(WordResult word : result.getWords()) {
System.out.print(word.toString());
}
查看更多示例here。
我的目标是让用户通过点击一个按钮来说话,然后当他们点击停止按钮时,控制台输出结果。 我尝试套用了CMU sphinx官网写的代码,如下代码:
LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
// Start recognition process pruning previously cached data.
recognizer.startRecognition(true);
SpeechResult result = recognizer.getResult();
// Pause recognition process. It can be resumed then with startRecognition(false).
recognizer.stopRecognition();
这是我用 zk-maven 项目实现的方式:
public class SphinxSpeechRecog extends SelectorComposer<Component> {
Configuration configuration = new Configuration();
private LiveSpeechRecognizer recognizer;
private SpeechResult result;
public SphinxSpeechRecog() {
// TODO Auto-generated constructor stub
}
@Listen("onClick=#speakbtn")
public void startSpeaking() throws IOException, InstantiationException {
//System.out.println("hi");
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
recognizer = new LiveSpeechRecognizer(configuration);
recognizer.startRecognition(true);
result = recognizer.getResult();
recognizer.stopRecognition();
}
@Listen("onClick=#stopspeakbtn")
public void stopSpeaking() {
System.out.print("result: "+result);
}
}
前端(.zul 文件):
<?page title="sphinx speech recognition" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="sphinx speech recognition" border="normal" apply="sphinx.SphinxSpeechRecog">
<button id="speakbtn" label="speak"/>
<button id="stopspeakbtn" label="stop speaking"/>
</window>
</zk>
java(eclipse) 控制台输出一些像这样的奇怪结果(这么多分钟后):
result: edu.cmu.sphinx.api.SpeechResult@3be41473
我可以做些什么来优化我的代码?以及如何得到我真正想看的口语?
for(WordResult word : result.getWords()) {
System.out.print(word.toString());
}
查看更多示例here。