【发布时间】:2018-01-23 05:48:03
【问题描述】:
早上好,
我正在尝试在 Java 上将 opus 音频文件转换为 wav 文件。
我一直在寻找不同库的不同解决方案,最后我找到了一个可能的解决方案。我的问题是输出的wav音频文件有很多噪音,比如失真,我不知道如何解决。
这是我的代码:
public void OpusToWav() {
JOpusFile inFile = new JOpusFile(input_File);
AudioFormat sourceFormat = inFile.format;
JOpusDecodable decoder; // com.glester.jopus.JOpusDecodable
ByteBuffer sampleBuffer;
WaveFileWriter wavWriter; // net.sourceforge.jaad.util.wav.WaveFileWriter
byte [] buf;
int bytesRead = 0;
try {
decoder = JOpusBufferFile.loadFromFile(input_File);
sampleBuffer = decoder.getSampleBuffer();
wavWriter = new WaveFileWriter(outputFile, 44100, sourceFormat.getChannels(), sourceFormat.getSampleSizeInBits());
buf = new byte[sampleBuffer.capacity()];
while(true) {
bytesRead = decoder.read();
if(bytesRead <= 0) break;
sampleBuffer.get(buf);
// Its needed to reduce sample volume in byte array??
wavWriter.write(buf, 0, bytesRead);
}
wavWriter.close();
decoder.close();
inFile.close();
} catch(URISyntaxException | IOException e) {
System.out.println("Error decoding opus file --> " + e.getMessage());
}
}
我尝试修改输出字节数组中的样本量,但问题仍然存在。
知道如何解决这个问题吗?
P.D:我也尝试过使用 Concentus 库,但没有区别。
【问题讨论】: