Clear Filters
Clear Filters

Audioread error "Undefined function 'wavread' for input arguments of type 'char'."

6 views (last 30 days)
I tried running the following code on versions R2020b, R2021a, R2022a both on matlab online and on desktop and get the same error. The following is in a for loop, below is the relevant code.
i=1:length(files
filename = files(i);
filelocation = ['audio/',filename.name]
[wave,Fs]=audioread(filelocation);
Error message:
Undefined function 'wavread' for input arguments of type 'char'.
Error in audioread (line 3)
[y,Fs] = wavread(filename);
Error in untitled (line 63)
[wave,Fs]=audioread(filelocation);
I did try running the audioread function separately with a single file and get the same error message. I'm at a total loss because this code worked totally fine for a friend using R2020b
  2 Comments
Maxine
Maxine on 12 May 2022
Yes, and I've also tried including the entire path written out and still get the same error,

Sign in to comment.

Answers (1)

Siraj
Siraj on 20 Sep 2023
Hi!
It appears that you are experiencing an issue while trying to read data from an audio file using the audioread function.
The issue might be specific to your environment or the specific audio file you are trying to read.
Check whether "filename.name" is a character array or a string scalar. Since the error message suggests that wavread” is not defined for type “char”, try using a string scalar for the filelocation.
You can use the fullfile function to construct the file path, which handles file separators in a platform-independent way. Refer to the following link to know more about “fullfile” function.
To provide a clearer understanding, I have included an example code snippet below:
% Specify the filename
filename = "handle1.wav";
% Construct the file location using the fullfile function
filelocation = fullfile("Audio", filename);
% Read the audio file using the audioread function
[wave, Fs] = audioread(filelocation);
Hope this helps.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!