我正在使用CMU sphinx库来录制声音。当我开始java应用程序时,我只分配了Recognizer和Configuration Manager一次,如下所示:
cm = new ConfigurationManager(soundPart.class.getResource("hellongram.config.xml"));
recognizer = (Recognizer) cm.lookup("recognizer");
recognizer.allocate();此外,我在我的应用程序中有一个录音按钮。当用户点击它时,我使用下面的代码来录制声音:
Microphone microphone = (Microphone)MR.sp.cm.lookup("microphone");
if (!microphone.startRecording()) {
System.out.println("Cannot start microphone.");
MR.sp.recognizer.deallocate();
System.exit(1);
}
//MR.sp.pleaseStartSpeaking.setVisible(true);
while(true){
Result result = MR.sp.recognizer.recognize();
if(result!=null){
String resultText = result.getBestFinalResultNoFiller();
MR.sp.lblYouSearched.setVisible(true);
MR.sp.lblNewLabel.setVisible(true);
MR.sp.lblNewLabel.setText(resultText);
MR.textQuery = resultText.toLowerCase();
break;
}
}这是我第一次这么做的时候用到的。但是,如果用户再次单击record按钮,则会抛出错误"Cannot start microphone“。我在这里做错了什么。WHy我不能第二次拿到麦克风吗
发布于 2012-04-05 00:01:36
您可能需要查看麦克风的RecordingThread here,并重新阅读获取代码here的页面,因为您使用的代码和您想要做的事情之间的区别是,您使用的代码不会启动和停止麦克风,而是在持续记录。RecordingThread看起来就是您想要的东西,因为您可以很容易地调用start()和stop()来获得您想要的东西。
https://stackoverflow.com/questions/10014537
复制相似问题