Using Librosa in Python to Interpret Audio: A Guide

In case librosa returns an output that needs scaling, it can be multiplied by a scaling factor and converted to the same data type as the output of scipy wave reader to ensure consistent value ranges. An example code for reading an audio file is causing an error at line 4 and it is unclear what the issue could be. Both librosa and scipy are installed but are not functioning properly.


Question:

While attempting to read an
audio file
using Librosa, I encountered an error.

FileNotFoundError: [WinError 2] The system cannot find the file specified

The instructions stated that I must install

ffmpeg

, but it proved to be ineffective in resolving the issue. On the other hand,

ffmpeg

was successfully installed at

ffmpeg in c:programdataanaconda3libsite-packages (1.4)


.

This is a code example that I am utilizing to access a sample audio file.

import librosa
filename = librosa.util.example_audio_file()
print(filename)
y, sr = librosa.load(filename)

The error is being thrown on line 4.

C:ProgramDataAnaconda3libsite-packageslibrosautilexample_dataKevin_MacLeod_-_Vibe_Ace.ogg
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
 in 
      1 filename = librosa.util.example_audio_file()
      2 print(filename)
----> 3 y, sr = librosa.load(filename)
C:ProgramDataAnaconda3libsite-packageslibrosacoreaudio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    117 
    118     y = []
--> 119     with audioread.audio_open(os.path.realpath(path)) as input_file:
    120         sr_native = input_file.samplerate
    121         n_channels = input_file.channels
C:ProgramDataAnaconda3libsite-packagesaudioread__init__.py in audio_open(path, backends)
    105     """
    106     if backends is None:
--> 107         backends = available_backends()
    108 
    109     for BackendClass in backends:
C:ProgramDataAnaconda3libsite-packagesaudioread__init__.py in available_backends()
     84 
     85     # FFmpeg.
---> 86     if ffdec.available():
     87         result.append(ffdec.FFmpegAudioFile)
     88 
C:ProgramDataAnaconda3libsite-packagesaudioreadffdec.py in available()
    106         stdout=subprocess.PIPE,
    107         stderr=subprocess.PIPE,
--> 108         creationflags=PROC_FLAGS,
    109     )
    110     proc.wait()
C:ProgramDataAnaconda3libsite-packagesaudioreadffdec.py in popen_multiple(commands, command_args, *args, **kwargs)
     92         cmd = [command] + command_args
     93         try:
---> 94             return subprocess.Popen(cmd, *args, **kwargs)
     95         except OSError:
     96             if i == len(commands) - 1:
C:ProgramDataAnaconda3libsubprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    767                                 c2pread, c2pwrite,
    768                                 errread, errwrite,
--> 769                                 restore_signals, start_new_session)
    770         except:
    771             # Cleanup if the child failed starting.
C:ProgramDataAnaconda3libsubprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1170                                          env,
   1171                                          os.fspath(cwd) if cwd is not None else None,
-> 1172                                          startupinfo)
   1173             finally:
   1174                 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified

I’m uncertain about the issue at hand. Despite the installation of both

Librosa

and

ffmpeg

, neither seem to be functioning. Please inform me if additional information is necessary.


Solution:

The solution involves opening

anaconda

with the necessary

admin

permission, followed by executing a specific command.

conda install -c conda-forge librosa

The issue at hand is that

pip install librosa

did not function properly, requiring the installation of

librosa

via

conda install

.

Hope it will help future visitor.

Frequently Asked Questions