Main Content

read

Get recorded audio data

Since R2025a

    Description

    recordedAudio = read(as) returns the audio data that has been recorded by the audiostreamer.

    example

    recordedAudio = read(as,numSamples) reads the specified number of samples. This syntax blocks MATLAB® execution until the specified number of samples are available to read. The audiostreamer NumRecorderSamples property specifies the number of samples currently available to read.

    Examples

    collapse all

    Create an audiostreamer object with the "recorder" mode.

    as = audiostreamer("recorder");

    Call record to start recording with the audiostreamer. The audiostreamer will record continuously until you pause or stop the recording. Use the MATLAB pause function to wait for three seconds, then call stop on the audiostreamer object to stop recording.

    record(as)
    pause(3)
    stop(as)

    Call read to get all of the available recorded audio from the audiostreamer.

    x = read(as);

    Alternatively, you can call record with a specified number of samples after which the recording will automatically stop. Calling read with the specified number of samples will block MATLAB execution until that number of samples has been recorded.

    N = 3*as.SampleRate; % 3 seconds of samples
    record(as,N)
    y = read(as,N);

    Input Arguments

    collapse all

    The audiostreamer object used to record the audio.

    Number of audio samples to read, specified as a positive integer.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Output Arguments

    collapse all

    Recorded audio data, returned as a matrix where columns correspond to individual audio channels.

    Version History

    Introduced in R2025a