3

I need WAV format audio files to establish some functions but if i get AMR format audio files from client side to server, I need convert it into WAV format. Now i am using JAVE library file to convert other format audio media files into WAV format. Everything works fine but when i receive AMR Audio files, it throws Exception like "it.sauronsoftware.jave.EncoderException: Duration: N/A, bitrate: N/A", I have posted my code below...

/**
 * method to convert all media format to wav format
 * 
 * @param fileLoc
 * @return
 */
public static String universalContentToWav(String fileLoc) {
    String location = SoundWaveConstants.AUDIO_LOCATION + new Date().getTime() + ".wav";
    AudioAttributes audio = new AudioAttributes();
    audio.setCodec("pcm_s16le");
    EncodingAttributes attrs = new EncodingAttributes();
    attrs.setFormat("wav");
    attrs.setAudioAttributes(audio);
    Encoder encoder = new Encoder();
    try {
        encoder.encode(new File(fileLoc), new File(location), attrs);
        System.out.println("done");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return location;
}

I am using the java library file from http://www.sauronsoftware.it/projects/jave/. Is there any way to change AMR file to WAV or need some changes in my code. Thanks in advance.

chellapandi k
  • 299
  • 1
  • 4
  • 15
  • What does the public it.sauronsoftware.jave.MultimediaInfo getInfo tell you of the input file? – gfelisberto May 05 '16 at 13:54
  • @gfelisberto thanks for your reply :). Multimediainfo getInfo return like "it.sauronsoftware.jave.MultimediaInfo (format=amr, duration=-1, video=null, audio=null)", so i think encoder cannot read the AMR file. – chellapandi k May 05 '16 at 14:32

1 Answers1

1

The jave project is too old to handle some exception condition. I created a project to resolve EncoderException. The only thing you need to do is include the maven dependency:

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

and invoke AudioUtils.amrToWav method:

 File source = new File("testAudio.amr");
 File wavTarget = new File("testAudio.wav");
 it.sauronsoftware.jave.AudioUtils.amrToWav(source, wavTarget);

This project include the ffmpeg executable file for Linux/Mac/Windows, if the provided exe is incompatible with your platform, you can set ffmpeg.home as system property to tell where your own ffmpeg executable exists, like:

System.setProperty("ffmpeg.home", "/usr/local/bin/")

By the way, for compatibility, my project's package name is same as jave, in order to avoid package conflict, please remove the sauronsoftware jave's jar.

Project Site: https://github.com/dadiyang/jave

English Document: https://github.com/dadiyang/jave/blob/master/README-en.md

Shine Huang
  • 159
  • 1
  • 4