readAudio
Syntax
Description
Add-On Required
To use this function for accessing mobile device sensors remotely from MATLAB® installed on a desktop or laptop computer, you must also install either MATLAB Support Package for Apple iOS Sensors or MATLAB Support Package for Android® Sensors. For more information, see Get and Manage Add-Ons.
reads all available audio data from the collection buffer, and returns it to a double matrix
of size audioData
= readAudio(devObj
)NumSamples
-by-NumChannels
.
reads the number of samples indicated by audioData
= readAudio(devObj
,span
)span
, which you can specify as
a numeric value for the number of samples, or as a duration, in which case the function
reads the number of samples to fill the duration span, depending on the sample rate. You can
set the sample rate on the device in the Sensors menu, or by setting
the microphone object SampleRate
value in MATLAB.
Data is read from the start of the buffer, that is, the earliest samples. All data is cleared from the buffer by this operation. The function blocks MATLAB until the requested number of samples is read, or until a timeout occurs.
specifies to read the most recently collected samples from the audio buffer. The default is
to read to the oldest samples. You can specify audioData
= readAudio(devObj
,span
,"latest")"oldest"
to be explicit.
Reading the latest data leaves the earlier samples intact in the collection buffer. You can
clear the buffer with discardlogs
.
specifies the format of the returned data. The argument value audioData
= readAudio(___,OutputFormat=outFmt)outFmt
is a
string specified as "matrix"
or "timetable"
. The
default is "matrix"
.
[
returns a matrix of audio data samples, and a corresponding timestamp for the first sample
in the buffer. This two variable output requires the default
audioData
,timeStamp
] = readAudio(___)OutputFormat="matrix"
, and is not allowed when
OutputFormat="timetable"
.
Examples
Input Arguments
Output Arguments
Version History
Introduced in R2022b