9

我想将所有 .mp3 与 pydub 连接到一个目录中。文件依次编号为 file0.mp3、file1.mp3 等。

此代码来自示例代码:

playlist_songs = [AudioSegment.from_mp3(mp3_file) for mp3_file in glob("*.mp3")] 

给我所有文件,现在我想连接,就像伪代码一样:

for i in playlist_songs:
    append i to finalfile

有没有办法实现这一点,还是我接近它错了?

谢谢您的帮助 !

4

2 回答 2

25

你可以从一个空的声音开始,像这样:

combined = AudioSegment.empty()
for song in playlist_songs:
    combined += song

combined.export("/path/to/output.mp3", format="mp3")

或者,如果您想稍微花哨一点并使用 5 秒交叉淡入淡出,则必须将第一首歌曲从列表中弹出

combined = playlist_songs[0]

for song in playlist_songs[1:]:
    combined = combined.append(song, crossfade=5000)

combined.export("/path/to/output.mp3", format="mp3")
于 2014-10-14T17:11:00.313 回答
0

只需总结为 Python 列表的元素:

sum(playlist_songs)
于 2020-08-05T09:32:15.207 回答