status = 0;
silence = 0;
count = 0;
else % 语音结束
status = 3;
end
end
case 3,
break;
end
end
count = count-silence/2;
x2 = x1 + count -1;
subplot(311)
plot(x)
axis([1 length(x) -1 1])
ylabel('Speech');
line([x1*FrameInc x1*FrameInc], [-1 1], 'Color', 'red');
line([x2*FrameInc x2*FrameInc], [-1 1], 'Color', 'red');
subplot(312)
plot(amp);
axis([1 length(amp) 0 max(amp)])
ylabel('Energy');
line([x1 x1], [min(amp),max(amp)], 'Color', 'red');
line([x2 x2], [min(amp),max(amp)], 'Color', 'red');
subplot(313)
plot(zcr);
axis([1 length(zcr) 0 max(zcr)])
ylabel('ZCR');
line([x1 x1], [min(zcr),max(zcr)], 'Color', 'red');
line([x2 x2], [min(zcr),max(zcr)], 'Color', 'red');
程序:
%读入语音文件
fin=fopen('DR4_MLJHO_SX334.ADC','r');
x=fread(fin,'short');
fclose(fin);
%窗长
l=300;
step=100;
e_x=frame(x,'energy');
figure(1);
plot(e_x,'LineWidth',2);
xlabel('时间t');
ylabel('贞输出');
s=sort(e_x);
min_e=s(ceil(5*step/64));
max_e=s(length(s)-ceil(5*step/64));
%设置阈值
threshold=min_e+0.2*(max_e-min_e);
a=e_x>threshold;
%门限检验
if((length(a)<15*64/step)|(max_e/min_e<1.3)),
disp(&#39;No speech found&#39;);
else
figure(2);
plot(a,&#39;LineWidth&#39;,2);
xlabel(&#39;时间 t&#39;);
ylabel(&#39;端点&#39;);
set(gca,&#39;ylim&#39;,[0 1.5]);
end
%frame.m
function[yy]&#61;frame(x,func,SAMP_FREQ,1,step)
[m,n]&#61;size(x);
if m>n
n&#61;m;
else
n&#61;n;
x&#61;x&#39;;
end
if nargin<3,SAMP_FREQ&#61;8000;end;
if nargin<4,l&#61;SAMP_FREQ/40;end;
if nargin<5,step&#61;1/2;end;
%贞的数目
num_frame&#61;ceil(n/step);
%补零
x(n&#43;1:n&#43;2*1)&#61;zeros(2*1,1);
i&#61;[0:step:num_frames*step]&#39;;
j&#61;i*ones(1,1);
i&#61;j&#43;ones(num_frames&#43;1,1)*[1:1];
y&#61;reshape(x(i),num_frames&#43;1,1)&#39;;
y&#61;(hanning(l)*ones(1,num_frames&#43;1)).*y;
for i&#61;1:num_frames
cmd&#61;sprintf(&#39;yy(:,i)&#61;%s(y(:,i));&#39;,func);
eval(cmd);
end
[本帖最后由 mooni 于 2009-4-8 13:38 编辑]
2009-4-8 13:30 上传
点击文件名下载附件
2.39 KB, 下载次数: 12025
2009-4-8 13:30 上传
点击文件名下载附件
1.08 KB, 下载次数: 8257