sndread_chunked

sndfileio.sndread_chunked(path, chunksize=2048, start=0.0, stop=0.0)[source]

Read a soundfile in chunks

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

  • chunksize (int) – the chunksize, in samples

  • start (float) – time to skip before reading

  • stop (float) – time to stop reading (0=end of file)

Return type:

Iterator[np.ndarray]

Returns:

a generator yielding numpy arrays (float64) of at most chunksize frames

Example

>>> with sndwrite_chunked("out.flac", 44100) as writer:
...     for buf in sndread_chunked("in.flac"):
...         # do some processing, like changing the gain
...         buf *= 0.5
...         writer.write(buf)