How to divide a wav file into 1 second pieces with

2019-04-10 10:39发布

I had a question previously: Reading wav file in Java

Firstly, I want to read a wav file with Java and get its bytes to process into an array.

Secondly, I will remove the silences of it(this is another question's topic).

After that I will divide that wav file into 1 second pieces(I should handle header problem for that small wav files, this is one of the major problems)

I tried to read wav file with Java with that API, the answer of my previous question. However with that API should I do anything for header or API does it itself and how can I divide that wav file into 1 second pieces with Java. Another API or anything else is OK for me too.

标签: java wav
1条回答
贪生不怕死
2楼-- · 2019-04-10 11:03

The API you reference will return a double[] array containing the sample data from the original WAV file. All you have to do then is create a bunch of smaller arrays (each one second long) and copy from the appropriate position in the original array into each of the smaller arrays (so that all the original data is copied into the smaller ones). Then just use the writing methods of your API to create actual WAV files from each smaller array.

Using that API means you shouldn't have to worry about the headers yourself (which is a good thing, because they're easy to write but very complicated to read, potentially).

The size of each smaller array is dependent upon the format of the original. If the original WAV file is mono with a 44.1 KHz sample rate, then a 1-second array would contain 44,100 elements.

查看更多
登录 后发表回答