Need help fixing Audio Read Error reading in a WAV file
4 views (last 30 days)
Show older comments
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');
1 Comment
Answers (2)
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
Star Strider
on 6 Jun 2014
You need to either:
- put your file in your user directory ( ‘C:\. ..\Documents\MATLAB\...’ in Windows ) or
- include the full path to the file in the file name.
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
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?
Walter Roberson
on 25 Sep 2020
You can use audioinfo() https://www.mathworks.com/help/releases/R2015b/matlab/ref/audioinfo.html to get that kind of information.
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!