0

Import library

import librosa
import librosa.display
filename = get_audio_path(AUDIO_DIR, 36096) 
y, sr = librosa.load(filename)
print(len(y),sr)

With get_audio_path(AUDIO_DIR, 36096) the function to get the path of the audio (.mp3) 36096

output

> NoBackendError                            Traceback (most recent call last) <ipython-input-12-e5b91455e58d> in <module>
>       1 filename = get_audio_path(AUDIO_DIR, 36096)
> ----> 2 y, sr = librosa.load(filename)
>       3 print(len(y),sr)
>       4 each_file = filename.split('/')[-1]
>       5 genre_name = each_file.split('.')[0]
> 
> ~\Anaconda3\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
>     110 
>     111     y = []
> --> 112     with audioread.audio_open(os.path.realpath(path)) as input_file:
>     113         sr_native = input_file.samplerate
>     114         n_channels = input_file.channels
> 
> ~\Anaconda3\lib\site-packages\audioread\__init__.py in audio_open(path, backends)
>     114 
>     115     # All backends failed!
> --> 116     raise NoBackendError()
> 
> NoBackendError:

any help please !

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Adil chakhtouna
  • 95
  • 1
  • 2
  • 10
  • Possible duplicate: https://stackoverflow.com/questions/47870412/librosa-cant-open-wav-created-by-librosa – tripleee Jun 24 '20 at 12:19

2 Answers2

0

You can load the audio file path directly into librosa and specify the given sample rate and whether it's mono or stereo. No need for the get_audio_path function.

import librosa
audio_path='C:/Users/audio/name.mp3'
y, sr = librosa.load(audio_path, sr=44100, mono=False)

Documentation on librosa.load is here: https://librosa.org/librosa/0.5.1/generated/librosa.core.load.html?highlight=load#librosa.core.load

If you need to get an audio file in a given path you can use os. This will get all the mp3 files in a given path:

import os

AUDIO_DIR = "C:/Users/my/audio/path"
all_mp3s_paths = [os.path.join(AUDIO_DIR, file) for file in os.listdir(AUDIO_DIR) if os.path.splitext(file)[-1] == ".mp3"]
Eugene Upston
  • 196
  • 1
  • 3
  • The 2 methods together do not work, I have this error FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\adil\\Desktop\\codes\\PROJ 1\\fma_small\\036\\036\\036096.mp3' – Adil chakhtouna Jun 24 '20 at 16:26
  • have you checked to see if that exact path exists? – Eugene Upston Jun 25 '20 at 09:57
  • Yes the path is correct. RuntimeError: Error opening '/home/ub10/Desktop/PROJ 1/fma_small/036/036096.mp3': File contains data in an unknown format. – Adil chakhtouna Jun 25 '20 at 23:25
  • O okay I would try updating librosa to the most recent version. Also are you able to load that file into a sound editor? – Eugene Upston Jun 26 '20 at 07:13
0

Here is the answer that I found:

  1. You don't need to use the get_audio_path function.

    import librosa
    import librosa.display
    
    filename = 'C:/Users/audio/name.mp3' # make sure to add extension .wav or anything
    y, sr = librosa.load(filename)
    print(len(y), sr)
    
  2. If the problem still occurs, recheck your audio data set path.

Ivan
  • 34,531
  • 8
  • 55
  • 100