0

I'm starting learning basic feature extraction with librosa and was trying reading and storing ten kick drums with pathlib, but it doesn't work since I always getting an encoding error, where as there is no error without pathlib.

I tried changing the path, updating every imported library very often, using wav instead of mp3 but had no further idea.

My code:

%matplotlib inline
from pathlib import Path
import numpy, scipy, matplotlib.pyplot as plt, sklearn, urllib, IPython.display as ipd
import librosa, librosa.display
kick_signals = [
    librosa.load(p)[0] for p in Path().glob('audio/drum_samples/train/kick_*.mp3')
]

Error messages:

RuntimeError: Error opening 'audio/techno-nine_o_three.mp3': File contains data in an unknown format.

and

AttributeError: 'PosixPath' object has no attribute 'encode'

I would be very thankful, if you would and could help me.

mandaleybro
  • 23
  • 2
  • 7

2 Answers2

3

You can convert the PossixPath object to a string, using p.as_posix()

Example:

p = Path(file_path)
p.as_posix()
Anurag A S
  • 725
  • 10
  • 23
0

Try:

kick_signals = [
    librosa.load(p.absolute())[0] for p in Path().glob('audio/drum_samples/train/kick_*.mp3')
]

That way you pass a string instead of a PosixPath to librosa.

If that does not fix it, check your mp3 file. Does it play in a regular player? If not, please post the whole error message (stacktrace). Perhaps librosa's dependencies aren't installed properly.

Hendrik
  • 5,085
  • 24
  • 56