Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode a WAV to a mp3 on a Android device

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.

like image 216
bramp Avatar asked Sep 04 '10 10:09

bramp


People also ask

Do WAV files work on Android?

In addition to playing WAV files on Android through converting WAV to Android supported formats, you can use a WAV player for Android or an Android music player which enables to open and play wav on Android as well, such as “Remote Wave Free”. If you have VLC Media Player, you can use VLC to convert WAV files too.

What software converts a WAV to MP3?

If you need to convert WAV to MP3 fast and easily, choose free Freemake Wav to MP3 Converter. It converts any WAV music to a universal MP3 format that you can play on any gadget: PC, Mac, Linux, Apple and Android smartphones and tablets, or any other portable device and multimedia system.


1 Answers

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/

like image 63
Paul Gregoire Avatar answered Oct 04 '22 05:10

Paul Gregoire