本文整理汇总了Java中it.sauronsoftware.jave.AudioAttributes类的典型用法代码示例。如果您正苦于以下问题:Java AudioAttributes类的具体用法?Java AudioAttributes怎么用?Java AudioAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AudioAttributes类属于it.sauronsoftware.jave包,在下文中一共展示了AudioAttributes类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mp4ToMp3
import it.sauronsoftware.jave.AudioAttributes; //导入依赖的package包/类
/**
* Converts Mp4 file to MP3
*
* @param fileMp4
* @param fileMp3
* @return true if it has been converted
*/
public static boolean mp4ToMp3(File fileMp4, File fileMp3)
{
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(128000));
audio.setChannels(new Integer(2));
audio.setSamplingRate(new Integer(44100));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
try
{
encoder.encode(fileMp4, fileMp3, attrs);
Log.info("File MP4 convertito in MP3");
return true;
}
catch (IllegalArgumentException | EncoderException e)
{
Log.error("File non convertito");
Log.stackTrace(e.getStackTrace());
return false;
}
}
示例2: FileEncoder
import it.sauronsoftware.jave.AudioAttributes; //导入依赖的package包/类
public FileEncoder(String inFileName, String outFileName)
{
encoder = new Encoder();
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(320000));
audio.setChannels(new Integer(2));
audio.setSamplingRate(new Integer(44100));
attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
inputFile = new File(inFileName);
outputFile = new File(outFileName);
}
示例3: writeMP3
import it.sauronsoftware.jave.AudioAttributes; //导入依赖的package包/类
/**
* Converts the given <code>sequence</code> to a wav file and then to a mp3 file.
* The temporary wav file is deleted afterwards.
*
* @param sequence The sequence to write to the file
* @param fileName The file to write to
* @throws IOException Thrown if writing to file was not possible
* @see MusicWriter#writeWav(Sequence, String)
*/
public static void writeMP3(Sequence sequence, String fileName) throws IOException {
String file = fileNameWithoutEnding(fileName);
File wav = new File(file + System.currentTimeMillis() + ".wav");
File mp3 = new File(file + ".mp3");
mp3.delete();
writeWav(sequence, wav.getPath());
//Convert wav to mp3
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(64000);
audio.setChannels(2);
audio.setSamplingRate(22050);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
try {
encoder.encode(wav, mp3, attrs);
if (!fileName.equals(mp3.getName()))
System.out.println("Wrote mp3 to \"" + mp3.getPath() + "\"");
} catch (EncoderException e) {
e.printStackTrace();
} finally {
if (!wav.delete())
System.err.println("Could not delete temporary wav file");
}
}
示例4: encodeMP3
import it.sauronsoftware.jave.AudioAttributes; //导入依赖的package包/类
public boolean encodeMP3() {
try {
File fileConvert = new File(System.getProperty("user.dir") + "/" + toConvert);
File fileConversion = new File(System.getProperty("user.dir") + "/" + resultConversion);
Encoder enc = new Encoder();
EncodingAttributes att = new EncodingAttributes();
InfoMusic inf = new InfoMusic(fileConvert);
att.setDuration((float) inf.getFullTime());
AudioAttributes audioAttributes = new AudioAttributes();
audioAttributes.setBitRate(BITRATE);
audioAttributes.setChannels(CHANNELS);
audioAttributes.setSamplingRate((int) SAMPLE);
att.setAudioAttributes(audioAttributes);
att.setFormat("mp3");
enc.encode(fileConvert, fileConversion, att);
} catch (EncoderException e) {
e.printStackTrace();
return false;
}
return true;
}
示例5: toMp3
import it.sauronsoftware.jave.AudioAttributes; //导入依赖的package包/类
public byte[] toMp3(byte[] midi, String wavPath) throws Exception {
//allowing a maximum number users to generate tracks at the same time so that the system remains stable (midi->wav->mp3 is heavy)
semaphore.acquire();
try {
File wav;
if (wavPath == null) {
wav = File.createTempFile("gen", ".wav");
} else {
wav = new File(wavPath + "/gen.wav");
}
long start = System.currentTimeMillis();
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(wav))) {
Midi2WavRenderer.midi2wav(new ByteArrayInputStream(midi), fos);
IOUtils.write(midi, fos);
}
logger.info("midi2wav conversion took: " + (System.currentTimeMillis() - start) + " millis");
start = System.currentTimeMillis();
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
AudioAttributes audio = new AudioAttributes();
// audio.setBitRate(36000);
// audio.setSamplingRate(20000);
attrs.setAudioAttributes(audio);
attrs.setThreads(1);
File mp3 = File.createTempFile("gen", ".mp3");
encoder.encode(wav, mp3, attrs);
logger.info("wav2mp3 conversion took: " + (System.currentTimeMillis() - start) + " millis");
if (wavPath == null) {
wav.delete(); //cleanup the big wav file
}
byte[] mp3Bytes = FileUtils.readFileToByteArray(mp3);
mp3.delete();
return mp3Bytes;
} finally {
semaphore.release();
}
}