Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - removing headers from .wav

I'm reading a .wav file into a byte array with the following code.

AudioInputStream inputStream = 
    AudioSystem.getAudioInputStream(/*my .wav file */);
int numBytes = inputStream.available();
byte[] buffer = new byte[numBytes];
inputStream.read(buffer, 0, numBytes);
inputStream.close();

Is there a simple way to remove the .wav headers either before or after reading into the byte array?

like image 970
William Avatar asked Jan 28 '26 14:01

William


1 Answers

The data from the AudioInputStream read() method is already raw wav data. So there is no need to worry about the .wav header. If you do want to access the header stuff, you would use the AudioFormat object associated with this AudioInputStream.

http://download.oracle.com/javase/tutorial/sound/converters.html

BTW, unless your .wav file is really small, you won't get it all with a single read as you've done with your sample. You will have to put your reads in a while loop, as in the first code snippet in the above cited tutorial.

like image 121
Phil Freihofner Avatar answered Jan 31 '26 04:01

Phil Freihofner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!