how to cut audio file into small files using silent

6 次查看(过去 30 天)
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