Java - 从 .wav 中删除标头

发布于 2024-08-05 05:45:50 字数 326 浏览 2 评论 0原文

我正在使用以下代码将 .wav 文件读入字节数组。

AudioInputStream inputStream = 
    AudioSystem.getAudioInputStream(/*my .wav file */);
int numBytes = inputStream.available();
byte[] buffer = new byte[numBytes];
inputStream.read(buffer, 0, numBytes);
inputStream.close();

有没有一种简单的方法可以在读入字节数组之前或之后删除 .wav 标头?

I'm reading a .wav file into a byte array with the following code.

AudioInputStream inputStream = 
    AudioSystem.getAudioInputStream(/*my .wav file */);
int numBytes = inputStream.available();
byte[] buffer = new byte[numBytes];
inputStream.read(buffer, 0, numBytes);
inputStream.close();

Is there a simple way to remove the .wav headers either before or after reading into the byte array?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

画离情绘悲伤 2024-08-12 05:45:51

来自 AudioInputStream read() 方法的数据已经是原始 wav 数据。因此无需担心 .wav 标头。如果您确实想访问标头内容,则可以使用与此 AudioInputStream 关​​联的 AudioFormat 对象。

http://download.oracle.com/javase/tutorial/sound/converters.html

顺便说一句,除非您的 .wav 文件非常小,否则您无法像处理示例那样通过一次读取就获得全部内容。您必须将读取内容放入 while 循环中,如上面引用的教程中的第一个代码片段所示。

The data from the AudioInputStream read() method is already raw wav data. So there is no need to worry about the .wav header. If you do want to access the header stuff, you would use the AudioFormat object associated with this AudioInputStream.

http://download.oracle.com/javase/tutorial/sound/converters.html

BTW, unless your .wav file is really small, you won't get it all with a single read as you've done with your sample. You will have to put your reads in a while loop, as in the first code snippet in the above cited tutorial.

苏佲洛 2024-08-12 05:45:51

如果正确,.wav 标头的长度为 44 个字节,因此跳过/删除前 44 个字节就可以了。

但不确定。

If correct the .wav header is 44 bytes long, so skip/remove the first 44 and there you have it.

Don't know for sure though.

廻憶裏菂餘溫 2024-08-12 05:45:51

wav 文件头是固定大小的吗?如果是这样,inputStream.skip?

Is a wav file header a fixed size? If so inputStream.skip?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文