Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

audiorecorder - Create audiorecorder 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 channels nchans. Fs can be any sampling rate supported by the audio hardware. Common sampling rates are 8000, 11025, 22050, and 44100 (only 44100 on Macintosh® operating systems). The value of nbits must be 8, 16, or 24 on Microsoft Windows operating systems, and 8 or 16 on UNIX operating systems. 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. (You can obtain the ID of a device with the audiodevinfo function.) If ID equals -1, the default input device is used. This option is available only on Windows operating systems.

Remarks

Performance with Large Recordings

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.

Object Scope

When using an audiorecorder object inside a function, the scope of the object is limited to the duration of the function. When the function is completed, the object is cleared, so that you cannot access any of its data or callbacks after that point. For example, in this function, record does not block execution, so the function ends immediately after the recording starts, deleting all callbacks and data.

function makeRecorder(timerCallback, timerPeriod)

% Create an audio recorder object
recObject = audiorecorder();

% Set callback to be called every timerPeriod seconds
set(recObject, ...
    'TimerFcn', timerCallback, ...
    'TimerPeriod', timerPeriod);

% Start recording
record(recObject);

end

To work around this problem, you can try any of the following:

Examples

Using a microphone, record your voice with 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 the MATLAB workspace 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

Methods

After you create an audiorecorder object, you can use the following methods 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 you omit type the defaults is 'double'. For double and single, the array contains values from -1 to 1. For int8, values are from -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 audiorecorder object y.

Properties

audiorecorder objects have the following properties. To specify a user-settable property, use this syntax:

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

To view a read-only property, use this syntax:

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

Property

Description

Type

BitsPerSample

Number of bits per recorded sample.

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

NumberOfChannels

Number of channels of recorded audio.

Read-only

Running

Status of the audio recorder ('on' or 'off').

Read-only

SampleRate

Sampling frequency in Hz.

Read-only

TotalSamples

Total length, in samples, of the recording.

Read-only

Type

Name of the object's class.

Read-only

UserData

User data of any type.

User-settable

For information on using the following properties, see Creating and Executing Callback Functions in the MATLAB documentation. Note that for audio object callbacks, eventStruct(event) is currently empty ([]).

BufferLength

Length in seconds of buffer (you should adjust this only if you have skips, dropouts, etc., in your recording).

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

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

Tag

User-specified object label string.

User-settable

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

See Also

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

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS