I'm trying to go into a file full of .m4a audio files, retrieve each one and use the audioread() for each audiofile and output the result of each one in an array

11 views (last 30 days)
Like the Title says, I'm a new user that is trying to read through each file,modify it, and to write it out to an array.
Currently I have 51 audiofiles in a folder where I want to read the audiofile with
[xc5,Fs] = audioread('C4.m4a');
and then process the audiofile with
xc5_feat = processing(xc5,Fs);
So this would take a while for each file, is there a way to do this to every audiofile in my mainfile and put the result in an array?
Currently I have it saving to another folder but could I make this an array?
Heres the code I currently have but I keep getting an error message that I'll put below.
I have an audioread() but I would also like to add in my function 'processing' into it as well.
Thank you all!
clear all
outputFolder = 'C:Desktop\University\School\Fall 2021\Machine Learning\Project\C_sound_files'
for k= 1:51
% OPTION 1: Create a mat filename, and load it into a structure called matData.
matFileName = sprintf('C%d.m4a', k);
if isfile(matFileName)
matData = audioread(matFileName);
outputFilename = sprintf('C%d.m4a', outputFolder, k);
save(outputFilename, 'matData')
fprintf('File %s does not exist.\n', matFileName);
%%%%%% THE ERROR MESSAGE %%%%%%%%
Error using save
Unable to write file
Invalid argument.
Error in Full_audio_read (line 17)
save(outputFilename, 'matData')

Answers (1)

Kiran Felix Robert
Kiran Felix Robert on 9 Dec 2021
Hi Nicholas,
The error message is due to the file name you have created in outputFilename.
Change the line as follows to get a working loop.
outputFilename = sprintf('C%d.m4a',k);


Find more on Audio I/O and Waveform Generation 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!