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

7 次查看(过去 30 天)
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

回答(1 个)

Siraj
Siraj 2023-9-20
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.

类别

Help CenterFile Exchange 中查找有关 Measurements and Spatial Audio 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by