利用sauronsoftware实现铃声剪辑

听歌的时候突然被其中一段旋律打动,遂想剪辑出来作为手机铃声,奈何这种铃声制作工具又要下载麻烦,还不如写段代码来的方便,只要十几行就可实现……

首先引入jar包:

<!-- https://mvnrepository.com/artifact/it.sauronsoftware/jave -->
<dependency>
	<groupId>it.sauronsoftware</groupId>
	<artifactId>jave</artifactId>
	<version>1.0.2.1</version>
</dependency>

然后是实现方法:

public static void main(String[] args) throws EncoderException {
    AudioAttributes audio = new AudioAttributes();
    audio.setCodec("libmp3lame");
    audio.setBitRate(320*1000);//设置比特率
    audio.setSamplingRate(44100);

    EncodingAttributes attrs = new EncodingAttributes();
    attrs.setFormat("mp3");//设置格式
    attrs.setAudioAttributes(audio);
    attrs.setDuration(28f); // 设置截取的时长
    attrs.setOffset(26f); // 设置开始点

    String sourceFile = "E:\\CloudMusic\\房东的猫,陈婧霏 - New Boy.mp3";
    String targetFile = "E:\\CloudMusic\\New Boy.mp3";
    Encoder encoder = new Encoder();
    encoder.encode(new File(sourceFile), new File(targetFile), attrs);
}

搞定收工,继续搬砖……

posted @ 2021-07-27 15:18  逐梦寻欢  阅读(249)  评论(0编辑  收藏  举报