Tuesday, December 28, 2010

Record and Play Audio

Record audio from sound card

function record(filename)
AI=analoginput('winsound');
addchannel(AI, 1);
Fs = 8000;              % Sample Rate is 8000 Hz
set (AI, 'SampleRate', Fs)
duration = 2;           % 2 second acquisition
set(AI, 'SamplesPerTrigger', duration*Fs);
start(AI);
data = getdata(AI);
delete(AI);
wavwrite(data,Fs,filename); % Data will be saved to file

Play audio file

function play(filename)
soundsc(wavread(filename),Fs) % Play the file in specified sample rate

No comments:

Post a Comment