understanding librosa.feature.spectral_contrast

415 views Asked by At

i am using python and I am trying to use this function but i am struggling with it.

See code error

  def extract_feature_for_one_signal(signal):
    signal = signal.astype(float)
    mel = np.mean(librosa.feature.melspectrogram(signal, sr=SAMPLE_RATE, n_fft=N_FFT, hop_length=HOP_LENGTH).T, axis=0)
    mfccs = np.mean(librosa.feature.mfcc(y=signal, sr=SAMPLE_RATE, n_mfcc=40).T, axis=0)
    stft = np.abs(librosa.stft(signal))
    chroma = np.mean(librosa.feature.chroma_stft(S=stft, sr=SAMPLE_RATE).T, axis=0)
    **contrast = np.mean(librosa.feature.spectral_contrast(S=stft, sr=SAMPLE_RATE).T, axis=0)**
    tonnetz = np.mean(librosa.feature.tonnetz(y=librosa.effects.harmonic(signal), sr=SAMPLE_RATE).T, axis=0)
    average_distance = []
    for std in STD_NUMS:
        average_distance.append(average_distance_between_spikes(np.abs(signal), std, 320))
        average_distance.append(average_distance_between_spikes(signal, std, 320))
    return mfccs, chroma, mel, contrast, tonnetz, average_distance

The program falls here:

    contrast = np.mean(librosa.feature.spectral_contrast(S=stft, sr=SAMPLE_RATE).T, axis=0)

SAMPLE_RATE = 1000 (it must be 1000.....)

what can i do to make it work?

1

There are 1 answers

0
user17651088 On

Your nyquist is would be greater than the sampling rate. Try redcuing the number of filter band from default 6 to maybe 3 or 4. You can also reduce your fmin to say 50.

The sampling rate you have choosen is too small. Keep it around 44100, which is the standard. It should work fine then