Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any pure java way to convert .wav to .mp3?

Tags:

java

audio

mp3

wav

I've struggled a lot with Java but could not combine a working example of Java .wav to .mp3 converter. This converter will be used in a Java applet so it should depend only on libraries written in pure Java with no underlying C code calls.

Can anyone provide a fully working example?

Thank you

like image 261
Ivan Suhinin Avatar asked Feb 14 '11 22:02

Ivan Suhinin


2 Answers

Read your wave file @ http://java.sun.com/javase/technologies/desktop/media/jmf/ and encode to mp3 @ http://openinnowhere.sourceforge.net/lameonj/

As pointed out, lameonj is not a pure java solution. For that the options don't seem so many, but see the other SO question: MP3 Encoding in Java

like image 158
Nathan Kidd Avatar answered Oct 04 '22 04:10

Nathan Kidd


I use Jump3r to convert wav to mp3 on my project because the html5 player of IE11 can't play wav files.

Jump3r is the simpliest solution found to run inside a tomcat servlet. I wasn't able to integrate others solutions like jave certainly due to the security manager... Jump3r is a pure java program.

Jump3r is available on the maven repository (https://mvnrepository.com/artifact/de.sciss/jump3r/1.0.4) and the sources are available on github (https://github.com/Sciss/jump3r)

To convert a file, you should call the main method (in the following code, I use an inlined version of the main method to catch/throw an IOException if necessary)

private void convertWavFileToMp3File(File source, File target) throws IOException {
    String[] mp3Args = { "--preset","standard",
        "-q","0",
        "-m","s",
        source.getAbsolutePath(),
        target.getAbsolutePath()
    };
    (new Main()).run(mp3Args);
}
like image 45
jfgiraud Avatar answered Oct 04 '22 03:10

jfgiraud