Java - 从 .wav 中删除标头
我正在使用以下代码将 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 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.
如果正确,.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.
这是有关波形文件格式的良好参考。
Here is a good reference on the wave file format.
wav 文件头是固定大小的吗?如果是这样,inputStream.skip?
Is a wav file header a fixed size? If so inputStream.skip?