How to divide a wav file into 1 second pieces with Java?

我只是一个虾纸丫 提交于 2019-12-06 05:54:45

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5978087/how-to-divide-a-wav-file-into-1-second-pieces-with-java

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