I am looking for a java library that will allow me to "trim" an audio file so that I can pull out and save X amount of seconds of an audio file. Ideally, I am looking for something that would be like a substr for an audio file. If I want from 123 seconds in to 153 seconds in I would be able to do:

coollib.load('bigfile.mp3');

coollib.trimAudioSeconds(123,30);

coollib.export('newfile.mp3');

I have seen this post:

But it didn't have anything about my substr quest. I am hoping someone has needed this functionality before so they will know exactly what direction to point me.

Thanks!

解决方案

I don't know about an existing library, but what you can do is read the file header for bitrate information, then multiply that by the seconds you want to go in, read so many bytes of the file and throw them away. Then you're at the right point to start recording, read so many bytes, and stop.

A regular mp3 library should be able to tell you about bitrate without your having to read the header yourself.

Then there's the problem of variable bitrate files...

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐