ljacquet
ljacquet

Reputation: 29

Implementing JAVE in a program

I'm trying to use JAVE http://www.sauronsoftware.it/projects/jave/ to convert flac to mp3 in a java program on windows. I have downloaded the sources etc and I am wondering how to add it to my program?

Upvotes: 0

Views: 1550

Answers (1)

Suyash
Suyash

Reputation: 525

@Faendol : First of all you will need to import latest JAVE jar i.e. jave-1.0.2.jar You can google about importing jar files.

Now I have created standalone program to convert wav file to mp3.(just to give you brief idea). Example is tested. Similarly you can implement it for FLAC file. But I doubt you can do it with JAVE though its website says YES!

    import it.sauronsoftware.jave.AudioAttributes;
    import it.sauronsoftware.jave.Encoder;
    import it.sauronsoftware.jave.EncoderException;
    import it.sauronsoftware.jave.EncodingAttributes;
    import it.sauronsoftware.jave.InputFormatException;

    import java.io.File;
    import java.io.IOException;
    import java.security.InvalidAlgorithmParameterException;
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;

    import javax.crypto.BadPaddingException;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.NoSuchPaddingException;
    import javax.sound.sampled.UnsupportedAudioFileException;


 public class AudioConverter {

   public static void main(String[] args) throws IllegalArgumentException, InputFormatException, EncoderException, IOException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, UnsupportedAudioFileException{

    String sourceFile = "D:\\source.wav";
    String targetFile = "D:\\target.mp3";


    int samplingRate = 16000;// this could be 8000, 16000 mono or 16000 stereo 
    int channels = 2;// this could be 1 for mono and 2 for stereo
    int bitRate = 190000;// this could be 128, 160, 190 kbps, etc..

    AudioAttributes audio   = new AudioAttributes();
    audio.setCodec("libmp3lame");
    audio.setBitRate(bitRate);
    audio.setChannels(channels);
    audio.setSamplingRate(samplingRate);
    EncodingAttributes ea = new EncodingAttributes();
    ea.setAudioAttributes(audio);
    ea.setFormat("mp3");
    File f = new File(sourceFile);
    Encoder e = new Encoder();

    System.out.println(e.getInfo(f));

    e.encode(f, new File(targetFile), ea);
 }}

Upvotes: 1

Related Questions