Clear Filters
Clear Filters

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

3 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')
else
fprintf('File %s does not exist.\n', matFileName);
end
end
%%%%%% THE ERROR MESSAGE %%%%%%%%
Error using save
Unable to write file
C67.m4aC58.m4aC68.m4aC101.m4aC115.m4aC107.m4aC116.m4aC111.m4aC112.m4aC92.m4aC85.m4aC110.m4aC105.m4aC118.m4aC101.m4aC114.m4aC115.m4aC105.m4aC116.m4aC121.m4aC32.m4aC111.m4aC102.m4aC32.m4aC72.m4aC111.m4aC117.m4aC115.m4aC116.m4aC111.m4aC110.m4aC92.m4aC71.m4aC114.m4aC97.m4aC100.m4aC117.m4aC97.m4aC116.m4aC101.m4aC32.m4aC83.m4aC99.m4aC104.m4aC111.m4aC111.m4aC108.m4aC92.m4aC70.m4aC97.m4aC108.m4aC108.m4aC32.m4aC50.m4aC48.m4aC50.m4aC49.m4aC92.m4aC77.m4aC97.m4aC99.m4aC104.m4aC105.m4aC110.m4aC101.m4aC32.m4aC76.m4aC101.m4aC97.m4aC114.m4aC110.m4aC105.m4aC110.m4aC103.m4aC92.m4aC70.m4aC105.m4aC110.m4aC97.m4aC108.m4aC32.m4aC80.m4aC114.m4aC111.m4aC106.m4aC101.m4aC99.m4aC116.m4aC92.m4aC67.m4aC95.m4aC115.m4aC111.m4aC117.m4aC110.m4aC100.m4aC95.m4aC102.m4aC105.m4aC108.m4aC101.m4aC115.m4aC1.m4a:
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);

Categories

Find more on Code Generation and Deployment 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!