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

语音合成与识别

开发平台:

Matlab

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