简体   繁体   English

如何用Java将WAV文件分成1秒?

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

I had a question previously: Reading wav file in Java 以前我有一个问题: 用Java读取wav文件

Firstly, I want to read a wav file with Java and get its bytes to process into an array. 首先,我想用Java读取wav文件并获取其字节以处理成数组。

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) 之后,我将把该wav文件分成1秒(我应该处理那个小wav文件的头文件问题,这是主要问题之一)

I tried to read wav file with Java with that API, the answer of my previous question. 我尝试使用具有该API的Java读取wav文件,这是我上一个问题的答案。 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. 但是,使用该API时,我应该对标头执行任何操作,或者API本身执行此操作,以及如何使用Java将wav文件分为1秒。 Another API or anything else is OK for me too. 我也可以使用其他API或其他任何工具。

The API you reference will return a double[] array containing the sample data from the original WAV file. 您引用的API将返回一个double[]数组,其中包含原始WAV文件中的示例数据。 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. 然后,只需使用API​​的编写方法即可从每个较小的数组创建实际的WAV文件。

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). 使用该API意味着您不必自己担心标头(这是一件好事,因为标头很容易编写,但阅读起来很复杂,可能)。

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. 如果原始WAV文件是具有44.1 KHz采样率的单声道,则1秒数组将包含44,100个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM