Mercurial > hg > emotion-detection-top-level
view Code/Descriptors/Matlab/Common/calculate_Silence.m @ 4:92ca03a8fa99 tip
Update to ICASSP 2013 benchmark
author | Dawn Black |
---|---|
date | Wed, 13 Feb 2013 11:02:39 +0000 |
parents | ea0c737c6323 |
children |
line wrap: on
line source
function [Limits] = calculate_Silence( x, fs, frameLength ) % Convert mono to stereo if (size(x, 2)==2) x = mean(x')'; end [m n]=size(x); if(m>n) x=x'; end % Window length and step (in seconds): win = frameLength/fs; step = win; %%%%%%%%%%%%%%%%%%%%%%%%%%% % THRESHOLD ESTIMATION %%%%%%%%%%%%%%%%%%%%%%%%%%% % Weight = 10; % used in the threshold estimation method % Compute short-time energy and spectral centroid of the signal: Eor = ShortTimeEnergy(x, win*fs, step*fs); % Apply median filtering in the feature sequences (twice), using 5 windows: % (i.e., 250 mseconds) E = medfilt1(Eor, 5); E = medfilt1(E, 5); % normalise E = E*(1/max(E)); % Get the average values of the smoothed feature sequences: E_mean = mean(E); % %Find energy threshold: % [HistE, X_E] = hist(E, round(length(E) / 10)); % histogram computation % [MaximaE, countMaximaE] = findMaxima(HistE, 3); % find the local maxima of the histogram T_E = 0.0005; % determined empirically % Thresholding: Flags1 = (E>=T_E); flags = Flags1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % SPEECH SEGMENTS DETECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% count = 1; WIN = 0; Limits = []; while (count < length(flags)) % while there are windows to be processed: % initilize: curX = []; countTemp = 1; % while flags=1: while ((flags(count)==1) && (count < length(flags))) if (countTemp==1) % if this is the first of the current speech segment: Limit1 = round((count-WIN)*step*fs)+1; % set start limit: if (Limit1<1) Limit1 = 1; end end count = count + 1; % increase overall counter countTemp = countTemp + 1; % increase counter of the CURRENT speech segment end if (countTemp>1) % if at least one segment has been found in the current loop: Limit2 = round((count+WIN)*step*fs); % set end counter if (Limit2>length(x)) Limit2 = length(x); end Limits(end+1, 1) = Limit1; Limits(end, 2) = Limit2; end count = count + 1; % increase overall counter end %%%%%%%%%%%%%%%%%%%%%%% % POST - PROCESS % %%%%%%%%%%%%%%%%%%%%%%% % find the frame index of the start and end frames of non-silent segments Limits = floor( Limits / frameLength ); pos = find(Limits == 0); if(pos) Limits(pos) = 1; end % A. MERGE OVERLAPPING SEGMENTS: RUN = 1; while (RUN==1) RUN = 0; for (i=1:size(Limits,1)-1) % for each segment if (Limits(i,2)>=Limits(i+1,1)) RUN = 1; Limits(i,2) = Limits(i+1,2); Limits(i+1,:) = []; break; end end end % B. Get final segments: segments = {}; for (i=1:size(Limits,1)) segments{end+1} = x(Limits(i,1)*frameLength:Limits(i,2)*frameLength); end