Record audio data using computer's audio device
AudioRecorder object records audio data
using the computer's audio device.
To record audio data using the computer's audio device:
Define and set up your audio recorder object. See Construction.
step to record audio data according
to the properties of
dsp.AudioRecorder. The behavior
step is specific to each object in the toolbox.
This System object™ buffers the data from a frame of data using the process illustrated by the following figure.
Starting in R2016b, instead of using the
H = dsp.AudioRecorder returns
an audio recorder object,
H, that records audio samples
using an audio input device in real-time.
H = dsp.AudioRecorder(' returns an audio recorder object,
with each property set to the specified value.
Device from which to acquire audio data
Specify the device from which to acquire audio data. The default
Number of samples per second read from audio device
Specify the number of samples per second in the signal as an integer. The default is 44100. This property is tunable.
Number of audio channels
Specify the number of audio channels as an integer. The default is 2.
Data type used by device
Specify the data type used by the device to acquire audio data
Source of Buffer Size
Specify how to determine the buffer size as
Specify as an integer the size of the buffer that the audio
recorder object uses to communicate with the audio device. This property
applies when you set the
Size of queue in seconds
Specify the length of the audio queue, in seconds. The default
To minimize latency, lower the
Number of samples in the output signal
Specify the number of samples in the audio recorder's output as an integer. The default is 1024.
Data type of the output
Select the output data type as
Enable output of overrun count
Source of device channel mapping
Specify whether to determine the channel mapping as
Device-to-data channel mapping
Vector of valid channel indices to represent the mapping between
device input channels and the data. The term Channel Mapping refers
to a 1-to-1 mapping that associates channels on the selected audio
device to channels of the data. When you record audio, channel mapping
allows you to specify which channel of the audio data directs input
to a specific channel of audio. By default, the
|clone||Create audio recorder object with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs of step method|
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|step||Record audio from recording device|
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).
Record ten seconds of speech from a microphone, and send the output to a .wav file.
AR = dsp.AudioRecorder('OutputNumOverrunSamples',true); AFW = dsp.AudioFileWriter('myspeech.wav','FileFormat', 'WAV'); disp('Speak into microphone now'); tic; while toc < 10 [audioIn,nOverrun] = AR(); AFW(audioIn); if nOverrun > 0 fprintf('Audio recorder queue was overrun by %d samples\n'... ,nOverrun); end end release(AR); release(AFW); disp('Recording complete');
Speak into microphone now Recording complete
To run your generated standalone executable application in Shell, you need to set your environment to the following:
This object implements the algorithm, inputs, and outputs described on the From Audio Device block reference page. The object properties correspond to the block parameters.