setmodel.asv
上传用户:doudz874
上传日期:2007-03-30
资源大小:792k
文件大小:2k
源码类别:

语音合成与识别

开发平台:

Matlab

  1. model(:,:)=zeros;
  2. Fs=8000;
  3. mywave=wavrecord(2*Fs,Fs);
  4. wavplay(mywave,Fs);
  5. %ave_wave=sum(mywave)/(2*Fs);
  6. end_wave=mywave-mean(mywave);
  7. %E(i),Z(i),Z_opt(i)
  8. Z_cmp=3*mean(abs(end_wave(100:500)));%0.02;
  9. Nframe=2*Fs/80-1;
  10. for i=1:Nframe;
  11.       E(i)=(end_wave((i-1)*80+1))^2;
  12.       Z(i)=0;
  13.       Z_opt(i)=0;  
  14.     for j=2:160
  15.         E(i)=E(i)+end_wave((i-1)*80+j)^2;
  16.         Z(i)=Z(i)+abs(sign(end_wave((i-1)*80+j))-sign(end_wave((i-1)*80+j-1)));
  17.         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));   
  18.     end
  19.     Z(i)=Z(i)/2;
  20.     Z_opt(i)= Z_opt(i)/2;
  21. end
  22. %start and end
  23. E_high= 0.3;
  24. E_low=20*mean(E(1:10));%%%%%%%%%0.2;
  25. Z_low=2*mean(Z_opt(1:10));%%%%%%%%%%%15;
  26. start=1;
  27. end0=1;
  28. for i=2:Nframe
  29.     if E(i)>E_high && E(i-1)<E_high
  30.         start=i;
  31.     end 
  32.     if E(i)<E_high && E(i-1)>E_high 
  33.         end0=i;
  34.     end
  35.     if end0-start>15
  36.         start1=start;
  37.         end1=end0;
  38.     end
  39.     %%%%%%%%%%%%%
  40. end
  41. i=start1;
  42. while E(i)>E_low && i>1
  43.     i=i-1;
  44. end
  45. start2=i+1;
  46. i=end1;
  47. while E(i)>E_low && i<Nframe
  48.     i=i+1;
  49. end
  50. end2=i-1;
  51. i=start2;
  52. while Z_opt(i)>Z_low && i>1
  53.     i=i-1;
  54. end
  55. start3=i;
  56. %plot
  57. %i=1:Fs*2;%%%%%%%%
  58. i=(start3-5)*80:(end2+4)*80;
  59. y=-1:0.01:1;
  60.  
  61. figure(1);
  62. plot(i,end_wave(i));
  63. hold;
  64. plot(start3*80,y);
  65. plot(end2*80,y);
  66. hold off;
  67. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%lpc%%%%%%%
  68. for i=start3:end2
  69.     [A,C,F]=lpc(end_wave((i-1)*80+1:(i-1)*80+160));
  70.     acf=[A,C,F];
  71.     model(i-start3+1,:)=acf;
  72. end