import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
public class Audio_to_bytes {
public static void main(String args[]) throws IOException
{
File WAV_FILE = new File("/home/cybersecurity/Desktop/scream.wav");
ByteArrayOutputStream out = new ByteArrayOutputStream();
AudioInputStream in = null;
try {
in = AudioSystem.getAudioInputStream(WAV_FILE);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
int read,i;
byte[] buff = new byte[1024];
while ((read = in.read(buff)) > 0)
{
out.write(buff, 0, read);
}
out.flush();
byte[] audioBytes = out.toByteArray();
for(i=0;i<audioBytes.length;i++)
System.out.println(audioBytes[i]);
}
}
上面的代码是将.wav文件转换为字节数组。当我执行程序时,我得到许多值为-128或-127,我想知道这些值是精确值还是值变为如果超出字节范围(-128到128),则为边界值, 如果可以,我可以将音频文件转换为整数数组,因为它具有更宽的范围。