wavfile.wavwrite module

Provides the WavWrite class for writing wave files.

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

class wavfile.wavwrite.WavWrite(fp: Union[str, PathLike, IO], sample_rate: int = 44100, num_channels: Optional[int] = None, bits_per_sample: int = 16, fmt: WavFormat = WavFormat.PCM)

Bases: Wavfile

Class for writing a wave file

__init__(fp: Union[str, PathLike, IO], sample_rate: int = 44100, num_channels: Optional[int] = None, bits_per_sample: int = 16, fmt: WavFormat = WavFormat.PCM) None

Initialise the WavWrite object.

Parameters
  • fp – Either a path to a wave file or a pointer to an open file.

  • sample_rate – The sample rate for the new file.

  • num_channels – The number of audio channels for the new file.

  • bits_per_sample – The number of bits to encode each audio sample.

  • fmt – The audio format (chunk.WavFormat.PCM, chunk.WavFormat.IEEE_FLOAT)

write(audio: List[List[Union[int, float]]]) None

Write audio data to the file. The data should be a list of lists with dimensions (N,C), where N is the number of frames and C is the number of audio channels. The data may be int or float. The data may be converted if they do match the format of the destination file.

Parameters

audio – Audio frames to write.

close() None

Close the file.