This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

dsp.AudioFileReader System object

Stream from audio file


The AudioFileReader object reads audio samples from an audio file.

To read audio samples from an audio file:

  1. Define and set up your audio file reader object. See Construction.

  2. Call step to read audio samples according to the properties of dsp.AudioFileReader. The behavior of step is specific to each object in the toolbox.


Starting in R2016b, instead of using the step method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, y = step(obj) and y = obj() perform equivalent operations.


afr = dsp.AudioFileReader returns an audio file reader System object, afr that reads audio from an audio file.

afr = dsp.AudioFileReader('PropertyName',PropertyValue,...) returns an audio file reader System object, afr, with each specified property set to the specified value.

afr = dsp.AudioFileReader(Filename,'PropertyName',PropertyValue,...) returns an audio file reader object, afr, with Filename property set to FILENAME and other specified properties set to the specified values.



Name of audio file from which to read

Specify the name of an audio file as a character vector. Specify the full path for the file only if the file is not on the MATLAB® path. The default is speech_dft.mp3.


Number of times to play file

Specify a positive integer as the number of times to play the file. The default is 1.


Sampling rate of the audio file

This read-only property displays the sampling rate, in Hz, of the audio file.


Number of samples in audio frame

Specify the number of samples in an audio frame as a positive, scalar integer value. The default value is 1024.


Data type of output

Set the data type of the audio data output from the audio file reader object. Specify the data type as double| single | int16 | uint8. The default is double.

Supported Platforms and File Types

The following table lists the supported audio file formats:

PlatformsFile Name Extensions
Windows®.wav, .wma, .avi, .aif, .aifc, .aiff, .mp3, .au, .snd, .mp4, .m4a, .flac, .ogg, .mov
Non-Windows.avi, .mp3, .mp4, .m4a, .wav, .flac, .ogg, .aif, .aifc, .aiff, .au, .snd, .mov


infoInformation about specific audio file
isDoneEnd-of-file status (logical)
resetReset internal states of audio file reader to read from beginning of file
stepRead audio samples from audio file
Common to All System Objects

Create System object with same property values


Expected number of inputs to a System object


Expected number of outputs of a System object


Check locked states of a System object (logical)


Allow System object property value changes


expand all

This example shows how to read and play back an audio file using the standard audio output device.

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For dsp.AudioFileReader System object™, myObject() becomes step(myObject). For all other objects, myObject(x) becomes step(myObject,x).

afr = dsp.AudioFileReader('speech_dft.mp3');
adw = audioDeviceWriter('SampleRate', afr.SampleRate);

while ~isDone(afr)
    audio = afr();


This object implements the algorithm, inputs, and outputs described on the From Multimedia File block reference page. The object properties correspond to the block parameters, except:

  • The object has no corresponding property for the Inherit sample time from file block parameter. The object always inherits the sample time from the file.

  • The object has no corresponding property for the Output end-of-file indicator parameter. The object always outputs EOF as the last output.

  • The object has no corresponding property for the Multimedia Outputs parameter because audio is the only supported output.

  • The object has no corresponding property for the Image signal block parameter.

  • The object has no corresponding property for the Output color format parameter.

  • The object has no corresponding property for the Video output data type parameter.

Extended Capabilities

Introduced in R2012a

Was this topic helpful?