如何用Java将wav文件分成1秒的片段? [英] How to divide a wav file into 1 second pieces with Java?

查看:17
本文介绍了如何用Java将wav文件分成1秒的片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前有一个问题:在 Java 中读取 wav 文件

首先,我想用 Java 读取一个 wav 文件并将其字节处理成一个数组.

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).

之后我会把那个wav文件分成1秒的片段(我应该处理那个小的wav文件的头问题,这是主要问题之一)

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)

我尝试使用该 API 使用 Java 读取 wav 文件,这是我上一个问题的答案.但是,对于该 API,我应该为标头做任何事情还是 API 自己做,以及如何使用 Java 将该 wav 文件分成 1 秒的片段.另一个 API 或其他任何东西对我来说也可以.

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.

推荐答案

您引用的 API 将返回一个 double[] 数组,其中包含来自原始 WAV 文件的示例数据.然后你要做的就是创建一堆较小的数组(每一秒长),然后从原始数组中的适当位置复制到每个较小的数组中(这样所有的原始数据都被复制到较小的数组中).然后只需使用 API 的写入方法从每个较小的数组创建实际的 WAV 文件.

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.

使用该 API 意味着您不必自己担心标头(这是一件好事,因为它们很容易编写,但阅读起来可能非常复杂).

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).

每个较小数组的大小取决于原始格式.如果原始 WAV 文件是具有 44.1 KHz 采样率的单声道文件,那么 1 秒的数组将包含 44,100 个元素.

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.

这篇关于如何用Java将wav文件分成1秒的片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆