我正在尝试获得音频输入的双/内部幅度值:
AudioFormat format = new AudioFormat(8000.0f, 8, 1, true, true);
TargetDataLine line = null;
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
format);
if (!AudioSystem.isLineSupported(info)) {
}
try {
line = (TargetDataLine) AudioSystem.getLine(info);
line.open(format);
} catch (LineUnavailableException ex) {
// Handle the error ...
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
int numBytesRead;
byte[] data = new byte[line.getBufferSize() / 5];
line.start();
while (true) {
numBytesRead = line.read(data, 0, data.length);
// Save this chunk of data.
out.write(data, 0, numBytesRead);
for(int i=0; i<numBytesRead; i+=1) {
System.out.println(Byte.toString(data[i]));
}
System.out.println();
}
我无法理解为什么字节数组只包含值0,-1或1.如何获得幅度的双倍或整数值。
答案 0 :(得分:-1)
解决方案是将麦克风设备设置得更敏感。 :)