我想读一个音频文件,它从22050赫兹降到8000赫兹。对于22050赫兹,缓冲区大小为512。有没有解决这个问题或其他方法来读取Java中的下采样?wav文件?
使用readexample类从
http://www.labbookpages.co.uk/audio/javaWavFiles.html
适用于22050赫兹的原始音频。
当我使用python的librosa对音频进行采样并以8000hz的频率写入文件时,为了使用readexample方法读取此文件,它抛出了一个异常-
Error :WavFileException: Compression Code 3 not supported WavFileException: Compression Code 3 not supported
Process finished with exit code -1
代码是
import java.io.*;
public class ReadExample
{
public static void main(String[] args)
{
try
{
WavFile wavFile = WavFile.openWavFile(new File(args[0]); //22050Hz filepath
wavFile.display();
int numChannels = wavFile.getNumChannels(); //numChannels = 1
double[] buffer = new double[512 * numChannels];
int framesRead;
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
do
{
framesRead = wavFile.readFrames(buffer, 512);
for (int s=0 ; s
{
if (buffer[s] > max) max = buffer[s];
if (buffer[s] < min) min = buffer[s];
}
}
while (framesRead != 0);
wavFile.close();
System.out.printf("Min: %f, Max: %f\n", min, max);
}
catch (Exception e)
{
System.err.println(e);
}
}
}
预期结果是像往常一样在缓冲区中获取值。