music.read_audio

music.read_audio(filename)[source]

Read an audio file and return an array of its values.

Parameters:
filenamestr

The path to read. WAV and FLAC are understood; the container is whatever the file says it is, not what the extension claims.

Returns:
NDArray

The samples in [-1, 1], mono as (nsamples,) and stereo as (2, nsamples). Integer PCM is divided by its own full scale; a float WAV declares none, so it is scaled by its own peak.

Raises:
ValueError

If the file’s encoding is one this package cannot normalize – anything outside READABLE_SUBTYPES. libsndfile will decode ADPCM and companded formats happily, but they have no full scale the normalization is defined against, so being decodable is not the same as being supported.

Parameters:

filename (str)

Return type:

NDArray[float64]

Examples

>>> write_audio(note(freq=440, duration=0.5), "tone.flac")
>>> read_audio("tone.flac").shape      # any format libsndfile reads
(22050,)