www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ReadAndPlayAnAudioFileExample.m
%% Read and Play an Audio File %% % *Note*: This example runs only in R2016b or later. If you are using an % earlier release, replace each call to the function with the equivalent % |step| syntax. For example, myObject(x) becomes step(myObject,x). %% % Read in an AVI audio file, and play the file back using the standard % audio output device. AFR = dsp.AudioFileReader; % points to a default audio file AP = dsp.AudioPlayer('SampleRate',AFR.SampleRate, ... 'QueueDuration',2, ... 'OutputNumUnderrunSamples',true); while ~isDone(AFR) audio = AFR(); nUnderrun = AP(audio); if nUnderrun > 0 fprintf('Audio player queue underrun by %d samples.\n'... ,nUnderrun); end end pause(AP.QueueDuration); % wait until audio is played to the end release(AFR); % close the input file release(AP); % close the audio output device