[y,Fs] = audioread('C1.wav');
fprintf('默认抽样频率为: %d\n',Fs);
n=length(y) ;
t=(0:n-1)/Fs;
%播放
sound(y,Fs);       %原速播放声音 
pause(4)           %暂停4s
sound(y,2*Fs);     %二倍速播放声音 
pause(4)           %暂停4s
sound(y,1/2*Fs);   %半速播放声音 
pause(4)           %暂停4s
%存储
filename='C1.wav';
audiowrite(filename,y,Fs); 
filename='half.wav';
audiowrite(filename,y,0.5*Fs) ; %1/2倍采样频率
filename='double.wav';
audiowrite(filename,y,2*Fs) ;%2倍采样频率
%读取
[y,Fs] = audioread('C1.wav');
[y1,Fs1] = audioread('half.wav');%使用 audioread 将数据读回 MATLAB 
t1 = (1:length(y1))/Fs1;
[y2,Fs2] = audioread ('double.wav');
t2 = (1:length(y2))/Fs2;
%显示
figure(1);
subplot(311);axis([0 3 -1 1]);
plot(t,y);xlabel('时间/s');ylabel('幅度');title('初始采样频率');
subplot(312);axis([0 3 -1 1]);
plot(t1,y1);xlabel('时间/s');ylabel('幅度');title(' 1/2 采样频率');
subplot( 313 );axis([0 3 -1 1]);
plot(t2,y2);xlabel('时间/s');ylabel('幅度');title('2 倍采样频率');

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐