views:

1500

answers:

6

Is it possible using Java to convert a real time audio stream from the mixer to MP3?

  • It has to be converted chunk by chunk otherwise the memory will be exhausted.
  • I already know how to record but only to lossless formats such as wav and aiff.
  • I need conversion as the audio comes in.
+3  A: 

May be you could use LAMEOnJ, which is a 100% Java API wrapping the standard LAME API (LAME being a MP3 encoder).

I am not sure however it would encode "chunk by chunk"...

VonC
A: 

As to the first question - is it possible, the only limitation I can see would be processor speed. If the algorithm you are using and your processor are both fast enough, there is no reason why it wouldn't be possible.

I know this isn't Java source, but it may get you on the right track - try looking at the Lame MP3 Encoder.

As far as I know all MP3 conversion algorithms work chunk by chunk. They don't need to read the whole WAV file to begin conversion, but they convert on the fly.

Bork Blatt
+1  A: 

Lame is indeed the de facto standard on MP3 encoding, partly because of its high quality (encoding MP3 is hard to do right... and it is a subjective art), partly because of legal issues (MP3 is a patented technique, AFAIK, that's why you get Lame binaries from a limited number of sites, most of them in countries where these legal issues are less (or not) enforced).

The LAMEOnJ project found by VonC seems to use a non-free JNI implementation, but I suppose you can do your own binding with JNI or even JNA, particularly if you target a precise system.

PhiLho
A: 

Create a new process in Java and write the stream to the stdin of to a tool like SoX to have it convert the audio data to MP3 on the fly.

Aaron Digulla
A: 

try using Ring buffer to encode the raw audio buffer in fly.

krishnakumar
+1  A: 

Use Xuggler to do it. It's free, and open source (LGPL), and uses libmp3lame under the covers. And the MediaTool API in Xuggler gives lots of examples of how to use it:

Xuggle