question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Librosa 0.7.1 load() gives Malformed 'fmt ' chunk (worked in 0.7.0)

See original GitHub issue

Description

In v0.7.0 company_sensitive.wav worked, but with v0.7.1 throws an “Malformed 'fmt ’ chunk.” error. Unfortunately I’m not able to provide said file, but I’ll try to find another one / remove sensitive data later.

Steps/Code to Reproduce

import librosa

aud, sr = librosa.load(Path("/egg/foo.wav"), sr=None, mono=False)

Expected Results

No output, and aud to contain numpy formatted audio data.

Actual Results

Error opening '/egg/foo.wav': Error in WAV/W64/RF64 file. Malformed 'fmt ' chunk.
Traceback (most recent call last):
  File "/opt/conda/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 922, in _run_raw_task
    result = task_copy.execute(context=context)
  File "/opt/conda/lib/python3.7/site-packages/airflow/operators/python_operator.py", line 113, in execute
    return_value = self.execute_callable()
  File "/opt/conda/lib/python3.7/site-packages/airflow/operators/python_operator.py", line 118, in execute_callable
    return self.python_callable(*self.op_args, **self.op_kwargs)
  File "/usr/local/airflow/dags/scripts_processing/*company*/audio_parser.py", line 187, in start
    return task_class.audio_parser(kwargs['params']["expected_sr"])
  File "/usr/local/airflow/dags/scripts_processing/*company*/audio_parser.py", line 65, in audio_parser
    audio_concat, file_metadata = self.combine_audio(audio_folder[0], sr_expected=expected_sr)
  File "/usr/local/airflow/dags/scripts_processing/*company*/audio_parser.py", line 109, in combine_audio
    aud, sr = librosa.load(audio_file, sr=None, mono=False)
  File "/opt/conda/lib/python3.7/site-packages/librosa/core/audio.py", line 149, in load
    six.reraise(*sys.exc_info())
  File "/opt/conda/lib/python3.7/site-packages/six.py", line 696, in reraise
    raise value
  File "/opt/conda/lib/python3.7/site-packages/librosa/core/audio.py", line 129, in load
    with sf.SoundFile(path) as sf_desc:
  File "/opt/conda/lib/python3.7/site-packages/soundfile.py", line 627, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "/opt/conda/lib/python3.7/site-packages/soundfile.py", line 1182, in _open
    "Error opening {0!r}: ".format(self.name))
  File "/opt/conda/lib/python3.7/site-packages/soundfile.py", line 1355, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening '/egg/foo.wav': Error in WAV/W64/RF64 file. Malformed 'fmt ' chunk.

Versions

Using Anaconda

Broken v0.7.1

Linux-4.15.0-65-generic-x86_64-with-debian-buster-sid Python 3.7.5 (default, Oct 25 2019, 15:51:11) [GCC 7.3.0] NumPy 1.17.3 SciPy 1.3.2 librosa 0.7.1

Working v0.7.0

Linux-4.15.0-65-generic-x86_64-with-debian-buster-sid Python 3.7.5 (default, Oct 25 2019, 15:51:11) [GCC 7.3.0] NumPy 1.17.3 SciPy 1.3.1 librosa 0.7.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
NumesSanguiscommented, Nov 18, 2019

The following steps reproduce the error in 0.7.1, but not in 0.7.0

  1. Download a sample .mp3 file to your current folder: curl https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3 --output sample.mp3
  2. Create 2 conda envs with version 0.7.0 and 0.7.1 (2x):
conda create --name librosa070 python=3.7  # librosa071
conda activate librosa070  # librosa071
conda install -c conda-forge librosa=0.7.0  # 0.7.1
  1. Creation a python file librosa_regression.py with the following code:
from pathlib import Path
import librosa

import soundfile as sf
print("PySoundFile", sf.__version__)

import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
import scipy; print("SciPy", scipy.__version__)
import librosa; print("librosa", librosa.__version__)

aud_file = "sample.mp3"
aud, sr = librosa.load(Path(aud_file), sr=None, mono=False)
print(aud.shape)
  1. Librosa v0.7.0: Works
$ python librosa_regression.py 
PySoundFile 0.10.2
Linux-4.15.0-70-generic-x86_64-with-debian-buster-sid
Python 3.7.5 (default, Oct 25 2019, 15:51:11) 
[GCC 7.3.0]
NumPy 1.17.3
SciPy 1.3.2
librosa 0.7.0
(2, 870191)
  1. Librosa v0.7.1: Broken
$ python librosa_regression.py 
PySoundFile 0.10.2
Linux-4.15.0-70-generic-x86_64-with-debian-buster-sid
Python 3.7.5 (default, Oct 25 2019, 15:51:11) 
[GCC 7.3.0]
NumPy 1.17.3
SciPy 1.3.2
librosa 0.7.1
Traceback (most recent call last):
  File "librosa_regression.py", line 14, in <module>
    aud, sr = librosa.load(Path(aud_file), sr=None, mono=False)
  File "/home/*user*/anaconda3/envs/librosa071/lib/python3.7/site-packages/librosa/core/audio.py", line 149, in load
    six.reraise(*sys.exc_info())
  File "/home/*user*/anaconda3/envs/librosa071/lib/python3.7/site-packages/six.py", line 696, in reraise
    raise value
  File "/home/*user*/anaconda3/envs/librosa071/lib/python3.7/site-packages/librosa/core/audio.py", line 129, in load
    with sf.SoundFile(path) as sf_desc:
  File "/home/*user*/anaconda3/envs/librosa071/lib/python3.7/site-packages/soundfile.py", line 627, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "/home/*user*/anaconda3/envs/librosa071/lib/python3.7/site-packages/soundfile.py", line 1182, in _open
    "Error opening {0!r}: ".format(self.name))
  File "/home/*user*/anaconda3/envs/librosa071/lib/python3.7/site-packages/soundfile.py", line 1355, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'sample.mp3': File contains data in an unknown format.

$ file sample.mp3 
sample.mp3: Audio file with ID3 version 2.3.0, contains:MPEG ADTS, layer III, v1, 224 kbps, 32 kHz, Stereo
0reactions
NumesSanguiscommented, Nov 21, 2019

@bmcfee It was indeed pathlib!

Since the error is not very helpful to find the source of the problem, sf.SoundFile(path) does accept pathlib, and it is better to not push the responsibility to fix it on the user, I added a converter from pathlib object to String (see pull request above). Basically it comes down to: Python 3.6+: path = os.fspath(path) Python 3.4+: path = str(path)

When Librosa 0.8.x comes around, this temporary fix can be removed, and only this has to change (also mentioned in the pull request):

import pathlib

# if isinstance(path, six.string_types):  -->
if isinstance(path, (six.string_types, pathlib.PurePath)):

https://github.com/librosa/librosa/blob/7feb1efdbc9f0c61fbee623fc03fa62410113927/librosa/core/audio.py#L142-L164

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced I/O Use Cases — librosa 0.10.0.dev0 documentation
Advanced I/O Use Cases¶. This section covers advanced use cases for input and output which go beyond the I/O functionality currently provided by...
Read more >
April 2018 - devel - Fedora Mailing-Lists
I have the yarrow's iso files on my HD in a RH9 system. Let's say I want to upgrade selected packages using an...
Read more >
Issues-librosa/librosa - PythonTechWorld
Librosa 0.7.1 load() gives Malformed 'fmt ' chunk (worked in 0.7.0). 888. Description In v0.7.0 company_sensitive.wav worked, but with v0.7.1 throws an ...
Read more >
Not able to install librosa - Stack Overflow
First, update setuptools and wheel python3 -m pip install --upgrade pip setuptools wheel. Second python setup.py bdist_wheel. Try to install the ...
Read more >
librosa - PyPI
Hints for the Installation. librosa uses soundfile and audioread to load audio files. Note that soundfile does not currently support MP3 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found