Problem in recording
I have a program that first plays: "please say your name". It then records the name.
Part of my code is:
try {
AudioInputStream audio = AudioSystem.getAudioInputStream(new File("sth.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
}
catch(UnsupportedAudioFileException uae) {
System.out.println(uae);
}
catch(IOException ioe) {
System.out.println(ioe);
}
catch(LineUnavailableException lua) {
System.o开发者_JAVA百科ut.println(lua);
}
r.captureAudio();
Here r
is an instance of the main class.
The problem is that the recording goes like this:
It first plays "please enter your name" and then plays what I record with mic.I am a beginner and don't have much experience with Java.
What changes should I make so that the recording contains only the microphone input and not "please enter your name"?
I am not sure I completely understand your question.
Popping a JOptionPane
(or modal JDialog
) will block the GUI until dismissed.
If you pop one to say 'start recording', start the recording directly after that is closed and pop a new one with 'stop recording', the second will stop the rest of the program statements (but not the recording itself, as long as it is done in a Thread
).
Try calling clip.drain()
, this will block current thread until the clip has finished playing. After that you can start capturing.
精彩评论