% [ MEETING_SEG.m ]
%
% A to Z implementation of unsupervised location-based segmentation
% of multi-party speech with a microphone array (IDIAP RR 06-26).
%
% If all you want is to quickly run the whole implementation on one meeting,
% you are in the right place.
%
% (If you are more interested into multiple moving speaker cases,
% and/or to understand the fine details of each step, go to README.m)
%
% By Guillaume Lathoud, 2006 - lathoud@idiap.ch


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Application to unsupervised location-based speaker segmentation
% "unsupervised" means that we don't know in advance the occupied locations
% and the number of such locations.
%
% We are using here one recording from the M4 Corpus (mmm.idiap.ch).

% ( 1 ) Run multisource detection-localization and short-term clustering

FAST_detect_locate_wrapper( 'Scripted-Meeting-TST-01' );

% ( 2 ) Set an automatic threshold on posteriors of wideband activity

par = [];
par.in_filename = 'DATA/FAST_detect_locate_wrapper-Scripted-Meeting-TST-01-result.mat';
par.n_comp_list = 2:10;

% To select the automatic threshold for the final decision,
% based on IDIAP RR 05-52. This is a False Alarm Rate target, between 0 and 1.
%
% NOTE: the threshold is less conservative than above, in order to
% counterbalance the fact that we now use BOTH wideband activeness and
% MFCC vectors to discriminate between speech and non-speech.
par.far_t = 0.01;

par.out_dir     = 'DATA';

sbmfcc_sns_model( par );   % This one takes time

% ( 3 ) Now use the threshold to take a cluster-level decision

classify_cluster_sns( 'DATA/sbmfcc_sns_model-FAST_detect_locate_wrapper-Scripted-Meeting-TST-01-result.mat' );

% ( 4 ) Now run STATIC location clustering to determine automatically:
% - the number and positions of most occupied locations in the meeting.
% - the speech segments.

static_sigma( 'DATA/classify_cluster_sns-sbmfcc_sns_model-FAST_detect_locate_wrapper-Scripted-Meeting-TST-01-result.mat' );

% ( 5 ) Show the resulting meeting segmentation

% Don't show the figure
% (a matlab file and a text file are also written)
show_static_seg( 'DATA/static_sigma-classify_cluster_sns-sbmfcc_sns_model-FAST_detect_locate_wrapper-Scripted-Meeting-TST-01-result.mat' );

% Load the result
load( 'DATA/show_static_seg-static_sigma-classify_cluster_sns-sbmfcc_sns_model-FAST_detect_locate_wrapper-Scripted-Meeting-TST-01-result.mat', 'static_obj' );

% Show the figure(s)
for a = 1:numel( static_obj.list )
  figure;
  plot_loctimeseg( static_obj.list( a ).smooth_loctimeseg );
  title( static_obj.list( a ).name );
end

% Also show the text file contents
system( 'cat DATA/show_static_seg-Scripted-Meeting-TST-01-smooth_seg.txt' );
