How can I process OPUS format with Librosa?

1k views Asked by At

I am trying to generate spectrograms by using Librosa. When I was working with the .wav format file it was working fine. But I changed the format to OPUS audio codec and tried to run the same file, it give me below error.

X, sample_rate = librosa.load('TESS emotion datasets opus/OAF_Fear/OAF_beg_fear.opus', res_type='kaiser_fast', duration = 2.5, sr = 22050*2, offset = 0.5)

Error generated:

RuntimeError                              Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    145     try:
--> 146         with sf.SoundFile(path) as sf_desc:
    147             sr_native = sf_desc.samplerate

~/anaconda3/lib/python3.6/site-packages/soundfile.py in __init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
    628                                          format, subtype, endian)
--> 629         self._file = self._open(file, mode_int, closefd)
    630         if set(mode).issuperset('r+') and self.seekable():

~/anaconda3/lib/python3.6/site-packages/soundfile.py in _open(self, file, mode_int, closefd)
   1183         _error_check(_snd.sf_error(file_ptr),
-> 1184                      "Error opening {0!r}: ".format(self.name))
   1185         if mode_int == _snd.SFM_WRITE:

~/anaconda3/lib/python3.6/site-packages/soundfile.py in _error_check(err, prefix)
   1356         err_str = _snd.sf_error_number(err)
-> 1357         raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
   1358 

RuntimeError: Error opening 'TESS emotion datasets opus/OAF_Fear/OAF_beg_fear.opus': File contains data in an unimplemented format.

During handling of the above exception, another exception occurred:

NoBackendError                            Traceback (most recent call last)
<ipython-input-39-1372f02f676e> in <module>()
----> 1 X, sample_rate = librosa.load('TESS emotion datasets opus/OAF_Fear/OAF_beg_fear.opus', res_type='kaiser_fast', duration = 2.5, sr = 22050*2, offset = 0.5)

~/anaconda3/lib/python3.6/site-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    161         if isinstance(path, (str, pathlib.PurePath)):
    162             warnings.warn("PySoundFile failed. Trying audioread instead.")
--> 163             y, sr_native = __audioread_load(path, offset, duration, dtype)
    164         else:
    165             raise (exc)

~/anaconda3/lib/python3.6/site-packages/librosa/core/audio.py in __audioread_load(path, offset, duration, dtype)
    185 
    186     y = []
--> 187     with audioread.audio_open(path) as input_file:
    188         sr_native = input_file.samplerate
    189         n_channels = input_file.channels

~/anaconda3/lib/python3.6/site-packages/audioread/__init__.py in audio_open(path, backends)
    114 
    115     # All backends failed!
--> 116     raise NoBackendError()

NoBackendError: 

I tried to install ffmpeg and gstreamer as suggested by some previous answers and github page of Librosa. But it didn't solve the problem.

On the contrary, this audio format works well when I run the same code in Google Colab.

What can be the reason of this error? How to solve it?

0

There are 0 answers