我想从音频文件中制作块,以便在块之间重叠。例如,如果每个块的长度为4秒,并且第一个块从0到4开始并且重叠的步长为1秒,则第二个块应该从3到7开始。 ,但块之间没有重叠,只是将音频文件切成固定长度的块。有人为此目的有主意吗?谢谢
最佳答案
这是一种方法:
import numpy as np
from scipy.io import wavfile
frequency, signal = wavfile.read(path)
slice_length = 4 # in seconds
overlap = 1 # in seconds
slices = np.arange(0, len(signal), slice_length-overlap, dtype=np.int)
for start, end in zip(slices[:-1], slices[1:]):
start_audio = start * frequency
end_audio = end * frequency
audio_slice = audio[start_audio: end_audio]
本质上,我们执行以下操作:
要说服 slice ,请检查以下代码段:
slice_length = 4 # in seconds
overlap = 1 # in seconds
slices = np.arange(0, 26, slice_length-overlap, dtype=np.int) # 26 is arbitrary
frequency = 1
for start, end in zip(slices[:-1], slices[1:]):
start_audio = start * frequency
end_audio = end * frequency + overlap
print(start_audio, end_audio)
输出:
0 4
3 7
6 10
9 13
12 16
15 19
18 22
21 25
关于python - 使音频文件中的块与python中的重叠,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54341880/