Problem reading wav files: error in audioread (line 137)

24 views (last 30 days)
Hi everyone,
I'm having an issue reading .wav files using audioread function and I get the following message every time:
Error using audioread>readaudio
File could not be read due to an unexpected error. Reason: Error in WAV file. No 'data' chunk marker.
Error in audioread (line 137)
[y, Fs] = readaudio (filename, range, datatype);
Even audioinfo fails to read the files, with the following error:
Error using audioinfo>extractinfo
File could not be read due to an unexpected error. Reason: Error in WAV file. No 'data' chunk marker.
Error in audioinfo (line 91)
info = extractinfo(filename);
I am sure the syntax and the rest of the code is fine as it works in Matlab Online, but it doesn't work in the desktop application.
I suspect it may be the particular sample rate they have, which is 46875 and which I (sadly) cannot change.
Is there any compatibility issue with audioread regarding sample rates, that you know of? Is there anything I can do except keep on using the online version of Matlab to make it work?
Thank you.

Accepted Answer

Keerthana Ramesh
Keerthana Ramesh on 17 Aug 2022
Moved: Walter Roberson on 17 Aug 2022
Hi,
This error of “File could not be read due to an unexpected error. Reason: Error in WAV file. No 'data' chunk marker” could be caused by the .wav file not abiding by the standardized format. The function 'audioread' relies on Windows Media Foundation WMF and can only read the standard format.
The workaround requires editing the bytes of the wav file. The following code helps in deleting the extra bytes and converting the .wav file to the standard format:
>> loc = strfind( bytes.', uint8('data') ); % Find where the 'data' keyword is.
>> bytes( 37:loc-1 ) = []; % Delete the extra bytes.
>> f = fopen( 'tmp.wav', 'w' );
>> fwrite( f, bytes, '*uint8' ); % Write the new byte sequence.
>> fclose( f );
>> [y, Fs] = audioread( 'tmp.wav' ); % Read the audio file.
WMF expects bytes 37-40 to store the keyword 'data', so the extra bytes between 37 and the first byte of the keyword need to be deleted.
I hope the above workaround solves the issue. If it does not, may I please know the MATLAB version you are using?
Thanks,
Keerthana
  1 Comment
Diego Bianchera
Diego Bianchera on 23 Aug 2022
I'm sorry if this seems trivial, but I have issues understanding the use of bytes.' in strfind and I have troubles making this work. I'm reading documentation at the moment and making an attempt. If I find a solution to my problem I will post the final code I used.
I really appreciate the input you gave me. I think I'm heading in the right direction. Thanks a lot.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!