How to split a wav file into smaller pieces using Java?

I have a very large WAV file about 100 MB in size. I would like to use Java to read this wav file and split it into smaller pieces for every 2 seconds of audio.

Is it possible to do this in Java? Could you offer me an API with which I can reach it?

Thanks in advance, Snehal

+6
java audio wav
source share
3 answers

You can use AudioInputStream and AudioFileFormat (which contains the AudioFormat instance) to know what to write (format, sample rate), you can use AudioSystem to record it.

Based on the sampling rate of the format, you can find out how many bytes of audio are 2 seconds, and go on to the reading loop that many bytes from AudioInputStream write to a new file.

+4
source share

You can also find the specification for the wav file , which is really simple and simple. Then the binary will read the file and save it again in smaller bits.

I think this is the best learning experience to do it this way, and not always rely on libraries.

+1
source share

If you don't care about the longevity of your code, Quicktime For Java is a good bet for the media. It runs on Windows and Mac and will read and write almost any audio (and video) format. The downside is that Apple has not supported it for many years, so while it still works, you are investing in dying technology.

0
source share

All Articles