compair.m
资源名称:语音识别.rar [点击查看]
上传用户:doudz874
上传日期:2007-03-30
资源大小:792k
文件大小:4k
源码类别:
语音合成与识别
开发平台:
Matlab
- %function compair;
- %load model;
- %disp('press any key to start');
- %input('');
- Fs=8000;
- mywave=wavrecord(2*Fs,Fs);
- wavplay(mywave,Fs);
- %ave_wave=sum(mywave)/(2*Fs);
- end_wave=mywave-mean(mywave);
- %E(i),Z(i),Z_opt(i)
- Z_cmp=mean(abs(end_wave(100:500)));%0.02;
- Nframe=2*Fs/80-1;
- for i=1:Nframe;
- E(i)=(end_wave((i-1)*80+1))^2;
- Z(i)=0;
- Z_opt(i)=0;
- for j=2:160
- E(i)=E(i)+end_wave((i-1)*80+j)^2;
- Z(i)=Z(i)+abs(sign(end_wave((i-1)*80+j))-sign(end_wave((i-1)*80+j-1)));
- Z_opt(i)=Z_opt(i)+abs(sign(end_wave((i-1)*80+j)-Z_cmp)-sign(end_wave((i-1)*80+j-1)-Z_cmp));
- end
- Z(i)=Z(i)/2;
- Z_opt(i)= Z_opt(i)/2;
- end
- %start and end
- E_high= 0.3;
- E_low=20*mean(E(1:10));%%%%%%%%%0.2;
- Z_low=2*mean(Z_opt(1:10));%%%%%%%%%%%15;
- start=1;
- end0=1;
- for i=2:Nframe
- if E(i)>E_high && E(i-1)<E_high
- start=i;
- end
- if E(i)<E_high && E(i-1)>E_high
- end0=i;
- end
- if end0-start>15
- start1=start;
- end1=end0;
- end
- %%%%%%%%%%%%%
- end
- i=start1;
- while E(i)>E_low && i>1
- i=i-1;
- end
- start2=i+1;
- i=end1;
- while E(i)>E_low && i<Nframe
- i=i+1;
- end
- end2=i-1;
- i=start2;
- while Z_opt(i)>Z_low && i>1
- i=i-1;
- end
- start3=i;
- %plot
- %i=1:Fs*2;%%%%%%%%
- i=(start3-5)*80:(end2+5)*80;
- y=-1:0.01:1;
- figure(1);
- plot(i,end_wave(i));
- hold;
- plot(start3*80,y);
- plot(end2*80+160,y);
- hold off;
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%lpc%%%%%%%
- model_sample=zeros(end2-start3+1,44);
- for i=start3:end2
- [A,C,F]=lpc(end_wave((i-1)*80+1:(i-1)*80+160));
- acf=[A,C,F];
- model_sample(i-start3+1,:)=acf;
- end
- %dtw
- %A
- D_model_A=zeros(11,1);
- D_model_A(1)=dtwdistance(model_sample(:,1:12),model1(:,1:12));%
- D_model_A(2)=dtwdistance(model_sample(:,1:12),model2(:,1:12));%
- D_model_A(3)=dtwdistance(model_sample(:,1:12),model3(:,1:12));%
- D_model_A(4)=dtwdistance(model_sample(:,1:12),model4(:,1:12));%
- D_model_A(5)=dtwdistance(model_sample(:,1:12),model5(:,1:12));%
- D_model_A(6)=dtwdistance(model_sample(:,1:12),model6(:,1:12));%
- D_model_A(7)=dtwdistance(model_sample(:,1:12),model7(:,1:12));%
- D_model_A(8)=dtwdistance(model_sample(:,1:12),model8(:,1:12));%
- D_model_A(9)=dtwdistance(model_sample(:,1:12),model9(:,1:12));%
- D_model_A(10)=dtwdistance(model_sample(:,1:12),model10(:,1:12));%
- D_model_A(11)=dtwdistance(model_sample(:,1:12),model0(:,1:12));%
- [Dmin,ai]=min(D_model_A);
- if ai==11
- ai=0;
- end;
- %A
- D_model_C=zeros(11,1);
- D_model_C(1)=dtwdistance(model_sample(:,13:28),model1(:,13:28));%
- D_model_C(2)=dtwdistance(model_sample(:,13:28),model2(:,13:28));%
- D_model_C(3)=dtwdistance(model_sample(:,13:28),model3(:,13:28));%
- D_model_C(4)=dtwdistance(model_sample(:,13:28),model4(:,13:28));%
- D_model_C(5)=dtwdistance(model_sample(:,13:28),model5(:,13:28));%
- D_model_C(6)=dtwdistance(model_sample(:,13:28),model6(:,13:28));%
- D_model_C(7)=dtwdistance(model_sample(:,13:28),model7(:,13:28));%
- D_model_C(8)=dtwdistance(model_sample(:,13:28),model8(:,13:28));%
- D_model_C(9)=dtwdistance(model_sample(:,13:28),model9(:,13:28));%
- D_model_C(10)=dtwdistance(model_sample(:,13:28),model10(:,13:28));%
- D_model_C(11)=dtwdistance(model_sample(:,13:28),model0(:,13:28));%
- [Dmin,ci]=min(D_model_C);
- if ci==11
- ci=0;
- end;
- %disp(i);
- %F
- D_model_F=zeros(11,1);
- D_model_F(1)=dtwdistance(model_sample(:,30:44),model1(:,30:44));%
- D_model_F(2)=dtwdistance(model_sample(:,30:44),model2(:,30:44));%
- D_model_F(3)=dtwdistance(model_sample(:,30:44),model3(:,30:44));%
- D_model_F(4)=dtwdistance(model_sample(:,30:44),model4(:,30:44));%
- D_model_F(5)=dtwdistance(model_sample(:,30:44),model5(:,30:44));%
- D_model_F(6)=dtwdistance(model_sample(:,30:44),model6(:,30:44));%
- D_model_F(7)=dtwdistance(model_sample(:,30:44),model7(:,30:44));%
- D_model_F(8)=dtwdistance(model_sample(:,30:44),model8(:,30:44));%
- D_model_F(9)=dtwdistance(model_sample(:,30:44),model9(:,30:44));%
- D_model_F(10)=dtwdistance(model_sample(:,30:44),model10(:,30:44));%
- D_model_F(11)=dtwdistance(model_sample(:,30:44),model0(:,30:44));%
- [Dmin,fi]=min(D_model_F);
- if fi==11
- fi=0;
- end;
- disp(' alfa ceps fft');
- %fprintf(' alfa cepstrum fft ');
- disp([ai,ci,fi]);