Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...