function [minNormDistance, speakerIndex, sentenceIndex, allDistance]=speakerIdDtw(fea, speakerSet2, sidOpt, showInfo) % Speaker ID using DTW % % Example: % auFile='¤£¦Y¸²µå­Ë¦R¸²µå¥Ö#019_12672_44585.wav'; % au=myAudioRead(auFile); % sidOpt=sidOptSet; % fea=wave2fea(au, sidOpt); if nargin<4, showInfo=0; end %% memory allocation speakerNum2=length(speakerSet2); speakerDistance=inf*ones(1, speakerNum2); sentenceNum=length(speakerSet2(1).sentence); % Assume each speaker has the same no. of sentence sentenceDistance=inf*ones(1, sentenceNum); allDistance=inf*ones(speakerNum2, sentenceNum); % To record all distance, to be analyzed for speaker verification (sidOpt.useDtwPartialComputation is required to be 0!) distanceBound=inf; % for sidOpt.useDtwPartialComputation=1 for p=1:speakerNum2 % sentenceNum=length(speakerSet2(p).sentence); % sentenceDistance=inf*ones(1, sentenceNum); for q=1:sentenceNum if sidOpt.useDtwPartialComputation % [sentenceDistance(q), dtwPath]=feval(sidOpt.dtwFunc, fea, speakerSet2(p).sentence(q).fea, 1, 1, distanceBound); % Two times slower if dtwPath is needed sentenceDistance(q)=feval(sidOpt.dtwFunc, fea, speakerSet2(p).sentence(q).fea, 1, 1, distanceBound); distanceBound=min(distanceBound, sentenceDistance(q)); else % [sentenceDistance(q), dtwPath]=feval(sidOpt.dtwFunc, fea, speakerSet2(p).sentence(q).fea, 1, 1); % Two times slower if dtwPath is needed sentenceDistance(q)=feval(sidOpt.dtwFunc, fea, speakerSet2(p).sentence(q).fea, 1, 1); end allDistance(p,q)=sentenceDistance(q); % Record all distance end [speakerDistance(p), sentenceIndex]=min(sentenceDistance); end [minDistance, speakerIndex]=min(speakerDistance); frameNum=size(fea, 2); minNormDistance=minDistance/frameNum; %minDistance=minDistance/size(dtwPath, 2); % Two times slower, but no improvement %fprintf('computedName=%s, time=%.2f sec\n', computedName, etime(clock, t0));