Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return value of librosa.effect.Split is strange

Tags:

python

librosa

As titled, the result of this function is not logical and I don't understand what the function is doing.

For example, here is some reproducible code:

#load sample audio
filename = librosa.util.example_audio_file()
audio, sr = librosa.load(filename)

#get intervals which are non-silent
inter_20 = librosa.effects.split(audio, top_db=20)
inter_5 = librosa.effects.split(audio, top_db=5)

#create audio
above_20 = np.zeros(audio.shape)
above_5 = np.zeros(audio.shape)

for i in inter_20:
    start,end = i
    above_20[start:end]=audio[start:end]

for j in inter_5:
    start,end = j
    above_5[start:end]=audio[start:end]

#plot them out:
plt.figure(figsize=[15,3]) #figure 1
plt.plot(audio)
plt.plot(above_5,color='red')
plt.title('Audio above 5 dB')

plt.figure(figsize=[15,3]) #figure 2
plt.plot(audio)
plt.plot(above_20,color='red')
plt.title('Audio above 20 dB')

you can see from here: for figure 1, which is audio above 5dB:

audio above 5db

for figure 2, which is audio above 20dB:

audio above 20db

How can it be that audio above 20dB is more than audio above 5dB? To me this doesn't make sense.

like image 913
BarCodeReader Avatar asked Oct 16 '22 09:10

BarCodeReader


1 Answers

From the documentation at: https://librosa.github.io/librosa/generated/librosa.effects.split.html

top_db:number > 0

  The threshold (in decibels) **below** reference to consider as silence

I think top_db:20 means everything below (TOP - 20dB) instead of just 20dB is considered silence.

And there will be more above TOP - 20dB than TOP - 5dB. It also could explain your pictures.

like image 157
Pieter21 Avatar answered Oct 19 '22 11:10

Pieter21