lazy_wav Module

Resources for opening data from Wave (.wav) files

Summary of module contents:

Name Description
WavStream A Stream related to a Wave file
class WavStream(wave_file, keep=False)[source]

Bases: audiolazy.lazy_stream.Stream

A Stream related to a Wave file

A WavStream instance is a Stream with extra attributes:

  • rate: sample rate in samples per second;
  • channels: number of channels (1 for mono, 2 for stereo);
  • bits: bits per sample, a value in [8, 16, 24, 32].
song = WavStream("my_song.wav")
with AudioIO(True) as player:, rate=song.rate, channels=song.channels)


Stereo data is kept serialized/flat, so the resulting Stream yields first a sample from one channel, then the sample from the other channel for that same time instant. Use Stream.blocks(2) to get a Stream with the stereo blocks.

__init__(wave_file, keep=False)[source]

Loads a Wave audio file.

  • wave_file – Wave file name or a already open wave file as a file-behaved object.
  • keep – This flag allows keeping the data on the original range and datatype, keeping each sample an int, as stored. False by default, meaning that the resulting range is already scaled (but not normalized) to fit [-1,1). When True, data scales from - (2 ** (bits - 1)) to 2 ** (bits - 1) - 1 (signed int), except for 8 bits, where it scales from 0 to 255 (unsigned).
_unpackers = {8: <built-in function ord>, 16: <function WavStream.<lambda>.<locals>.<lambda>>, 24: <function WavStream.<lambda>.<locals>.<lambda>>, 32: <function WavStream.<lambda>.<locals>.<lambda>>}