When I define my stretch() function like this:
def stretch(data, rate=0.8):
return librosa.effects.time_stretch(data, rate)
It gives the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[56], line 6
4 y = []
5 for i in range(len(audio_df)):
----> 6 feature=get_features(audio_df['Arrays'].iloc[i]);
7 for j in feature:
8 x.append(j)
Cell In[55], line 14, in get_features(data)
11 result.append(res2)
13 # with stretching and pitching
---> 14 new_data = stretch(data)
15 data_stretch_pitch = pitch(new_data, sr)
16 res3 = extract_features(data_stretch_pitch)
Cell In[53], line 7, in stretch(data, rate)
6 def stretch(data, rate=0.8):
----> 7 return librosa.effects.time_stretch(data, rate)
TypeError: time_stretch() takes 1 positional argument but 2 were given
But when I remove the 'rate' argument, it gives the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[58], line 6
4 y = []
5 for i in range(len(audio_df)):
----> 6 feature=get_features(audio_df['Arrays'].iloc[i]);
7 for j in feature:
8 x.append(j)
Cell In[55], line 14, in get_features(data)
11 result.append(res2)
13 # with stretching and pitching
---> 14 new_data = stretch(data)
15 data_stretch_pitch = pitch(new_data, sr)
16 res3 = extract_features(data_stretch_pitch)
Cell In[57], line 7, in stretch(data, rate)
6 def stretch(data, rate=0.8):
----> 7 return librosa.effects.time_stretch(data)
TypeError: time_stretch() missing 1 required keyword-only argument: 'rate'
I removed the 'rate' parameter to try working with the default that (even though that would have any effect on the data), but it still gave the error. I might be wrong, but according to me, when I give 2 arguments, it says it needs only 1, when I give 1, it says I'm missing one argument, what should I do?
The
time_stretch()function from thelibrosalibrary requires therateparameter as a keyword-only argument. You need to provide therateparameter explicitly as a keyword argument when calling the function :