CMU sphinx ライブラリを使用してサウンドを録音しています。Java アプリケーションを開始するとき、次のように Recognizer と Configuration Manager を 1 回だけ割り当てます。
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;
}
}
これは私が初めて行うときに機能します。ただし、ユーザーが録音ボタンを 2 回クリックすると、「マイクを開始できません」というエラーがスローされます。ここで私が間違っていること。2回目にマイクを取得できないのはなぜですか