In my project I have implemented an audio record option. For reading real-time voice I used TargetDataLine
.I want to record audio with high volume. How can I do that?
TargetDataLine line;
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
File file = new File("RecordedVoice.raw");
if(file.exists())
file.delete();
file.createNewFile();
fos = new FileOutputStream(file);
if (!AudioSystem.isLineSupported(info)) {
System.out.println("Line not supported: " + format.toString());
System.exit(0);
} else {
try {
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format);
out = new ByteArrayOutputStream();
int numBytesRead;
byte[] data = new byte[line.getBufferSize()/5];
line.start();
while (!isCancelled()) {
numBytesRead = line.read(data, 0, data.length);
out.write(data, 0, numBytesRead);
fos.write(data, 0, data.length);
}
out.close();
} catch (Exception excp) {
System.out.println("Error! Could not open Audio System line!");
excp.printStackTrace();
}
}