audioinfo

Reads the metadata of an audio file without loading its samples.

Category: Data Import and Analysis > Data Import and Export

Syntax

info = audioinfo(filename)

Returns a struct describing the file.

Description

Only the file header is read, so the call is cheap even for long recordings. Use it to learn the sample rate and length before deciding how much to load with audioread. Duration is TotalSamples / SampleRate, in seconds.

Input arguments

filename
Name of the audio file, as a character vector or string.

Output arguments

info
Struct with fields such as Filename, CompressionMethod, NumChannels, SampleRate, TotalSamples, Duration and BitsPerSample.

Example

Header of a WAV file

y = sin(2*pi*440*(0:7999)'/8000);
audiowrite('tone.wav', y, 8000);
info = audioinfo('tone.wav');
fprintf('%d Hz, %d channel(s), %d samples, %g s\n', ...
    info.SampleRate, info.NumChannels, info.TotalSamples, info.Duration);
Output
8000 Hz, 1 channel(s), 8000 samples, 1 s

Notes

MatLivre reads and writes WAV files in this family of functions.

See also

audioread audiowrite