如何在 Android 设备上将 WAV 编码为 mp3

发布于 2024-09-17 20:41:43 字数 493 浏览 10 评论 0原文

我简化了我的问题并提供了赏金: 有哪些选项可以在 Android 设备上将原始 PCM 音频数据压缩为 mp3。

我的原始帖子: 我正在我的 Android 手机上创建一个合成器,并且我一直在生成 PCM 数据以发送到扬声器。现在我想知道是否可以将此 PCM 数据编码为 mp3 以保存到 SD 卡。 MediaRecorder 对象可以将来自麦克风的音频编码为各种格式,但是不允许对以编程方式生成的音频数据进行编码。

所以我的问题是,是否有一个标准的 Android API 用于编码音频?如果没有,有哪些纯 Java 或基于 NDK 的解决方案?您能推荐其中任何一个吗?

如果失败,我只需将生成的音频保存为 WAV 文件,我可以轻松做到这一点。

I have simplified my question and offered a bounty:
What options are there for compressing raw PCM audio data to a mp3 on a Android device.

My original post:
I'm creating a synthesiser on my Android phone, and I've been generating PCM data to send to the speakers. Now I'm wondering if I can encode this PCM data as a mp3 to save to the sdcard. The MediaRecorder object can encode audio coming from the microphone into various formats, but doesn't allow the encoding from programmatically generated audio data.

So my question is, is there a standard Android API for encoding audio? If not, what pure Java or NDK based solutions are there? And can you recommend any of them?

Failing this I'll just have to save my generated audio as a WAV file, which I can easily do.

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

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

发布评论

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

评论(3

李不 2024-09-24 20:41:43

纯Java

查看 Tritonus 的 javasound 洁净室实现,它在此处提供 MP3 编码器 插件:http: //www.tritonus.org/plugins.html

其次,我建议查看 jzoom 的库 JLayer 或 JLayerME: http://www.javazoom.net/ javalayer/javalayer.html (这可能只是解码,不确定)

如果这些不适合您的需要,您可以查看 2000 年这篇有关向 J2SE 添加 MP3 功能的文章(带源代码):http://www.javaworld.com/javaworld/jw-11-2000/jw-1103-mp3.html

本地路由

如果您想要“本机”性能,我会考虑适用于 Android 的 FFmpeg 或 Lame 端口。
拉梅:http://lame.sourceforge.net/

Pure Java

Look into Tritonus's clean room implementation of javasound which offers an MP3 encoder plugin here: http://www.tritonus.org/plugins.html

Secondly, I would suggest looking into jzoom's libraries JLayer or JLayerME: http://www.javazoom.net/javalayer/javalayer.html (this may only be decode, not sure)

If those doesn't suit your need you can look at this article from 2000 about adding MP3 capabilities to J2SE (with source): http://www.javaworld.com/javaworld/jw-11-2000/jw-1103-mp3.html

Native route

If you want "native" performance I would look at an FFmpeg or Lame port for Android.
Lame: http://lame.sourceforge.net/

靖瑶 2024-09-24 20:41:43

据我所知,仅使用 SDK 中的工具无法做到这一点。根据官方开发人员指南,该平台中没有 MP3 编码器(Android 支持媒体格式),因此您必须使用 NDK 自行移植编码器,然后编写一些包装器代码以通过 JNI 接收音频样本。

我目前正在为我自己的音乐播放器移植一些来自 Rockbox 项目的音频解码器,它可以将音频录制到 MP3 中,所以也许您应该尝试查看它的源代码并找到编码器库。大多数解码器都有 ARM 优化,这可以显着加快速度,所以我猜一些编码器也有这个附加功能。

As far as i know you can't do this using only the tools in the SDK. According to the official developer guide there isn't an MP3 encoder in the platform (Android Supported Media Formats), so you have to port an encoder on your own using the NDK, then write some wrapper code to receive the audio samples through JNI.

I'm currently working on porting some audio decoders from the Rockbox project for my own music player, and it can record audio into MP3, so maybe you should try to look into it's source and find the encoder library. Most of the decoders have ARM optimalizations which speeds up things noticable, so i guess some of the encoders have also this addition.

情栀口红 2024-09-24 20:41:43

Mp3 编码器在 android 中不可用。您必须使用 mp3 lame lib 编译 libav,您可以从中找到代码
http://libavandroid.wordpress.com

Mp3 encoder is not available in android.you have to compile libav with mp3 lame lib you can find code from
http://libavandroid.wordpress.com

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