如何重复音频 wav 文件,使其在 python 中至少长 6 秒

how to repeat the audio wav file such that it becomes at least 6-seconds long in python

我正在处理声音分类问题,我希望我的音频文件至少应有 6 秒长。如果不是,我想在循环中通过 运行 扩展它。然后在 python.

的 librosa 库中找到它的 STFT

这可能有点帮助

import math
import soundfile as sf
import numpy as np
import librosa

data, samplerate = sf.read('test1.wav')
channels = len(data.shape)
length_s = len(data)/float(samplerate)
if(length_s < 6.0):
    n = math.ceil(6*samplerate/len(data))
if(channels == 2):
    data = np.tile(data,(n,1))
else:
    data = np.tile(data,n)
sf.write('new.wav', data, samplerate)
# now calculate stft for each channel if stereo