用Java读取WAV文件的问题 [英] Problem with reading wav file with Java

查看:213
本文介绍了用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文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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