Read collected audio data from mobile device microphone
reads the number of samples indicated by
audioData = readAudio(
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(
"oldest" to be explicit.
Reading the latest data leaves the earlier samples intact in the collection buffer. You can
clear the buffer with
specifies the format of the returned data. The argument value
audioData = readAudio(___,OutputFormat=outFmt)
outFmt is a
string specified as
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
timeStamp] = readAudio(___)
OutputFormat="matrix", and is not allowed when
Read Audio Signals from Mobile Device
Using MATLAB® Mobile™ on your phone or tablet, you must enable sensor access to the device microphone. Select Stream to > MATLAB.
In MATLAB, connect to your device and read the first (oldest) 1000 samples into a matrix.
devObj = mobiledev; audioData = readAudio(devObj,1000);
Read the most recent 10 seconds of buffered audio data into a timetable.
audioData = readAudio(devObj,seconds(10),"latest",OutputFormat="timetable");
devObj — mobile device
Mobile device, specified as a
mobiledev object. Use the
mobiledev function to make this object and connect to the device.
span — Length of read operation
duration | double
Length of read operation, specified as a duration or double. If this is a duration type, it specifies the time duration of the acquired samples. If it is a double, it specifies the number of samples.
audioData — Audio samples captured by device microphone
matrix | timetable
Audio samples captured by device microphone, returned as a matrix of size
NumChannels or as a timetable,
with data values normalized in the range
timeStamp — Time of first sample in buffer
Time of first sample in the collection buffer, returned as a datetime. This argument
is available only when
OutputFormat is specified as
Introduced in R2022b