嗨,伙计们,我试着用python做音频分类,我和我安装了一个包,当我尝试使用这些函数时,它说:"TypeError: TypeError: reduce_noise()得到了一个意想不到的关键字参数'audio_clip‘,听听函数的代码。
进口librosa进口numpy为np进口噪音为nr
def save_STFT(文件、名称、活动、主题):#read音频数据audio_data,sample_rate =librosa.load(文件)打印(文件)
#noise reduction
noisy_part = audio_data[0:25000]
reduced_noise = nr.reduce_noise(audio_clip=audio_data, noise_clip=noisy_part, verbose=False)
#trimming
trimmed, index = librosa.effects.trim(reduced_noise, top_db=20, frame_length=512, hop_length=64)
#extract features
stft = np.abs(librosa.stft(trimmed, n_fft=512, hop_length=256, win_length=512))
# save features
np.save("STFT_features/stft_257_1/" + subject + "_" + name[:-4] + "_" + activity + ".npy", stft)
这段代码在带有Conda环境的jupyternote中运行,但它不是在py魅力中运行的。我在PYcharm中安装了conda环境,但它无法工作。请你帮我知道如何纠正这个错误好吗?
发布于 2021-09-23 14:48:17
你的问题的答案在错误信息中。
"TypeError: TypeError: reduce_noise() got an unexpected keyword argument 'audio_clip'
我猜您正在使用降噪 Python库。如果您检查这些文档,它在参数列表中没有audio_clip
。
正确代码示例:
reduced_noise = nr.reduce_noise(y=audio_data, y_noise=noisy_part, sr=SAMPLING_FREQUENCY) # check the SAMPLING_FREQUENCY
发布于 2021-12-13 15:41:40
您可能是指更新版本的库的旧APIs。
在新版本的库中使用旧APIs的工作是
from noisereduce.noisereducev1 import reduce_noise
现在,您可以将代码重用为
reduced_noise = reduce_noise(audio_clip=audio_data, noise_clip=noisy_part, verbose=False)
https://stackoverflow.com/questions/69299518
复制相似问题