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

语音合成与识别

开发平台:

Matlab

  1. %read wave
  2. Fs=8000;
  3. mywave=wavrecord(2*Fs,Fs);
  4. wavplay(mywave,Fs);
  5. ave_wave=sum(mywave)/(2*Fs);
  6. end_wave=mywave-ave_wave;
  7. %E(i),Z(i),Z_opt(i)
  8. Z_cmp=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.4;
  24. E_low=0.2;
  25. Z_low=15;
  26. start1=1;
  27. end1=1;
  28. for i=2:Nframe
  29.     if E(i)>E_high && E(i-1)<E_high
  30.         start1=i;
  31.     end 
  32.     if E(i)<E_high && E(i-1)>E_high 
  33.         end1=i;
  34.     end
  35.     %%%%%%%%%%%%%
  36. end
  37. i=start1;
  38. while E(i)>E_low && i>1
  39.     i=i-1;
  40. end
  41. start2=i;
  42. i=end1;
  43. while E(i)>E_low && i<Nframe
  44.     i=i+1;
  45. end
  46. end2=i;
  47. i=start2;
  48. while Z_opt(i)>Z_low && i>1
  49.     i=i-1;
  50. end
  51. start3=i;
  52. %plot
  53. i=(start3-10)*80:(end2+10)*80;
  54. x1=start1;
  55. y1=-1:0.01:1;
  56. x2=end1;
  57. y=-1:0.01:1;
  58. %hold;
  59. figure;
  60. plot(i,end_wave(i));
  61. hold;
  62. plot(start3*80,y);
  63. plot(end2*80,y);
  64. hold off;
  65. for i=start3:end2
  66.     [A,C]=lpc(end_wave((i-1)*80+1:(i-1)*80+160));
  67.     ac=[A,C];
  68.     model_test(i-start3+1,:)=ac;
  69. end
  70. %A(),C()
  71. %for i=start3:end2
  72. %    [A,C]=lpc(end_wave((i-1)*80+1:(i-1)*80+160));
  73. %    ac=[A,C];
  74. %    filey(i-start3+1,:)=ac;
  75. %end %fid = fopen('exp.txt','w');
  76. %fprintf(fid,'%6.8f b%6.8fn',filey);
  77. %fclose(fid);