Create object for recording audio
recorder = audiorecorder
recorder = audiorecorder(Fs,nBits,nChannels)
recorder = audiorecorder(Fs,nBits,nChannels,ID)
creates
an 8000 Hz, 8-bit, 1-channel recorder
= audiorecorderaudiorecorder
object.
sets
the sample rate recorder
= audiorecorder(Fs
,nBits
,nChannels
)Fs
(in Hz), the sample size nBits
,
and the number of channels nChannels
.
sets
the audio input device to the device specified by recorder
= audiorecorder(Fs
,nBits
,nChannels
,ID
)ID
.
| Sampling rate in Hz. Valid values depend on both the sample rates permitted by MATLAB® and the specific audio hardware on your system. MATLAB has a hard restriction of 1000 Hz <= Fs <= 384000 Hz, although further hardware-dependent restrictions apply. Typical values supported by most sound cards are 8000, 11025, 22050, 44100, 48000, and 96000 Hz. Default: 8000 |
|
Bits per sample. Valid values depend on the audio hardware installed: Default: 8 |
|
The number of channels: Default: 1 |
|
Device identifier. To obtain the ID of a device, use the Default: |
When calling any method, include the audiorecorder
object
name using function syntax, such as stop(
.recorder
)
Query properties of | |
Create an array that stores the recorded signal values. | |
| Create an |
| Query whether recording is in progress: returns |
| Pause recording. |
Play recorded audio. This method returns an | |
Start recording. | |
Record, and do not return control until recording completes.
This method requires a second input for the length of the recording
in seconds: | |
| Restart recording from paused position. |
Set properties of | |
| Stop recording. |
See the reference pages for get
, getaudiodata
, play
, record
, recordblocking
,
and set
for
additional syntax options.
BitsPerSample | Number of bits per sample. (Read-only) |
CurrentSample | Current sample that the audio input device is recording.
If the device is not recording, |
DeviceID | Identifier for audio device. (Read-only) |
NumberOfChannels | Number of audio channels. (Read-only) |
Running | Status of the audio recorder: |
SampleRate | Sampling frequency in Hz. (Read-only) |
TotalSamples | Total length of the audio data in samples. (Read-only) |
Tag | Label of the object. |
Type | Name of the class: |
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 | |
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 | Time in seconds between |
| |
BufferLength | Length of buffer in seconds. |
NumberOfBuffers | Number of buffers. |
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);
To use an audiorecorder
object,
your system must have a properly installed and configured sound card.
audiorecorder
is not intended
for long, high-sample-rate recording. audiorecorder
uses
system memory for storage and does not use disk buffering. When you
attempt a large recording, your MATLAB performance sometimes
degrades over time.