Reputation: 175
import librosa
import librosa.display
import IPython.display
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.font_manager as fm
audio_path = 'rec.wav'
y, sr = librosa.load(audio_path)
I tried to load the audio file into librosa. So I wrote the code like that. But I get the error "File contains data in an unknown format", "File contains data in an unknown format".
I searched on Google and I was told to install ffmpeg. So I installed ffmpeg but still get the error
What's wrong? (I guess there is a problem with the encoding.........)
all error messege:
Traceback (most recent call last):
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 129, in load
with sf.SoundFile(path) as sf_desc:
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 629, in __init__
self._file = self._open(file, mode_int, closefd)
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 1184, in _open
"Error opening {0!r}: ".format(self.name))
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\soundfile.py", line 1357, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'rec.mp3': File contains data in an unknown format.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/****/PycharmProjects/pitch_project_/pitdetec.py", line 12, in <module>
y, sr = librosa.load(audio_path)
File "C:\Users\*****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 147, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\librosa\core\audio.py", line 171, in __audioread_load
with audioread.audio_open(path) as input_file:
File "C:\Users\****\AppData\Local\Programs\Python\Python36\lib\site-packages\audioread\__init__.py", line 116, in audio_open
raise NoBackendError()
audioread.exceptions.NoBackendError
try:
audio_path = 'C:/Users/ddolcju/PycharmProjects/pitch_project/rec.mp3'
Upvotes: 8
Views: 21295
Reputation: 1080
I also had this problem and the issue was that I had only partially downloaded the targetted .wav
file and it was therefore corrupted. Once I re-downloaded the file and tried again it worked fine. The error was a bit misleading in my case because the backend was available and working. As such, if none of the suggestions here work, try loading your target file in a music player to confirm its veracity.
Upvotes: 0
Reputation: 2949
In ubuntu I resolved it by following command
sudo apt update
sudo apt install ffmpeg
pip install ffmpeg
did not worked for me
Upvotes: 6
Reputation: 321
There are few things you need to check:
librosa
can't read mp3 files directly so it tries to use the audioread
package.
Audioread
tries to utilise a number of different packages that may or may not be installed. One of those is ffmpeg
.
However it uses FFmpeg
'via its command-line interface'. I think this is the reason that pip
installing FFmpeg doesn't work. It needs the ffmpeg.exe
file.
You can download the ffmpeg
installer from here
After it is installed make sure you can start ffmpeg
from the command line (type ffmpeg -h
). You will probably need to add the path to the install folder (eg c:\ffmpeg\bin
) to the Windows path.
Finally, make sure to restart your IDE. Visual Studio Code probably won't recognise the new path until after a reset.
Upvotes: 10
Reputation: 786
Upvotes: 0
Reputation: 59
I'm assuming that you solved your problem, but if anyone else has this problem:
I installed ffmpeg (the following code) and it worked.
pip install ffmpeg
Upvotes: 2
Reputation: 183
I got the same problem on windows 10, after installing ffmpeg and configuring it to PATH, it works. Need restart a python session.
Upvotes: 2