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

조회 수: 24 (최근 30일)
Diego Bianchera
Diego Bianchera 2022년 8월 14일
댓글: Diego Bianchera 2022년 8월 23일
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.

채택된 답변

Keerthana Ramesh
Keerthana Ramesh 2022년 8월 17일
이동: Walter Roberson 2022년 8월 17일
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
Diego Bianchera
Diego Bianchera 2022년 8월 23일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by