wavread函数
函数语法
y = wavread(filename)
[y, Fs] = wavread(filename)
[y, Fs, nbits] = wavread(filename)
[y, Fs, nbits, opts] = wavread(filename)
[...] = wavread(filename, N)
[...] = wavread(filename, [N1 N2])
[...] = wavread(..., fmt)
siz = wavread(filename,'size')
界面操作
File,Import Data可打开导入向导。
实例:
oad handel.mat %载入MATLAB自带的示例音频数据mat文件
hfile='Data_waveread.wav'; %准备写的音频数据文件
wavwrite(y,Fs,hfile) %将y以Fs
采样率写到文件中
clear y Fs %清除载入的y以及Fs
[y, Fs, nbits, readinfo] = wavread(hfile); %从声音文件中载入数据,y为从声音文件载入的数据,Fs为采样率,nbits为采样使用的位数,本例中readinfo仅有fmt字段
sound(y, Fs); %播放声音
pause(4) %暂停4秒,与后面的声音分隔开
%读取前两秒的数据,并播放
nsamples = 2 * Fs; %2秒内共采样的点数
[y2, Fs] = wavread(hfile, nsamples); %只读取前两秒的采样点
sound(y2, Fs); %播放声音
pause(4) %暂停4秒
%读并播放中间三分之一声音
sizeinfo = wavread(hfile, 'size'); %获取声音文件的采样点数以及通道数
tot_samples = sizeinfo(1); %采样点数
startpos = tot_samples / 3; %1/3采样点
endpos = 2 * startpos; %2/3采样点
[y3, Fs] = wavread(hfile, [startpos endpos]); %读中间的1/3采样点数据
sound(y3, Fs); %播放声音