- clear frame at the beginning of the loop otherwise the next file operation may be corrupted by what you have done in the previous iteration
- also use absolute path naming (more robust) , so use fullfile
Audios doesn't looping right
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to deleting silence in audios. this code is just work fine when I'm tryng it in one single audio. But, I've 100 audio left. what I'm tryng to do is to get first audio then remove silnce then save audio with new downloaded audiofile from matlab. but what happens in the attached code is shuffling audios and every new file sound downloaded have 2 or more from the original file audios.
clc;
clear all;
C = dir('*.wav');
for i=1:1:length(C)
[data,fs]=audioread(C(i).name);
data = data(1:end,1)/max(data(1:end,1));
% do framing
f_d = 0.25;
f_size = round(f_d * fs);
n = length(data);
n_f = floor(n/f_size); %no. of frames
temp = 0;
for j = 1 : n_f
frames(j,:) = data(temp + 1 : temp + f_size);
temp = temp + f_size;
end
% silence removal based on max amplitude
m_amp = abs(max(frames,[],2)); % find maximum of each frame
id = find(m_amp > 0.03); % finding ID of frames with max amp > 0.03
fr_ws = frames(id,:); % frames without silence
data_r = reshape(fr_ws',1,[]);
plot(data_r); title('speech without silence');
%saving the new audiofile
write_filename = "Silence_" +num2str(i)+".wav";
audiowrite('C:\Users\Mahmoud El-Moghazi\Desktop\Internship\AudioData\'+write_filename,data_r,fs);
end
what i want is looping in all audios ONE BY ONE then remove silence thene download it without inseting any other audio files.
0 Kommentare
Antworten (1)
Mathieu NOE
am 23 Aug. 2022
hello
I a not sure what you mean by "download " audio files
I interpreted your post as simply looping over a folder and store the new audio files
IMHO, it's better to put them in a separate output folder (so I created the /out for that purpose)to avoid any mix up between original and processed files (that may be reprocessed by inadvertance).
other suggestions :
here the modified code :
clc;
clearvars;
folder= pwd; % put here folder where wav files are
folder_out = [folder '\out']; % output folder
C=dir(fullfile(folder,'*.wav')); %list all .wavs in folder
nFiles=numel(C);
for i= 1:nFiles
% clear some data first
clear frames
% load new data
fname = C(i).name;
[data,fs]=audioread(fullfile(folder,fname));
data = data(:,1)/max(data(:,1));
% do framing
f_d = 0.25;
f_size = round(f_d * fs);
n = length(data);
n_f = floor(n/f_size); %no. of frames
temp = 0;
for j = 1 : n_f
frames(j,:) = data(temp + 1 : temp + f_size);
temp = temp + f_size;
end
% silence removal based on max amplitude
m_amp = abs(max(frames,[],2)); % find maximum of each frame
id = find(m_amp > 0.03); % finding ID of frames with max amp > 0.03
fr_ws = frames(id,:); % frames without silence
data_r = reshape(fr_ws',1,[]);
subplot(211),plot(data);
subplot(212),plot(data_r);
pause(1)
title('speech without silence');
%saving the new audiofile
write_filename = "Silence_" +num2str(i)+".wav";
% audiowrite('C:\Users\Mahmoud El-Moghazi\Desktop\Internship\AudioData\'+write_filename,data_r,fs);
audiowrite(fullfile(folder_out,write_filename),data_r,fs);
end
3 Kommentare
Mathieu NOE
am 23 Aug. 2022
hi
do this happens for all files or only a few ones ?
could you share the audio files that created the issue ?
tx
Siehe auch
Kategorien
Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!