votes up 3

File format (repr(str1)) not understood. Only 'RIFF' and 'RIFX' supported.

Package:
scipy
github stars 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?

ūüė≤ Agile task management is now easier than calling a taxi. #Tracklify
ūüôŹ Scream for help to Ukraine
Today, 8th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this ūüė†, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 1 votes down

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

Aug 03, 2022 kellemnegasi answer
kellemnegasi 30.6k

Add a possible fix

Please authorize to post fix