File format (repr(str1)) not understood. Only 'RIFF' and 'RIFX' supported.
Package:
scipy
8546
Exception Class:
ValueError
Raise code
is_big_endian = False
fmt = '<I'
elif str1 == b'RIFX':
is_big_endian = True
fmt = '>I'
else:
# There are also .wav files with "FFIR" or "XFIR" signatures?
raise ValueError(f"File format {repr(str1)} not understood. Only "
"'RIFF' and 'RIFX' supported.")
# Size of entire file
file_size = struct.unpack(fmt, fid.read(4))[0] + 8
str2 = fid.read(4)
if str2 != b'WAVE':
Comment explaining raise
There are also .wav files with "FFIR" or "XFIR" signatures?
Links to the raise (1)
https://github.com/scipy/scipy/blob/e4b3e6eb372b8c1d875f2adf607630a31e2a609c/scipy/io/wavfile.py#L521Ways to fix
This happens when a file with the wrong format is used.
Code that reproduces the exception:
from os.path import dirname, join as pjoin
from scipy.io import wavfile
import scipy.io
data_dir = pjoin(dirname(scipy.io.__file__), 'tests', 'data')
wav_fname = pjoin(data_dir, 'fortran-sf8-1x1x7.dat')
samplerate, data = wavfile.read(wav_fname)
print(f"number of channels = {data.shape[1]}")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-16-c418b6b3e727> in <module>() 4 data_dir = pjoin(dirname(scipy.io.__file__), 'tests', 'data') 5 wav_fname = pjoin(data_dir, 'fortran-sf8-1x1x7.dat') ----> 6 samplerate, data = wavfile.read(wav_fname) 7 print(f"number of channels = {data.shape[1]}")
/usr/local/lib/python3.7/dist-packages/scipy/io/wavfile.py in read(filename, mmap) 648 649 try: --> 650 file_size, is_big_endian = _read_riff_chunk(fid) 651 fmt_chunk_received = False 652 data_chunk_received = False
/usr/local/lib/python3.7/dist-packages/scipy/io/wavfile.py in _read_riff_chunk(fid) 519 else: 520 # There are also .wav files with "FFIR" or "XFIR" signatures? --> 521 raise ValueError(f"File format {repr(str1)} not understood. Only " 522 "'RIFF' and 'RIFX' supported.") 523
ValueError: File format b'8\x00\x00\x00' not understood. Only 'RIFF' and 'RIFX' supported.
Fixed version of the code:
from os.path import dirname, join as pjoin
from scipy.io import wavfile
import scipy.io
data_dir = pjoin(dirname(scipy.io.__file__), 'tests', 'data')
wav_fname = pjoin(data_dir, 'test-44100Hz-2ch-32bit-float-be.wav')
samplerate, data = wavfile.read(wav_fname)
print(f"number of channels = {data.shape[1]}")
number of channels = 2
Add a possible fix
Please authorize to post fix