package audio;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Port;
import javax.sound.sampled.TargetDataLine;
public class SoundMicroTest {
public static void main(String[] args) {
TargetDataLine line = null;
DataLine.Info info = new DataLine.Info(TargetDataLine.class, getAudioFormat()); // format
// is
// an
// AudioFormat
// object
if (AudioSystem.isLineSupported(Port.Info.MICROPHONE)) {
try {
Port port = (Port) AudioSystem.getLine(Port.Info.MICROPHONE);
port.open();
System.out.println(port.getLineInfo());
// line.open(getAudioFormat());
// line.start();
// while(true) {
//// System.out.println("Level: " + line.getLevel());
// }
} catch (LineUnavailableException ex) {
// Handle the error.
// ...
}
}
}
private static AudioFormat getAudioFormat()
{
AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;
float sampleRate = 41000.0F;
int sampleSizeInBits = 16;
int channels = 1;
int frameSize = 2;
int frameRate = 41000;
boolean bigEndian = false;
return new AudioFormat(encoding,
sampleRate,
sampleSizeInBits,
channels,
frameSize,
frameRate,
bigEndian);
}
}