Need help fixing Audio Read Error reading in a WAV file

4 views (last 30 days)
I keep getting an error trying to read in a WAV file that says: Error using audioread (line 127) Range requested is greater than the total number of samples in the file. TotalSamples is 0.
I am trying to plot the time domain and the FFT of WAV file by the frequency domain.I have looked online for similar errors, but have found nothing. I have my code below.
file = 'wav_tester_new';
[y, Fs] = audioread(file); %read in WAV file
sound(y, Fs); %play the WAV file
t=0:1/Fs:(length(y)-1)/Fs; %sampling frequency
figure(1);
plot(t,y); %plot WAV file by time domain array t
title('WAV File in Time Domain');
ylabel('Amplitude');
xlabel('Length (in seconds)');
n=length(y)-1;
f=0:Fs/n:Fs; %frequency domain
wavefft=abs(fft(y)); %FFT of WAV file
figure(2);
plot(f,wavefft); %plot the FFT of WAV file by the frequency domain array f
xlabel('Frequency in Hz');
ylabel('Magnitude');
title('WAV File FFT');

Answers (2)

Star Strider
Star Strider on 6 Jun 2014
The audioread function needs the file extension as well. (The soon-to-be-obsolete wavread assumes a ‘.wav’ file.)
See if:
file = 'wav_tester_new.wav';
improves things.
  2 Comments
Jennifer
Jennifer on 6 Jun 2014
I tried this, but instead got the error Error using audioread (line 74) The filename specified was not found in the MATLAB path.
Star Strider
Star Strider on 6 Jun 2014
You need to either:
  1. put your file in your user directory ( ‘C:\. ..\Documents\MATLAB\...’ in Windows ) or
  2. include the full path to the file in the file name.

Sign in to comment.


ARUN PRATAP SINGH
ARUN PRATAP SINGH on 15 Jun 2017
audioread is no longer available to play wav file. Just use wavread instead of that. I hope it helps.
  3 Comments
zina shalchi
zina shalchi on 25 Sep 2020
wavread is not supporeted any more
[Size, Sfreq, NbS, opt] = wavread (File, 'size');
and when I replace it with audioread I got errors too many parameters
[Size, Sfreq, NbS, opt] = audioread (File, 'size');
do you know how to solve this problem please?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!