audiorecorder

Create audio recorder object

Syntax

y = audiorecorder
y = audiorecorder(Fs, nbits, nchans)
y = audiorecorder(Fs, nbits, channels, id)

Description

y = audiorecorder creates an 8000 Hz, 8-bit, 1 channel audiorecorder object. y is a handle to the object. The audiorecorder object supports methods and properties that you can use to record audio data.

y = audiorecorder(Fs, nbits, nchans) creates an audiorecorder object using the sampling rate Fs (in Hz), the sample size nbits, and the number of channelsnchans. Fs can be any sampling rate supported by the audio hardware. Common sampling rates are 8000, 11025, 22050, and 44100 (only 44100 on Macintosh® systems). The value of nbits must be 8, 16, or 24, on Microsoft® Windows®, and 8 or 16 on UNIX®. The number of channels, nchans must be 1 (mono) or 2 (stereo).

y = audiorecorder(Fs, nbits, channels, id) creates an audiorecorder object using the audio device specified by its id for input. If id equals -1, the default input device will be used. This option is only available on Windows.

Examples

Using a microphone, record your voice, using a sample rate of 44100 Hz, 16 bits per sample, and one channel. Speak into the microphone, then pause the recording. Play back what you have recorded so far. Record some more, then stop the recording. Finally, return the recorded data to MATLAB® as an int16 array.

r = audiorecorder(44100, 16, 1);
record(r);     % speak into microphone...
pause(r);
p = play(r);   % listen
resume(r);     % speak again
stop(r);
p = play(r);   % listen to complete recording
mySpeech = getaudiodata(r, 'int16'); % get data as int16 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.

Methods

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

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.

Properties

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

set(y, 'property1', value,'property2',value,...)

To view a read-only property,

get(y,'property')		%displays 'property' setting.

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

Handle to a user-specified callback function that is executed repeatedly (at TimerPeriod intervals) during recording.

User-settable

TimerPeriod

Time, in seconds, between TimerFcn callbacks.

User-settable

StartFcn

Handle to a user-specified callback function that is executed once when recording starts.

User-settable

StopFcn

Handle to a user-specified callback function that is executed once 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


© 1984-2008 The MathWorks, Inc.