sndread

sndfileio.sndread(path, start=0, end=0)[source]

Read a soundfile as a numpy array.

This is a float array defined between -1 and 1, independently of the format of the soundfile

Parameters:
  • path (str) – the path to read

  • start (float) – the time to start reading

  • end (float) – the time to end reading (0=until the end)

Return type:

sample_t

Returns:

a tuple (samples – ndarray[dtype=float], sr: int)

Example

# Normalize and save as flac
from sndfileio import sndread, sndwrite
samples, sr = sndread("in.wav")
maxvalue = max(samples.max(), -samples.min())
samples *= 1/maxvalue
sndwrite(samples, sr, "out.flac")