how to cut audio file into small files using silent

조회 수: 6 (최근 30일)
hanem ellethy
hanem ellethy 2016년 11월 12일
편집: Walter Roberson 2022년 2월 18일
hi all
i have an audio file like this
i want to cut it into 5 small files and save them separated to work on. any help
i am using this code but it remove silent only. I don't know how to cut it.
% Read in data and plot it.
[y, Fs] = readwav('F1.wav');
figure, plot(y, 'b-');
%Find the envelope by taking a moving max operation, imdilate.
envelope = imdilate(abs(y), true(1501, 1));
% Plot it.
hold on;
plot(envelope, 'r-', 'LineWidth', 2);
plot(-envelope, 'r-', 'LineWidth', 2);
% Find the quiet parts.
quietParts = envelope < 0.07; % Or whatever value you want.
% Cut out quiet parts and plot.
yEdited = y; % Initialize
yEdited(quietParts) = [];
figure,plot(yEdited, 'b-', 'LineWidth', 2);

답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 12일
You want to look for transitions from quietParts being true to it being false in order to locate the beginning of non-quiet, and you want to look for transitions from quietParts being false to it being true in order to locate the ending of non-quiet.
A trick involved is to use
quiet_row = quietParts(:).'; %need it as row vector
A = strfind(quiet_row, [1 0]); %silence ends
B = strfind(quiet_row, [0 1]); %silence starts
You need to work out the boundary conditions to figure out whether to use those indices exactly as-is or one before or one after.
Also, you need to be concerned about whether the file begins in silence or not, and whether it ends in silence or not. For that purpose it can be useful to pad quiet_row with false or true on both sides (I leave it to you to work out which is appropriate.)
  댓글 수: 7
Joenam Coutinho
Joenam Coutinho 2022년 2월 18일
Hello Walter,
I tried to implement this, And I understood the concept. But I am finding it difficult to plot the segments I want.
How would you plot the waveforms that dont include the silent segments.
Walter Roberson
Walter Roberson 2022년 2월 18일
편집: Walter Roberson 2022년 2월 18일
sound_row = ~quietParts(:).'; %need it as row vector
starts = strfind([false sound_row], [0 1]); %sound starts
stops = strfind([sound_row false], [1 0]); %sound end
times = (0:length(sound_row)-1)/Fs;
for K = 1 : length(starts)
extracted_time = times(starts(K):stops(K));
extracted_signal = y(starts(K):stops(K),:);
plot(extracted_time, extracted_signal);
%or write the extacted signal to a file if that is what you want
end
Or, since it is for plotting purposes:
yc = y;
yc(quiet_parts,:) = nan;
times = (0:length(quiet_parts)-1)/Fs;
plot(times, yc);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by