【问题标题】:Opus audio File to Wav conversionOpus 音频文件到 Wav 转换
【发布时间】: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 库,但没有区别。

【问题讨论】:

    标签: java wav opus


    【解决方案1】:

    没有 Java 库可以执行此操作,但您可以使用 opus-tools 并使用 Java ProcessBuilder 执行 opusdec。请参阅my answerthis 文章了解如何使用ProcessBuilder

    【讨论】:

      【解决方案2】:

      试试这个:https://github.com/louisyonge/opus_android

      从 opus 编码为 wav

      OpusTool oTool = new OpusTool();
      oTool.decode(fileName,fileNameOut, null);
      oTool.encode(fileName, fileNameOut, null);
      

      【讨论】:

      • 知道为什么在 decode() 时会崩溃吗?
      【解决方案3】:

      我猜这是因为您正在使用 bytesRead = decoder.read() 将音频数据作为字节读取,或者 1) 输出被限制为 8 位深度(不确定为什么会这样做)或 2 ) 字节序或字节偏移量以某种方式混淆了。

      Concentus 确实有一种方法可以将 opus 数据包解码为明确表示波形的 16 位短值。唯一的问题是从 .opus 文件中读取 ogg 数据包的支持从未真正完成。不过可以通过稍微修改VorbisJava使其支持opus解码来实现。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-29
        • 2015-02-26
        • 1970-01-01
        • 2019-01-07
        • 2014-09-12
        • 2021-04-06
        • 2013-11-12
        • 1970-01-01
        相关资源
        最近更新 更多