Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slice indices must be integers or None or have an __index__ method [in timbral_brightness and timbral_hardness] #5

Open
ffont opened this issue Mar 26, 2018 · 2 comments

Comments

@ffont
Copy link
Member

ffont commented Mar 26, 2018

When processing this sound: https://freesound.org/people/bone666138/sounds/198841/ both timbral_brightness and timbral_hardness models fail (the others work fine). Both return the same error, although it happens in different parts of the code and might be completely unrelated. This is the Python stack trace for the errors:

timbral_brightness

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-85-852004113145> in <module>()
----> 1 timbral_brightness('/mtgdb/incoming/freesound/sounds/198/198841_285997.wav')

~/freesound-audio-analyzer/timbral_models/Timbral_Brightness.py in timbral_brightness(fname)
    105         eval_audio = audio_samples[i:i + blockSize]
    106         complex_spectrum = np.fft.fft(eval_audio * window)
--> 107         magnitude_spectrum = np.absolute(complex_spectrum[0:1 + len(complex_spectrum) / 2])
    108 
    109         if sum(magnitude_spectrum) > 0:

TypeError: slice indices must be integers or None or have an __index__ method

timbral_hardness

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-86-d8f62a7fc6e0> in <module>()
----> 1 timbral_hardness('/mtgdb/incoming/freesound/sounds/198/198841_285997.wav')

~/freesound-audio-analyzer/timbral_models/Timbral_Hardness.py in timbral_hardness(fname, dev_output, max_attack_time, bandwidth_thresh_db, phase_correction)
    636 
    637     # calculate the onsets
--> 638     original_onsets = calculate_onsets(audio_samples, envelope, fs, nperseg=nperseg)
    639     onset_strength = librosa.onset.onset_strength(audio_samples, fs)
    640 

~/freesound-audio-analyzer/timbral_models/Timbral_Hardness.py in calculate_onsets(audio_samples, envelope_samples, fs, look_back_time, hysteresis_time, hysteresis_percent, onset_in_noise_threshold, threshold_correction, minimum_onset_time_separation, nperseg)
    507             current_strength_onset = strength_onset_times[onset_idx]
    508             if current_strength_onset == strength_onset_times[-1]:
--> 509                 onset_strength_seg = onset_strength[current_strength_onset:]
    510             else:
    511                 onset_strength_seg = onset_strength[current_strength_onset:strength_onset_times[onset_idx + 1]]

TypeError: slice indices must be integers or None or have an __index__ method
@AndyP103
Copy link
Collaborator

timbral_brightness and timbral_hardness have now been updated to deal with this.
The error was caused due to the differences in python 2/3, whereby division in python 2 results in an int, but a float in python 3. I've now made the conversion to int explicit so should work on both.

@ffont
Copy link
Member Author

ffont commented Apr 18, 2018

I'm don't seem to be able to process https://freesound.org/s/198841 in either python2 or python3. In python2 I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/ffont/Developer/AudioCommons/timbral_models/test.py in <module>()
      1 from timbral_models import timbral_hardness
      2 
----> 3 timbral_hardness('test.wav')

/Users/ffont/Developer/AudioCommons/timbral_models/timbral_models/Timbral_Hardness.pyc in timbral_hardness(fname, dev_output, max_attack_time, bandwidth_thresh_db, phase_correction)
    637 
    638     # calculate the onsets
--> 639     original_onsets = calculate_onsets(audio_samples, envelope, fs, nperseg=nperseg)
    640     onset_strength = librosa.onset.onset_strength(audio_samples, fs)
    641 

/Users/ffont/Developer/AudioCommons/timbral_models/timbral_models/Timbral_Hardness.pyc in calculate_onsets(audio_samples, envelope_samples, fs, look_back_time, hysteresis_time, hysteresis_percent, onset_in_noise_threshold, threshold_correction, minimum_onset_time_separation, nperseg)
    379      I'm still adding new features to this so remember to update the definitions of all the input features
    380     '''
--> 381     onsets = librosa.onset.onset_detect(audio_samples, fs, backtrack=True, units='samples')
    382 
    383     # set values for return_loop method

/usr/local/lib/python2.7/site-packages/librosa/onset.pyc in onset_detect(y, sr, onset_envelope, hop_length, **kwargs)
    144 
    145     # Peak pick the onset envelope
--> 146     return util.peak_pick(onset_envelope, **kwargs)
    147 
    148 

TypeError: peak_pick() got an unexpected keyword argument 'backtrack'

With python3 I get this other error: (the same as in the issue description)

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    timbral_hardness('test.wav')
  File "/Users/ffont/Developer/AudioCommons/timbral_models/timbral_models/Timbral_Hardness.py", line 639, in timbral_hardness
    original_onsets = calculate_onsets(audio_samples, envelope, fs, nperseg=nperseg)
  File "/Users/ffont/Developer/AudioCommons/timbral_models/timbral_models/Timbral_Hardness.py", line 510, in calculate_onsets
    onset_strength_seg = onset_strength[current_strength_onset:]
TypeError: slice indices must be integers or None or have an __index__ method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants