Python库可拆分和加入mp3文件 [英] Python library to split and join mp3 files

查看:171
本文介绍了Python库可拆分和加入mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多可以使用mp3标签的库,但是我只需要2个功能-将mp3文件分为2部分,第二部分将合并5 mp3.

There are a lot of libs to work with mp3 tags, but I need just 2 functions - split mp3 file in 2 parts and the second one to merge 5 mp3.

你能建议什么吗? 谢谢!

Can you suggest anything? Thanks!

推荐答案

我写了一个漂亮的库( pydub )确切的用例很多:

I wrote a library (pydub) for pretty much this exact use case:

from pydub import AudioSegment

sound = AudioSegment.from_mp3("/path/to/file.mp3")

# len() and slicing are in milliseconds
halfway_point = len(sound) / 2
second_half = sound[halfway_point:]

# Concatenation is just adding
second_half_3_times = second_half + second_half + second_half

# writing mp3 files is a one liner
second_half_3_times.export("/path/to/new/file.mp3", format="mp3")

增加沉默差距

如果您想在声音的各个部分之间添加静音:

Adding a silent gap

If you'd like to add silence between parts of a sound:

two_sec_silence = AudioSegment.silent(duration=2000)
sound_with_gap = sound[:1000] + two_sec_silence + sound[1000:]

这篇关于Python库可拆分和加入mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆