基於Matlab編寫的語音端點檢測程式function [x1,x2] = vad(x)%幅度歸一化到[-1,1]x = double(x);x = x / max(abs(x));%常數設定FrameLen = 240;FrameInc = 80;amp1 = 10;amp2 = 2;zcr1 = 10;zcr2 = 5;maxsilence = 8; % 6*10ms = 30msminlen = 15; % 15*10ms = 150msstatus = 0;count = 0;silence = 0;%計算過零率tmp1 = enframe(x(1:end-1), FrameLen, FrameInc);tmp2 = enframe(x(2:end) , FrameLen, FrameInc);signs = (tmp1.*tmp2)0.02;zcr = sum(signs.*diffs, 2);%計算短時能量amp = sum(abs(enframe(filter([1 -0.9375], 1, x), FrameLen, FrameInc)), 2);%調整能量門限amp1 = min(amp1, max(amp)/4);amp2 = min(amp2, max(amp)/8);%開始端點檢測x1 = 0; x2 = 0;for n=1:length(zcr) goto = 0; switch status case {0,1} % 0 = 靜音,1 = 可能開始 if amp(n) > amp1 % 確信進入語音段 x1 = max(n-count-1,1); status = 2; silence = 0; count = count + 1; elseif amp(n) > amp2 | ... % 可能處於語音段 zcr(n) > zcr2 status = 1; count = count + 1; else % 靜音狀態 status = 0; count = 0; end case 2, % 2 = 語音段 if amp(n) > amp2 | ... % 保持在語音段 zcr(n) > zcr2 count = count + 1; else % 語音將結束 silence = silence+1; if silence
基於Matlab編寫的語音端點檢測程式function [x1,x2] = vad(x)%幅度歸一化到[-1,1]x = double(x);x = x / max(abs(x));%常數設定FrameLen = 240;FrameInc = 80;amp1 = 10;amp2 = 2;zcr1 = 10;zcr2 = 5;maxsilence = 8; % 6*10ms = 30msminlen = 15; % 15*10ms = 150msstatus = 0;count = 0;silence = 0;%計算過零率tmp1 = enframe(x(1:end-1), FrameLen, FrameInc);tmp2 = enframe(x(2:end) , FrameLen, FrameInc);signs = (tmp1.*tmp2)0.02;zcr = sum(signs.*diffs, 2);%計算短時能量amp = sum(abs(enframe(filter([1 -0.9375], 1, x), FrameLen, FrameInc)), 2);%調整能量門限amp1 = min(amp1, max(amp)/4);amp2 = min(amp2, max(amp)/8);%開始端點檢測x1 = 0; x2 = 0;for n=1:length(zcr) goto = 0; switch status case {0,1} % 0 = 靜音,1 = 可能開始 if amp(n) > amp1 % 確信進入語音段 x1 = max(n-count-1,1); status = 2; silence = 0; count = count + 1; elseif amp(n) > amp2 | ... % 可能處於語音段 zcr(n) > zcr2 status = 1; count = count + 1; else % 靜音狀態 status = 0; count = 0; end case 2, % 2 = 語音段 if amp(n) > amp2 | ... % 保持在語音段 zcr(n) > zcr2 count = count + 1; else % 語音將結束 silence = silence+1; if silence