Python TypeError: reduce_noise() got an unexpected keyword

Viewed 868

hi guys I'm trying to do audio classification using python and I installed a package and when I tried to use the functions, it said "TypeError: TypeError: reduce_noise() got an unexpected keyword argument 'audio_clip' hear the code of function.

import librosa import numpy as np import noisereduce as nr

def save_STFT(file, name, activity, subject): #read audio data audio_data, sample_rate = librosa.load(file) print(file)

 #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)

this code running in jupyternote book with Conda environment but It's not running in pycharm. I installed conda environment in PYcharm but it does not work. Could you please help me know how to fix this error?

2 Answers

Answer to your question is in the error message.

"TypeError: TypeError: reduce_noise() got an unexpected keyword argument 'audio_clip' 

I am guessing you are using noisereduce Python library. If you check the docs, it does not have audio_clip on parameters' list.

Example of correct code:

reduced_noise = nr.reduce_noise(y=audio_data, y_noise=noisy_part, sr=SAMPLING_FREQUENCY) # check the SAMPLING_FREQUENCY

Probably you are referring old APIs for newer version of library
The work around to use old APIs in newer version of library is

from noisereduce.noisereducev1 import reduce_noise

Now you can reuse your code as

reduced_noise = reduce_noise(audio_clip=audio_data, noise_clip=noisy_part, verbose=False)
Related