嗨,我使用pydub来分割一个音频文件,给出从原始文件中提取片段的范围。
我拥有的是:
from pydub import AudioSegment
sound_file = AudioSegment.from_mp3("C:\\audio file.mp3")
# milliseconds in the sound track
ranges = [(30000,40000),(50000,60000),(80000,90000),(100000,110000),(150000,180000)]
for x, y in ranges:
new_file = sound_file[x : y]
new_file.export("C:\\" + str(x) + "-" + str(y) +".mp3", format="mp3")
它可以很好地工作前3个新的文件。然而,其余的就不一样了--它不会相应地分裂。
问题在我给范围的方式上吗?
谢谢。
插件:
当它变得简单的时候-例如
sound_file[150000:180000]
并将其导出到mp3文件中。它工作,但只削减了50000:80000的一部分。似乎看不出正确的范围。
发布于 2021-07-04 09:34:56
试试这个,也许能行
import pydub
import numpy as np
sound_file = pydub.AudioSegment.from_mp3("a.mp3")
sound_file_Value = np.array(sound_file.get_array_of_samples())
# milliseconds in the sound track
ranges = [(30000,40000),(50000,60000),(80000,90000),(100000,110000),(150000,180000)]
for x, y in ranges:
new_file=sound_file_Value[x : y]
song = pydub.AudioSegment(new_file.tobytes(), frame_rate=sound_file.frame_rate,sample_width=sound_file.sample_width,channels=1)
song.export(str(x) + "-" + str(y) +".mp3", format="mp3")
https://stackoverflow.com/questions/42060433
复制相似问题