python-soundfile: Can't open FLAC file with read on macOS (get unimplemented format error)
Hi!
I got an issue when trying to open a FLAC file using the following simple code:
>>> import soundfile as sf
>>> data, sr = sf.read('test.flac')
That results in the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/anaconda3/envs/mqa/lib/python3.6/site-packages/soundfile.py", line 373, in read
subtype, endian, format, closefd) as f:
File "/usr/local/anaconda3/envs/mqa/lib/python3.6/site-packages/soundfile.py", line 740, in __init__
self._file = self._open(file, mode_int, closefd)
File "/usr/local/anaconda3/envs/mqa/lib/python3.6/site-packages/soundfile.py", line 1265, in _open
"Error opening {0!r}: ".format(self.name))
File "/usr/local/anaconda3/envs/mqa/lib/python3.6/site-packages/soundfile.py", line 1455, in _error_check
raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening '/Users/afuhrmann/Desktop/test.flac': File contains data in an unimplemented format.
The available formats don’t show FLAC:
>>> sf.available_formats()
{'AIFF': 'AIFF (Apple/SGI)', 'AU': 'AU (Sun/NeXT)', 'AVR': 'AVR (Audio Visual Research)', 'CAF': 'CAF (Apple Core Audio File)', 'HTK': 'HTK (HMM Tool Kit)', 'SVX': 'IFF (Amiga IFF/SVX8/SV16)', 'MAT4': 'MAT4 (GNU Octave 2.0 / Matlab 4.2)', 'MAT5': 'MAT5 (GNU Octave 2.1 / Matlab 5.0)', 'MPC2K': 'MPC (Akai MPC 2k)', 'PAF': 'PAF (Ensoniq PARIS)', 'PVF': 'PVF (Portable Voice Format)', 'RAW': 'RAW (header-less)', 'RF64': 'RF64 (RIFF 64)', 'SD2': 'SD2 (Sound Designer II)', 'SDS': 'SDS (Midi Sample Dump Standard)', 'IRCAM': 'SF (Berkeley/IRCAM/CARL)', 'VOC': 'VOC (Creative Labs)', 'W64': 'W64 (SoundFoundry WAVE 64)', 'WAV': 'WAV (Microsoft)', 'NIST': 'WAV (NIST Sphere)', 'WAVEX': 'WAVEX (Microsoft)', 'WVE': 'WVE (Psion Series 3)', 'XI': 'XI (FastTracker 2)'}
but the subformats with format flac does:
>>> sf.available_subtypes(format='FLAC')
{'PCM_S8': 'Signed 8 bit PCM', 'PCM_16': 'Signed 16 bit PCM', 'PCM_24': 'Signed 24 bit PCM'}
Also FLAC is in the supported formats in both soundfile.py and sndfile.h
SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
Also, FLAC files can be played in macOS.
Does anyone know how to resolve that issue?
Thanks in advance
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 23 (10 by maintainers)
Find a work around with the issue hope it might help out, still to try @mgeier solution with the def dummy_find_library() function,
but what I did was I uninstall librosa and it uninstalled all it dependent packages 😒 conda uninstall librosa -y
and I install soundfile and loaded the .flac file and it works. but when I install librosa again installed libsnfile and soundfile._libname by default picks and "/…/anaconda//libsndfile.so.1"* found in anaconda.
I uninstall just that package 😒 conda remove --force libndfile
soundfile._libname default to “libsnfile.so.1”, which works alongside librosa.
Hoping to get a far more better and accurate solution in the future.
This tells you from which file on your system the
libsndfile
library is loaded.The path you are getting points somewhere inside your Anaconda folder. It’s not the one distributed with the
soundfile
wheel package.There seem to be FLAC problems with the macOS version of the Anaconda package, see https://github.com/conda-forge/libsndfile-feedstock/issues/2 and https://github.com/librosa/librosa/pull/847#issuecomment-475044902. There doesn’t seem to be a resolution.
You should try to uninstall
libsndfile
withconda
, then it probably works.