%% Record Audio from Input Device
% Record audio data from a microphone and then play the recorded audio.
% Create an audiorecorder object with default property values.

recObj = audiorecorder;

% Alternatively, create an audiorecorder object with the desired properties. For a CD-quality audio in stereo, define these properties: sampling frequency (Fs), number of bits per sample (nBits), the number of channels (nChannels), and input device identifier (ID).

Fs = 44100 ; 
nBits = 16 ; 
nChannels = 2 ; 
ID = -1; % default audio input device 
recObj = audiorecorder(Fs,nBits,nChannels,ID);

% Collect a five second sample of your speech with your microphone.

disp('Start speaking.')
recordblocking(recObj,5);
disp('End of Recording.');

% Play back the recording.

play(recObj);

% Copyright 2018 The MathWorks, Inc.