Extract labels from the 'filename'

I have a folder with many sub-folders. Each sub-folder has many .wav files. I need to extract the label for the filename of each .wav file.

Say, if the name is 32-45-65-44.wav, I need to get 45 as the label.

a = AudioList.from_folder(name_of_folder)
func = lambda o: int(o.split('-')[1])

I am using the above code, but this is throwing error - AttributeError: 'PosixPath' object has no attribute 'split'

Fastai uses PosixPath from pathlib so you can’t use split on that. You can either use one of the many methods available for them or just do str(o) to get the path as a string instead.

Look at how Lesson 1 pets is done. There’s a label_from_re (unsure if that’s in audio) where it does exactly that

1 Like

hey, couldn’t find label_from_re there.

str(o).split('-')[1] will work.

1 Like