如何从一个MP3音频数据加载? [英] How to get audio data from a MP3?

查看:600
本文介绍了如何从一个MP3音频数据加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有处理音频文件的应用程序。当使用MP3文件我不知道如何处理数据(我感兴趣的数据是音频字节为单位重新present我们所听到的那些)。

I'm working on an application that has to process audio files. When using mp3 files I'm not sure how to handle data (the data I'm interested in are the the audio bytes, the ones that represent what we hear).

如果我使用的是wav文件,我知道我有一个44个字节的头,然后将数据。当涉及到一个MP3,我读过,他们是由帧组成,包含头和音频数据的每一帧。是否有可能得到一个MP3文件中的所有音频数据?

If I'm using a wav file I know I have a 44 bytes header and then the data. When it comes to an mp3, I've read that they are composed by frames, each frame containing a header and audio data. Is it possible to get all the audio data from a mp3 file?

我用java(我已经添加MP3SPI,Jlayer和Tritonus),我能够从该文件的字节,但是我不知道什么这些字节重新present或如何办理即可。

I'm using java (I've added MP3SPI, Jlayer, and Tritonus) and I'm able to get the bytes from the file, but I'm not sure about what these bytes represent or how to handle then.

推荐答案

从MP3SPI 的文档:

From the documentation for MP3SPI:

File file = new File(filename);
AudioInputStream in= AudioSystem.getAudioInputStream(file);
AudioInputStream din = null;
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 
                                            baseFormat.getSampleRate(),
                                            16,
                                            baseFormat.getChannels(),
                                            baseFormat.getChannels() * 2,
                                            baseFormat.getSampleRate(),
                                            false);
din = AudioSystem.getAudioInputStream(decodedFormat, in);

您然后就阅读 DIN 数据 - 这将是原始的数据按德codedFormat 。 (请参阅 AudioFormat的文档$ C> 了解更多信息。)

You then just read data from din - it will be the "raw" data as per decodedFormat. (See the docs for AudioFormat for more information.)

(注意这个样本code不会关闭像流或任何东西 - 运用适当的try / finally块为正常)

(Note that this sample code doesn't close the stream or anything like that - use appropriate try/finally blocks as normal.)

这篇关于如何从一个MP3音频数据加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆