dsp.AudioFileReader System object

Package: dsp

Read audio samples 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.


H = dsp.AudioFileReader returns an audio file reader System object™, H that reads audio from an audio file. This audio file can be of the following formats on all platforms:

  • MP3

  • M4a

  • MP4

  • WAV

  • FLAC

  • OGG

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

H = dsp.AudioFileReader(Filename,'PropertyName',PropertyValue,...) returns an audio file reader object, H, 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 string. 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 hertz, 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 int16.


cloneCreate audio file reader object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs of step method
infoInformation about specific audio file
isDoneEnd-of-file status (logical)
isLockedLocked status for input attributes and nontunable properties
releaseAllow property value and input characteristics changes
resetReset internal states of audio file reader to read from beginning of file
stepRead audio samples from audio file


Read and play back an audio file using the standard audio output device.

      hmfr = dsp.AudioFileReader('speech_dft.mp3');
      hap = dsp.AudioPlayer('SampleRate', hmfr.SampleRate);

      while ~isDone(hmfr)
         audio = step(hmfr);
         step(hap, audio);

      release(hmfr); % release the input file
      release(hap);  % release the audio output device


Running an Executable Outside MATLAB

To run your generated standalone executable application in Shell, you need to set your environment to the following:

Macsetenv DYLD_LIBRARY_PATH $LD_LIBRARY_PATH: $MATLABROOT/bin/maci64 (csh/tcsh)


Linuxsetenv LD_LIBRARY_PATH $LD_LIBRARY_PATH: $MATLABROOT/bin/glnxa64 (csh/tcsh)


Windowsset PATH = $MATLABROOT\bin\win32;%PATH%

set PATH = $MATLABROOT\bin\win64;%PATH%


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.

Was this topic helpful?