Skip to Main Content Skip to Search
Product Documentation

audiorecorder - Create object for recording audio

Syntax

recorder = audiorecorder
recorder = audiorecorder(Fs,nBits,nChannels)
recorder = audiorecorder(Fs,nBits,nChannels,ID)

Description

recorder = audiorecorder creates an 8000 Hz, 8-bit, 1-channel audiorecorder object.

recorder = audiorecorder(Fs,nBits,nChannels) sets the sample rate Fs (in Hz), the sample size nBits, and the number of channels nChannels.

recorder = audiorecorder(Fs,nBits,nChannels,ID) sets the audio input device to the device specified by ID.

Tips

Input Arguments

Fs

Sampling rate in Hz. Valid values depend on the specific audio hardware installed. Typical values supported by most sound cards are 8000, 11025, 22050, 44100, 48000, and 96000 Hz.

Default: 8000

nBits

Bits per sample. Valid values depend on the audio hardware installed: 8, 16, or 24.

Default: 8

nChannels

The number of channels: 1 (mono) or 2 (stereo).

Default: 1

ID

Device identifier. To obtain the ID of a device, use the audiodevinfo function.

Default: -1 (default device)

Methods

get

Query properties of audiorecorder object.

getaudiodata

Create an array that stores the recorded signal values.

getplayer

Create an audioplayer object.

isrecording

Query whether recording is in progress: returns true or false.

pause

Pause recording.

play

Play recorded audio. This method returns an audioplayer object.

record

Start recording.

recordblocking

Record, and do not return control until recording completes. This method requires a second input for the length of the recording in seconds:
recordblocking(recorder,length)

resume

Restart recording from paused position.

set

Set properties of audiorecorder object.

stop

Stop recording.

See the reference pages for get, getaudiodata, play, record, recordblocking, and set for additional syntax options.

Properties

BitsPerSample

Number of bits per sample. (Read-only)

CurrentSample

Current sample that the audio input device is recording. If the device is not recording, CurrentSample is the next sample to record with record or resume. (Read-only)

DeviceID

Identifier for audio device. (Read-only)

NumberOfChannels

Number of audio channels. (Read-only)

Running

Status of the audio recorder: 'on' or 'off'. (Read-only)

SampleRate

Sampling frequency in Hz. (Read-only)

TotalSamples

Total length of the audio data in samples. (Read-only)

Tag

String that labels the object.

Type

Name of the class: 'audiorecorder'. (Read-only)

UserData

Any type of additional data to store with the object.

The following four properties apply to callback functions. The first two inputs to your callback function must be the audiorecorder object and an event structure.

StartFcn

Function to execute one time when recording starts.

StopFcn

Function to execute one time when recording stops.

TimerFcn

Function to execute repeatedly during recording. To specify time intervals for the repetitions, use the TimerPeriod property.

TimerPeriod

Time in seconds between TimerFcn callbacks. Default: .05

audiorecorder ignores any specified values for these properties, which will be removed in a future release.

BufferLength

Length of buffer in seconds.

NumberOfBuffers

Number of buffers.

Examples

Create an audiorecorder object for CD-quality audio in stereo, and view its properties:

recObj = audiorecorder(44100, 16, 2);
get(recObj)
 

Collect a sample of your speech with a microphone, and plot the signal data:

% Record your voice for 5 seconds.
recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 5);
disp('End of Recording.');

% Play back the recording.
play(recObj);

% Store data in double-precision array.
myRecording = getaudiodata(recObj);

% Plot the waveform.
plot(myRecording);

See Also

audiodevinfo | audioplayer | sound

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS