Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python TypeError: reduce_noise() got an unexpected keyword

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?
like image 654
RED ALPHA97 Avatar asked Sep 18 '25 16:09

RED ALPHA97


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
like image 178
Lukasz Tracewski Avatar answered Sep 21 '25 05:09

Lukasz Tracewski


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)
like image 21
Prajot Kuvalekar Avatar answered Sep 21 '25 04:09

Prajot Kuvalekar