如何读取 Java 中压缩的 .wav 音频文件?
How to read compressed .wav audio files in Java?
我想读取从 22050Hz 降采样到 8000Hz 的音频文件。对于 22050Hz,缓冲区大小为 512。是否有任何解决方案或任何其他方法来读取 java 中的下采样 .wav 文件?
读取音频文件的方法是使用 http://www.labbookpages.co.uk/audio/javaWavFiles.html 中的 ReadExample class 实现的,它适用于 22050Hz 原始音频。
当我使用 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<framesRead * numChannels ; 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);
}
}
}
预期的结果是像往常一样在缓冲区中获取值。
问题可能是您没有使用 java 对音频进行下采样。
或者
downsample .wav using java and then check its
working.
Good reference for Java-based downsampling and
this
或
resample .wav using third party libraries and test. Reference for
Re-sample using third-party library
我想读取从 22050Hz 降采样到 8000Hz 的音频文件。对于 22050Hz,缓冲区大小为 512。是否有任何解决方案或任何其他方法来读取 java 中的下采样 .wav 文件?
读取音频文件的方法是使用 http://www.labbookpages.co.uk/audio/javaWavFiles.html 中的 ReadExample class 实现的,它适用于 22050Hz 原始音频。
当我使用 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<framesRead * numChannels ; 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);
}
}
}
预期的结果是像往常一样在缓冲区中获取值。
问题可能是您没有使用 java 对音频进行下采样。
或者
downsample .wav using java and then check its working. Good reference for Java-based downsampling and this
或
resample .wav using third party libraries and test. Reference for Re-sample using third-party library