gpt4 book ai didi

java - 在java中读取wav文件

转载 作者:行者123 更新时间:2023-11-30 07:10:15 24 4
gpt4 key购买 nike

我是 java 的新手,谁能告诉我在下面的代码中将 wav 文件名放在哪里,我的文件名是“p.wav”,它的位置是 D:/p.wav;请帮忙,我收到以下错误:

线程“主”java.lang.Error 中的异常:

Unresolved 编译问题:

WavFile 无法解析为类型

无法解析WavFile

import java.io.*;

public class ReadExample
{

public static void main(String[] args)
{

try
{
// Open the wav file specified as the first argument
WavFile wavFile = WavFile.openWavFile(new File(args[0]));

// Display information about the wav file
wavFile.display();

// Get the number of audio channels in the wav file
int numChannels = wavFile.getNumChannels();

// Create a buffer of 100 frames
double[] buffer = new double[100 * numChannels];

int framesRead;
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;

do
{
// Read frames into buffer
framesRead = wavFile.readFrames(buffer, 100);

// Loop through frames and look for minimum and maximum value
for (int s=0 ; s<framesRead * numChannels ; s++)
{
if (buffer[s] > max) max = buffer[s];
if (buffer[s] < min) min = buffer[s];
}
}
while (framesRead != 0);

// Close the wavFile
wavFile.close();

// Output the minimum and maximum value
System.out.printf("Min: %f, Max: %f\n", min, max);
}
catch (Exception e)
{
System.err.println(e);
}

}

最佳答案

您需要从 HERE 下载 java 文件并将它们添加到与您的代码相同的包中。

然后改变这一行:

WavFile wavFile = WavFile.openWavFile(new File(args[0]));

到:

WavFile wavFile = WavFile.openWavFile(new File("D:/p.wav"));

关于java - 在java中读取wav文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22374258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com