Java Media Framework:从 mp3 文件中提取音频信息

发布于 2024-08-16 23:55:36 字数 888 浏览 13 评论 0原文

我正在分析音乐 mp3 文件。我正在做的是从文件中提取音频数据并计算音乐相似度。

我一直在使用 javazoom 来处理 mp3 文件。通过使用audioFormat,我从mp3文件中提取原始数据:

byte[] audioBytes = new byte[numBytes];
in_format_init = AudioSystem.getAudioInputStream(musicFile);
AudioFormat formatInit = in_format_init.getFormat(); 
AudioFormat formatFinal = new AudioFormat(
            AudioFormat.Encoding.PCM_SIGNED,
            formatInit.getSampleRate(),
            16,
            formatInit.getChannels(),
            formatInit.getChannels()*2,
            formatInit.getSampleRate(),
            false);
AudioInputStream streamIn = AudioSystem.getAudioInputStream(formatFinal,     in_format_init);
while (((numBytesRead = streamIn.read(audioBytes)) != -1))
{...}

通过这样做,我将音频数据(没有标题或标签)存储在audioBytes中,然后处理存储在数组中的信息。

我的问题是:是否可以从 mp3 音频文件中提取音频信息并将其存储,就像我在示例中所做的那样?我一直在阅读有关 JMF 的内容,但它让我感到困惑。

谢谢。

I'm analyzing music mp3 files. What I'm doing is extracting the audio data from the file and computing music similarity.

I've been using javazoom in order to handle mp3 files. By using audioFormat I'm extracting the raw data from the mp3 file:

byte[] audioBytes = new byte[numBytes];
in_format_init = AudioSystem.getAudioInputStream(musicFile);
AudioFormat formatInit = in_format_init.getFormat(); 
AudioFormat formatFinal = new AudioFormat(
            AudioFormat.Encoding.PCM_SIGNED,
            formatInit.getSampleRate(),
            16,
            formatInit.getChannels(),
            formatInit.getChannels()*2,
            formatInit.getSampleRate(),
            false);
AudioInputStream streamIn = AudioSystem.getAudioInputStream(formatFinal,     in_format_init);
while (((numBytesRead = streamIn.read(audioBytes)) != -1))
{...}

By doing this I store the audio data (without headers or tags) in audioBytes and then the info stored in the array is processed.

My question is: is it posible to extract the audio information from an mp3 audio file and store it as I do it in my example? I've been reading about JMF, but it's confusing for me.

Thanks.

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

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

发布评论

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

评论(1

死开点丶别碍眼 2024-08-23 23:55:36

我刚刚快速浏览了一下 JMF API,所以我不能 100% 确定这是否正确,甚至根本无法工作,但请尝试如下操作:

try {
  File f = new File ("/path/to/my/audio.mp3");
  DataSource ds = Manager.createDataSource(f.toURI().toURL());
  ds.connect();
  ds.start();
  ...
} catch (java.io.IOException e) {
  ...
} catch (NoDataSourceException e) {
  ...
}

在此之后尝试从 DataSource< 获取控件/code>: ds.getControls(),并查看是否有任何控件允许您读取原始音频数据。

阅读完音频后,您可能还需要执行各种清理操作,例如 ds.disconnect()

另外,不要忘记安装 JMF MP3 插件

-- Lauri

I've just had a quick look at the JMF API so I'm not a 100% sure this will be correct or even work at all, but try something like this:

try {
  File f = new File ("/path/to/my/audio.mp3");
  DataSource ds = Manager.createDataSource(f.toURI().toURL());
  ds.connect();
  ds.start();
  ...
} catch (java.io.IOException e) {
  ...
} catch (NoDataSourceException e) {
  ...
}

After this try getting the controls from the DataSource: ds.getControls(), and see if any of the controls allows you to read the raw audio data.

You'll probably have to do all kinds of cleanup as well, e.g. ds.disconnect(), after you're done reading the audio.

Also, don't forget to install the JMF MP3 plugin

-- Lauri

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