MATLAB Function Reference    
audiorecorder

Create an audio recorder object

Syntax

Description

y = audiorecorder returns a handle to an 8-kHz, 8-bit, mono audio recorder object.

y = audiorecorder(Fs,nbits,channels) returns a handle to an audio recorder object using the sampling rate, Fs ( in Hz), the sample size of nbits, and the number of channels. Fs can be any sampling rate supported by the audio hardware. Common sampling rates are 8000, 11025, 22050, and 44000. The value of nbits must be 8 or 16 (or 24, if a 24-bit device is installed). For mono or stereo, channels must be 1 or 2, respectively.

y = audiorecorder(Fs,nbits,channels,id) returns a handle to an audio recorder object using the audio device specified by its id for input.

After you create an audio recorder object, you can use the methods listed below on that object. y represents the name of the returned audio recorder.

Method
Description
record(y)
record(y,length)
Starts recording.
Records for length number of seconds.
recordblocking(y,length)
Same as record, but does not return control until recording completes.
stop(y)
Stops recording.
pause(y)
Pauses recording.
resume(y)
Restarts recording from where recording was paused.
isrecording(y)
Indicates the status of recording. If 0, recording is not in progress. If 1, recording is in progress.
play(y)
Creates an audioplayer, plays the recorded audio data, and returns a handle to the created audioplayer.
getplayer(y)
Creates an audioplayer and returns a handle to the created audioplayer.
getaudiodata(y)
getaudiodata(y,'type')
Returns the recorded audio data to the MATLAB workspace. type is a string containing the desired data type. Supported data types are double, single, int16, int8, or uint8. If type is omitted, it defaults to 'double'. For double and single, the array contains values between -1 and 1. For int8, values are between -128 to 127. For uint8, values are from 0 to 255. For int16, values are from -32768 to 32767. If the recording is in mono, the returned array has one column. If it is in stereo, the array has two columns--one for each channel.
display(y)
disp(y)
get(y)
Displays all property information about audio recorder y.

Audio recorder objects have the properties listed below. To set a user-settable property use this syntax:

To view a read-only property



Property
Description
Type
Type
Name of the object's class
read-only
SampleRate
Sampling frequency in Hz
read-only
BitsPerSample
Number of bits per recorded sample
read-only
NumberOfChannels
Number of channels of recorded audio
read-only
TotalSamples
Total length, in samples, of the recording
read-only
Running
Status of the audio recorder ('on' or 'off')
read-only
CurrentSample
Current sample being recorded by the audio output device (If it is not recording, currentsample is the next sample to be recorded with record or resume.)
read-only
UserData
User data of any type
user-settable



For information on using the following four properties, see Creating Timer Callback Functions in the MATLAB documentation. Note that for audio object callbacks, eventStruct (event) is currently empty ([]).
TimerFcn
Name of or handle to user-specified function to be called during recording
user-settable
TimerPeriod
Time, in seconds, between TimerFcn callbacks
user-settable
StartFcn
Name of or handle to the function to be called a single time when recording starts
user-settable
StopFcn
Name of or handle to the function to be called a single time when recording stops
user-settable



NumberOfBuffers
Number of buffers used for recording (You should adjust this only if you have skips, dropouts, etc. in your recording.)
user-settable
BufferLength
Length in seconds of buffer (You should adjust this only if you have skips, dropouts, etc. in your recording.)
user-settable
Tag
User-specified object label string
user-settable

Examples

Example 1

Using a microphone, record 3.5 seconds of 44.1-kHz, 16-bit, stereo data, and then return the data to the MATLAB workspace as a double array.

Example 2

Using a microphone, record 8-bit, 22-kHz mono data, play it back, record again and return the data to the MATLAB workspace as a uint8 array.

Remarks

The current implementation of AudioRecorder is not intended for long, high sample rate recording because it uses system memory for storage and does not use disk buffering. When large recordings are attempted, MATLAB performance may degrade.

See Also

audioplayer, wavread, wavrecord, wavwrite, get, set, methods


  audioplayer auread