wavfile.wavread module

Provides the WavRead class for reading wave files.

The WavRead class is returned by wavfile.open() when opening a file in read mode.

class wavfile.wavread.WavRead(f: str | PathLike | IO)

Bases: Wavfile

Class for reading a wave file

__init__(f: str | PathLike | IO) None

Initialise the WavRead object.

Parameters:

f – Either a path to a wave file or a pointer to an open file.

__copy__() WavRead

Create a shallow copy of the WavRead object.

close() None

Close the wav file.

read_int(num_frames: int | None = None) List[List[int]]

Read, at most, num_frames frames from the audio stream in integer format. The method returns a list of lists with dimensions (N,C), where C is the number of audio channels. Choosing N = None or N < 0 will read all remaining samples.

Parameters:

num_frames – Maximum number of frames to read.

Returns:

The audio samples as a list of lists.

iter_int(num_frames: int | None = None) Generator[List[List[int]], None, None]

This method is equivalent to read_int(), except that it returns a generator rather than a block of sample.

Parameters:

num_frames – Number of frames to read on each iteration.

Returns:

A generator to yield the next frame(s) of audio.

read_float(num_frames: int | None = None) List[List[float]]

Read, at most, num_frames frames from the audio stream in float format in the range [-1, 1). The method returns a list of lists with size [N][C], where C is the number of audio channels. Choosing N = None or N < 0 will read all remaining samples.

Parameters:

num_frames – Maximum number of frames to read.

Returns:

The audio samples as a list of lists.

iter_float(num_frames: int | None = None) Generator[List[List[float]], None, None]

This method is equivalent to read_float(), except that it returns a generator rather than a block of samples.

Parameters:

num_frames – Number of frames to read on each iteration.

Returns:

A generator to yield the next frame(s) of audio.

read(num_frames: int | None = None) List[List[int | float]]

Read, at most, num_frames frames from the audio stream in its native format. The method returns a list of lists with dimensions (N,C), where C is the number of audio channels. Choosing N = None or N < 0 will read all remaining samples.

Parameters:

num_frames – Maximum number of frames to read.

Returns:

The audio samples as a list of lists.

iter(num_frames=None) Generator[List[List[int | float]], None, None]

This method is equivalent to read(), except that it returns a generator rather than a block of samples.

Parameters:

num_frames – Number of frames to read on each iteration.

Returns:

A generator to yield the next frame(s) of audio.