Files
java-2d-screensaver/src/sound/TestSoundRecordingUtil.java
Sem van der Hoeven e347ea492f Add screensaver files
2025-09-02 20:34:20 +02:00

56 lines
1.4 KiB
Java

package sound;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.LineUnavailableException;
/**
* A sample program that tests the sound.SoundRecordingUtil utility class.
* @author www.codejava.net
*
*/
public class TestSoundRecordingUtil {
private static final int RECORD_TIME = 10000; // 1 seconds
public static void main(String[] args) {
File wavFile = new File("Record.wav");
final SoundRecordingUtil recorder = new SoundRecordingUtil();
// create a separate thread for recording
Thread recordThread = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("Start recording...");
recorder.start();
} catch (LineUnavailableException ex) {
ex.printStackTrace();
System.exit(-1);
}
}
});
recordThread.start();
try {
Thread.sleep(RECORD_TIME);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println("time over");
try {
recorder.stop();
System.out.println("stopped");
recorder.save(wavFile);
System.out.println("STOPPED");
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("DONE");
}
}