I have a very huge WAV file, about 100MB in size. I would like to use Java to read this wav file and split it into smaller chunks for every 2 seconds of audio.
Is it possible to do this in Java? Could you please suggest me an API with which I can achieve it?
Thanks in advance, Snehal
You can use AudioInputStream and its AudioFileFormat member (which contains an AudioFormat instance) to know what to write (format, sample rate), you can use AudioSystem to write it.
Based on the sample rate of the format you can find out how many bytes of audio are 2 seconds, and go on a loop of reading that many bytes from the AudioInputStream, writing them to a new file.
You could also look up the specification for a wav file which is really basic and simple. And then binary read the file, and save it again in smaller bits.
I think it's a better learning experience to do it this way instead of always relying on libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With