用Java读取WAV文件的问题

编程入门 行业动态 更新时间:2024-10-23 04:44:00
本文介绍了用Java读取WAV文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用该API在Java上读取wav文件:读取和写入Wav文件Java

I use that API to read wav file at Java: Reading and Writing Wav Files in Java

我用Java读取了一个wav文件,并希望将所有值放入一个arraylist中.我写道:

I read a wav file with Java and want to put all the values into an arraylist. I wrote:

// Open the wav file specified as the first argument WavFile wavFile = WavFile.openWavFile(fileToRemoveSilence); List<Double> allBuffer = new ArrayList<Double>(); .... do { // Read frames into buffer framesRead = wavFile.readFrames(buffer, 50); for (double aBuffer : buffer) { allBuffer.add(aBuffer); } } while (framesRead != 0);

当我在调试器中检查allBuffer的大小时,它说:

When I check the size of allBuffer at debugger it says:

74700

但是我使用的代码是

wavFile.display();

输出:

.... ... Frames: 74613 ....

我的allbuffer大于该API显示的帧.怎么来的?

My allbuffer is bigger than frames as displayed by that API. How it comes?

PS:我之前对此的疑问:

读取Java中的wav文件

如何分割wav用Java将文件压缩为1秒?

PS2: 我已修复了这些错误,但是当我运行该程序时,有时会出现该错误:可能是什么问题?

PS2: I fixed the bugs however when I run the program I get that error sometimes: What may be the problem?

java.lang.InterruptedException at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) at sun.java2d.Disposer.run(Disposer.java:127) at java.lang.Thread.run(Thread.java:662)

删除引用时发生异常:java.lang.InterruptedException

Exception while removing reference: java.lang.InterruptedException

推荐答案

从缓冲区复制到列表中时,您需要考虑framesRead.在上次通话中,您复制的双打数量比从文件中实际读取的数量多. (即与您第一个链接中的示例代码完全一样).

you need to account for framesRead when copying from the buffer into your list. on the last call, you are copying more doubles than you actually read from the file. (i.e. exactly like the example code in your first link).

更多推荐

用Java读取WAV文件的问题

本文发布于:2023-07-11 12:17:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1094029.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Java   WAV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!