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")
查看GStreamer及其Python包装器Gst-Python。
我编写了一个库(pydub)来处理这个用例:
看看维基百科上的MP3 file structure。在python中使用二进制读取模式编辑MP3文件。
s = open(file_name, 'rb').read()
将把整个文件放入表示文件中原始字节的字符串对象中(例如\xeb\xfe\x80
)。然后,您可以搜索并编辑字符串,使用方括号s[n]
用索引寻址字节偏移量。最后,只需在新文件中对所需的MP3帧进行二进制写入,将ID3头附加到要组成每个文件的帧集。相关问题 更多 >
编程相关推荐