% Train GMM for speaker verification using speaker models and anti-speaker models tInit=clock; addMyPath; load output\mat\speakerSet.mat % ====== GMM training on anti-speaker model gaussianNum=64; % No. of gaussians in a GMM speakerNum=length(speakerSet); for i=1:speakerNum % Create the feature set for anti model mfcc2=[]; for j=1:speakerNum if j==i, continue; end mfcc2=[mfcc2, [speakerSet(j).sentence.mfcc]]; end % Train the anti-model mfcc2=mfcc2(:, 1:10:end); % Down-sample fprintf('%d/%d: GMM training for anti-speaker model of %s\n', i, speakerNum, speakerSet(i).name); [antimodel(i).mean, antimodel(i).covariance, antimodel(i).weight, antimodel(i).logProb] = gmmTrain(mfcc2, gaussianNum); end fprintf('Saving antimodel.mat...\n'); save output\mat\antimodel antimodel % ====== GMM training on speaker model gaussianNum=32; % No. of gaussians in a GMM speakerNum=length(speakerSet); for i=1:speakerNum % Create the feature set for speaker model mfcc=[speakerSet(i).sentence(1:2:end).mfcc]; % Training data! % Train the speaker-model fprintf('%d/%d: GMM training for speaker model of %s\n', i, speakerNum, speakerSet(i).name); [model(i).mean, model(i).covariance, model(i).weight, model(i).logProb] = gmmTrain(mfcc, gaussianNum); end fprintf('Saving model.mat...\n'); save output\mat\model model % ====== GMM evaluation for speaker verification speakerNum=length(speakerSet); for i=1:speakerNum for j=2:2:length(speakerSet(i).sentence) % Test data! logProb1=gmmEvalMex(speakerSet(i).sentence(j).mfcc, antimodel(i).mean, antimodel(i).covariance, antimodel(i).weight); speakerSet(i).sentence(j).logProb1=mean(logProb1); logProb2=gmmEvalMex(speakerSet(i).sentence(j).mfcc, model(i).mean, model(i).covariance, model(i).weight); speakerSet(i).sentence(j).logProb2=mean(logProb2); end speakerSet(i).logProb1=[speakerSet(i).sentence.logProb1]; speakerSet(i).logProb2=[speakerSet(i).sentence.logProb2]; [speakerSet(i).fp, speakerSet(i).fn]=roc(speakerSet(i).logProb1, speakerSet(i).logProb2); speakerSet(i).recogRate=1-(speakerSet(i).fp+speakerSet(i).fn); end recogRate=[speakerSet.recogRate]; [junk, index]=sort(recogRate); for i=1:speakerNum fprintf('Name=%s, recogRate=%g%%\n', speakerSet(index(i)).name, 100*recogRate(index(i))); end fprintf('Average recog rate = %g%%\n', 100*mean(recogRate(~isinf(recogRate)))); fprintf('%s ===> %g seconds\n', mfilename, etime(clock, tInit));