Open mikechen66 opened 4 years ago
Hi Mike,
It looks like load_songs
didn't return anything, which from the source code seems to happen when it can't find any songs. See if the list_dir
above does anything or perhaps it is pointing to the wrong place.
Douwe
Hi Douwe:
I see that the path is too value to be understood. So it is shows the error
IndexError: list index out of range
I see that song_folder is a path but not be expressed in 15.1. Can you make an explicit example in the original code of lines. If the 15.1 Song Classification is to be solved, 15.2 to 15.4 will be easy to be solved.
def load_songs(song_folder):
song_specs = []
idx_to_genre = []
genre_to_idx = {}
genres = []
for genre in os.listdir(song_folder):
genre_to_idx[genre] = len(genre_to_idx)
idx_to_genre.append(genre)
genre_folder = os.path.join(song_folder, genre)
for song in os.listdir(genre_folder):
if song.endswith('.au'):
signal, sr = librosa.load(os.path.join(genre_folder, song))
melspec = librosa.feature.melspectrogram(signal, sr=sr).T[:1280,]
song_specs.append(melspec)
genres.append(genre_to_idx[genre])
return song_specs, genres, genre_to_idx, idx_to_genre
song_specs, genres, genre_to_idx, idx_to_genre = load_songs('/home/mike/Documents/datasets/genres')
song_specs[0].shape
Thanks in advance,
Mike
The song classification example is interesting. But the question is the IndexError: list index out of range. I tried many methods and could not correct the issue.
Hi Douwe:
I tried the song classification. It has the list index out of range error. Please indicate how how to solve the issue.
IndexError Traceback (most recent call last)