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

狂风中的少年 提交于 2019-12-29 06:59:08

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1507831/how-to-split-a-wav-file-into-smaller-chunks-using-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!