bastibe / python-soundfile

SoundFile is an audio library based on libsndfile, CFFI, and NumPy
BSD 3-Clause "New" or "Revised" License
699 stars 107 forks source link

"File contains data in an unknown format." when loading ".wav" file with soundfile.read() #302

Open Aleksandr34nov opened 3 years ago

Aleksandr34nov commented 3 years ago

When using soundfile.read() to load ".wav" file I get: "RuntimeError: Error opening 'gruesome.wav': File contains data in an unknown format." I have already install "ffmpeg" and I don't know what to do. When I use librosa.load() it works okey, but I need to use soundfile.read() and it doesn't work. I have the same problem with other formats(".flac", "mp3", "wav"). How to solve the problem? Any idea? Code:

import os import librosa as lb import soundfile as sd import numpy as np audio, sr = sd.read("gruesome.wav")

Error: image

bastibe commented 3 years ago

This sounds like a problem with your version of libsndfile. How did you install soundfile?

leto19 commented 3 years ago

I'm having a similar issue to this but for FLAC files - I have a manual install of libsndfile, and FLAC itself in a non standard directory. ./configure for libsndfile reports FLAC as being installed. For me print(sf._libname) returns

libsndfile.so.1

and sf.available_formats() returns

{'AIFF': 'AIFF (Apple/SGI)', 'AU': 'AU (Sun/NeXT)', 'AVR': 'AVR (Audio Visual Research)', 'CAF': 'CAF (Apple Core Audio File)', 'HTK': 'H TK (HMM Tool Kit)', 'SVX': 'IFF (Amiga IFF/SVX8/SV16)', 'MAT4': 'MAT4 (GNU Octave 2.0 / Matlab 4.2)', 'MAT5': 'MAT5 (GNU Octave 2.1 / Mat lab 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': 'WAV EX (Microsoft)', 'WVE': 'WVE (Psion Series 3)', 'XI': 'XI (FastTracker 2)

Which means FLAC isn't supported by the version of libsndfile that my installation is using? How do I specify which version of libsndfile that the module uses?

bastibe commented 3 years ago

Soundfile first tries to load your system library. So put your compiled libsndfile somewhere on PATH, or in LD_LIBRARY_PATH, or in your current directory. Only when it can't find a system library will soundfile try its own.

BuaaAlban commented 3 years ago

same issue

leto19 commented 3 years ago

Soundfile first tries to load your system library. So put your compiled libsndfile somewhere on PATH, or in LD_LIBRARY_PATH, or in your current directory. Only when it can't find a system library will soundfile try its own.

Thanks for the response; turns out that libsndfile requires opus as well as flac to be already installed in order to work properly when installing from the source code. I've done this and FLAC now shows in soundfile.available_formats().