How to replaced extracted audio files running in a for loop?

Hello Community,
I am trying to do some features extractions in m4a, trying to extract and replace several audios which are running in a for loop with the initial 'p'.
Audio_files(p).name consist of individual .m4a files running in the for loop with the initial 'p'.
I am running into some problems with my audiowrite line. How should I rewrite the line? What am I missing here? Thank you in advance! :)
[data,samp_rate] = audioread(Audio_files(p).name);
%% equations worked on the audio file and get s, the new starting point of the audio
startSample = s;
endSample = length(data);
extractedData = data(startSample:endSample);
audiowrite(Audio_files(p).name '.m4a', extractedData,fs );

 Accepted Answer

audiowrite cannot save the file in .mat format. Use extension of an audio file. Also use concotenation brackets [ ]
audiowrite([Audio_files(p).name '.wav'], extractedData,fs );

4 Comments

Hi Hamza, Thank you for your answer!
Would be glad if you could help with one more question regarding to this..
In my data, there are two columns. I am trying to use the second column.
If I just purely use the below code, the script will work on the first column,
how do I choose the second column, or insert data(:,end) to this code?
[data,samp_rate] = audioread(Audio_files(p).name);
%% equations worked on the audio file and get s, the new starting point of the audio
startSample = s;
endSample = length(data);
extractedData = data(startSample:endSample);
extractedData(1:2*samp_rate ) = [];
audiowrite(Audio_files(p).name '.m4a', extractedData,fs );
try this
[data,samp_rate] = audioread(Audio_files(p).name);
%% equations worked on the audio file and get s, the new starting point of the audio
startSample = s;
extractedData = data(:, 2); % choose 2nd column
extractedData(1:2*samp_rate ) = []; % delete first two seconds
audiowrite([Audio_files(p).name '.m4a'], extractedData,fs );

Sign in to comment.

More Answers (0)

Categories

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!