9 Collect some audio data
Begin by creating an audiorecorder; type the following in the Command Window:
[rec, fs] = getRecorder()
You should see something like the following:
rec =
audiorecorder with properties:
SampleRate: 16000
BitsPerSample: 16
NumberOfChannels: 1
DeviceID: 8
CurrentSample: 1
TotalSamples: 0
Running: 'off'
StartFcn: []
StopFcn: []
TimerFcn: []
TimerPeriod: 0.0500
Tag: ''
UserData: []
Type: 'audiorecorder'
fs =
16000
The getRecorder
function tries to connect to the webcam to access its microphone.
9.1 Try to record some audio data
To record 3 seconds of audio using the webcam type the following in the Command Window::
disp('Start recording.')
recordblocking(rec, 3);
disp('End of Recording.');
If you get an error when trying to use the recordblocking
function then check that the webcam is plugged into the computer and try re-calling the getRecorder
function.
9.2 Get the audio data from the recorder
To access the recorded audio data type the following into the Command Window:
y = getaudiodata(rec);
The vector y is the recorded audio data.
9.3 Playback the recorded audio data
To playback the recorded audio data type the following into the Command Window:
sound(y, fs)