将评论标签写入WAV和M4A

发布于 2025-01-26 23:46:59 字数 407 浏览 5 评论 0原文

我有一个音频应用程序,我需要读和编写WAV和M4A文件的评论标签。这就是我所需要的。我挣扎了几个小时,没有成功。

我到达的最接近的是com.github.goxr3plus:jaudiotagger:2.2.7。我在用audiorecord写下的wav成功了Mediarecorder 。

我的问题是:如何使用AudioreCord在文件上编写评论标签?我知道如何使用AudioreCord(包括其标头)编写WAV文件,但是我未能找到明确的规范,例如这个标题

但是,无论如何,我都不知道如何在有或没有外部库的情况下为M4A文件添加评论标头。线索?

I have an audio app and I need to read and write the COMMENT tag of WAV and M4A files. This is all I need. I had struggled for hours without success.

The closest I arrived is using com.github.goxr3plus:jaudiotagger:2.2.7. I had success with WAV written with AudioRecord but exception with M4A written with MediaRecorder.

My question is: How to write the COMMENT tag on files with AudioRecord? I know how to write a WAV file using AudioRecord, including its headers, but I had failed to find a CLEAR specification, like this one for the headers.

And yet, in any case, I do not know how to add the COMMENT header for M4A files, with or without external libraries. Clues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合约呢 2025-02-02 23:46:59

在网上浏览很多后,我发现了解决方案在这里 >“其中'....'代表4个字节,显示每个'块的长度''。因此,我做了以下方法,该方法为我构建了ICMT块:

byte[] getCMT(String cmt) {
    byte[] cmtBytes = cmt.getBytes();
    int l = cmtBytes.length+12;
    byte[] result = new byte[l+8];
    byte[] list = new byte[]{'L', 'I', 'S', 'T',
            (byte) (l & 0xff),(byte) ((l >> 8) & 0xff),(byte) ((l >> 16) & 0xff),(byte) ((l >> 24) & 0xff)};
    l=l-12;
    byte[] info = new byte[]{'I','N','F','O','I','C','M','T',
            (byte) (l & 0xff),(byte) ((l >> 8) & 0xff),(byte) ((l >> 16) & 0xff),(byte) ((l >> 24) & 0xff)};

    System.arraycopy(list, 0, result, 0, list.length);
    System.arraycopy(info, 0, result, list.length, info.length);
    System.arraycopy(cmtBytes, 0, result, list.length+info.length, cmtBytes.length);
    return result;
}

现在很容易:

for (byte datum : getCMT(MyTextComment))
      outStream.write(datum);

唯一要小心的是选择均匀长度的字符串myTextComment

抱歉,如果这是众所周知的,请添加参考,因为这花了我太多时间。

After surfing the web a lot I found the solution here, where the crucial information is "where '....' represents 4 bytes that show the length of each 'chunk'". So I did the following method that builds the ICMT chunk for me:

byte[] getCMT(String cmt) {
    byte[] cmtBytes = cmt.getBytes();
    int l = cmtBytes.length+12;
    byte[] result = new byte[l+8];
    byte[] list = new byte[]{'L', 'I', 'S', 'T',
            (byte) (l & 0xff),(byte) ((l >> 8) & 0xff),(byte) ((l >> 16) & 0xff),(byte) ((l >> 24) & 0xff)};
    l=l-12;
    byte[] info = new byte[]{'I','N','F','O','I','C','M','T',
            (byte) (l & 0xff),(byte) ((l >> 8) & 0xff),(byte) ((l >> 16) & 0xff),(byte) ((l >> 24) & 0xff)};

    System.arraycopy(list, 0, result, 0, list.length);
    System.arraycopy(info, 0, result, list.length, info.length);
    System.arraycopy(cmtBytes, 0, result, list.length+info.length, cmtBytes.length);
    return result;
}

Now it is easy:

for (byte datum : getCMT(MyTextComment))
      outStream.write(datum);

The only thing to be careful is to choose the string MyTextComment with even length.

Sorry if this is well known, adding it for reference since it took me waaaaay too much time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文