Reputation: 162
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]);
}
}
The above code is to convert the .wav file into a byte array.When I execute the program i get get many value as -128 or -127,I want to know that whether these values are exact values or the value becomes a boundary value if it exceeds the range of byte(-128 to 128), if so can i convert the audio file into a integer array since it has a wider range.
Upvotes: 1
Views: 1405
Reputation: 89169
The raw file is irrelevant since WAVE files are constructed using chunks. I suggest understanding those chunks first, RIFF
File Format, to understand WAVE files.
Upvotes: 2