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

首先引入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);
}

搞定收工,继续搬砖……

相关文章:

  • 2021-12-12
  • 2021-12-11
  • 2022-12-23
  • 2021-08-23
  • 2021-10-21
  • 2021-10-10
  • 2022-03-03
  • 2022-01-18
猜你喜欢
  • 2021-12-06
  • 2022-12-23
  • 2022-01-09
  • 2021-10-19
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案