Stream to audio file
object™ writes audio samples to an audio file.
To write audio samples to an audio file:
dsp.AudioFileWriter object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects? (MATLAB).
audio file writer System
afw = dsp.AudioFileWriter
afw. This object writes audio samples to an
returns an audio file writer System
afw = dsp.AudioFileWriter(
afw. This object has the
Filename property set to
returns an audio file writer object with each specified property set to the
specified value. Enclose each property name in single quotes. Unspecified
properties have default values.
afw = dsp.AudioFileWriter(
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).
Filename— Name of audio file to which to write
'output.wav'(default) | character vector | string scalar
Specify the name of the audio file as a character vector or a string scalar.
FileFormat— Audio file format
Specify which audio file format the object writes. On Microsoft® platforms, select one of
'WMA'. On Linux® platforms, select one of
'OGG'. On macOS platforms, select one of
'MPEG4'. These abbreviations correspond to the
following file formats:
'AVI': Audio-Video Interleave
'WAV': Microsoft WAVE Files
'FLAC': Free Lossless Audio Codec
'OGG': Ogg/Vorbis Compressed Audio
'MPEG4': MPEG-4 AAC File — You can
The default is
SampleRate— Sampling rate of audio data stream
44100(default) | positive scalar
Specify the sampling rate of the input audio data as a positive, numeric scalar value.
Compressor— Algorithm that compresses audio data
'None (uncompressed)'(default) |
Specify the type of compression algorithm the audio file writer uses to
compress the audio data. Compression reduces the size of the audio file.
'None (uncompressed)' to save uncompressed audio
data to the file. The other options available reflect the audio compression
algorithms installed on your system. You can use tab completion to query
Compressor options for your computer
H.Compressor = ' and then pressing the tab
This property applies when writing WAV or AVI files on Windows® platforms.
DataType— Data type of the uncompressed audio
Specify the type of uncompressed audio data written to the file as
This property only applies when writing uncompressed WAV files.
audio— Audio samples
One frame of audio samples, returned as a column vector or a matrix. A column vector input indicates a mono audio input. An M-by-N matrix indicates an N-channel audio input.
If the input is fixed-point, the input must be a signed fixed-point input with power-of-two slope and zero bias.
To use an object function, specify the
object as the first input argument. For
example, to release system resources of a System
The following platform-specific restrictions apply when writing these files:
Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent
step syntax. For example,
Decimate an audio signal, and write it to disk as a WAV file.
afr = dsp.AudioFileReader('OutputDataType',... 'double'); firdec = dsp.FIRDecimator; % decimate by 2 afw = dsp.AudioFileWriter... ('speech_dft.wav', ... 'SampleRate', afr.SampleRate/2); while ~isDone(afr) audio = afr(); audiod = firdec(audio); afw(audiod); end release(afr); release(afw);
This object implements the algorithm, inputs, and outputs described on the To Multimedia File block reference page. The object properties correspond to the block parameters, except:
FileFormat property does not support
video-only file formats.
The object has no corresponding property for the Write parameter. The object writes only audio content to files.
The object has no corresponding property for the Video compressor parameter.
The object has no corresponding property for the File color format parameter.
The object has no corresponding property for the Image signal parameter.
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).
The executable generated from this System
object relies on prebuilt dynamic library files
.dll files) included with MATLAB®. Use the
packNGo function to package
the code generated from this object and all the relevant files in a
compressed zip file. Using this zip file, you can relocate, unpack, and
rebuild your project in another development environment where
MATLAB is not installed. For more details, see How To Run a Generated Executable Outside MATLAB.