audioread

Reads an audio file into a matrix of samples and returns its sample rate.

Category: Data Import and Analysis > Data Import and Export

Syntax

[y, Fs] = audioread(filename)

Reads the whole file as doubles scaled to the range -1 to 1.

[y, Fs] = audioread(filename, [start finish])

Reads only samples start through finish.

[y, Fs] = audioread(filename, 'native')

Returns the samples in the type stored in the file, for example int16.

Description

A 16-bit file is mapped so that the integer range becomes roughly -1 to 1, which is the same convention audiowrite uses when it writes. Stereo files give a two-column matrix.

With 'native' the integers are returned untouched, which is useful when you need the exact stored values.

Input arguments

filename
Name of the audio file.
[start finish]
Two sample indices, counted from 1, selecting a segment.
'native'
Skips the conversion to double.

Output arguments

y
Samples, one row per sample and one column per channel.
Fs
Sample rate in hertz.

Example

Write, then read back

audiowrite('s.wav', [0 0.5 -0.5 1]', 8000);
[y, fs] = audioread('s.wav');
y'
fs
z = audioread('s.wav', [2 3])'
[n, ~] = audioread('s.wav', 'native'); class(n)
Output
ans = 1×4

         0    0.5000   -0.5000    1.0000
fs = 8000
z = 1×2

    0.5000   -0.5000
ans = 'int16'

See also

audiowrite audioinfo