我正在尝试使用JAVE http://www.sauronsoftware.it/projects/jave/在Windows上的Java程序中将flac转换为mp3。我已经下载了源代码等,我想知道如何将其添加到程序中?
最佳答案
@Faendol:首先,您将需要导入最新的JAVE jar,即jave-1.0.2.jar您可以通过google搜索有关导入jar文件的信息。
现在,我创建了一个独立程序,将wav文件转换为mp3。实例经过测试。
同样,您可以为FLAC文件实现它。但是我怀疑您是否可以通过JAVE做到这一点,尽管它的网站说是!
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);
}}
关于java - 在程序中实现HAVE,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35181255/