Pregunta

I'm writing a Java application and I'd like to convert Mp3 to Amr audio format. So, I could'nt success since there are no documentations or libraries to help. if possible, could you any hint about how to process, with examples.

Thanks.

¿Fue útil?

Solución

I have found this library called jave you can convert a media format to another format. you can see the library here

Here is a sample code that I did using the said plugin

Encoder encoder = new Encoder();
    EncodingAttributes attributes = new EncodingAttributes();
    attributes.setFormat("wav");
    AudioAttributes audio = new AudioAttributes();
    audio.setBitRate(new Integer(64000));
    audio.setChannels(new Integer(1));
    audio.setSamplingRate(new Integer(22050));
    attributes.setAudioAttributes(audio);

    File source = new File("mysong.mp3");
    File target = new File("mysong.wav");
    try {
        encoder.encode(source, target, attributes);
    } catch (IllegalArgumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InputFormatException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (EncoderException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

The code I posted basically converts the mp3 to wav

Otros consejos

JAVE is a well known and very useful tool for converting format, but it has some problems, EncoderException is one of it.

I created a project to make it updated and easy to use.

https://github.com/dadiyang/jave

English Documentation Here

This tool is mainly used to convert the AMR to MP3 format for playing in the audio tag of HTML5. It wrapper ffmpeg, and make it has cross platform feature.

Based on the JAVE project which relies on ffmpeg, this tool can be used to all ffmpeg supported format conversion. See JAVE official documentation for details.

The only thing you need to do is:

Inclue Maven Depandency

<dependency>
    <groupId>com.github.dadiyang</groupId>
    <artifactId>jave</artifactId>
    <version>1.0.0</version>
 </dependency>

And Invoke AudioUtils.amrToMp3 Method

public void amrToMp3()  {
    File source = new File("testAudio.amr");
    File target = new File("testAudio.mp3");
    AudioUtils.amrToMp3(source, target);
}

May it helps for you.

Aha, don't forget to star.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top