wavfile package

Read/write wave audio files to/from lists of native Python types.

The library currently supports PCM (integer) and IEEE float formats, and supports arbitrary integer precision, including: 16-, 24-, 32-, and 64-bit samples.

wavfile.open(f: Union[str, PathLike, IO], mode: Optional[str] = None, sample_rate: int = 44100, num_channels: Optional[int] = None, bits_per_sample: int = 16, fmt: WavFormat = WavFormat.PCM) Union[WavRead, WavWrite]

Open the wave file.

If writing and num_channels is unspecified, it is determined automatically from the first block of samples.

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

  • mode – Open the file for reading (‘r’, ‘rb’) or writing (‘w’, ‘wb’).

  • sample_rate – The sample rate for the new file (write only).

  • num_channels – The number of audio channels for the new file (write only).

  • bits_per_sample – The number of bits to encode each audio sample (write only).

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

Returns

Returns a wavfile.wavread.WavRead object or wavfile.wavwrite.WavWrite object.

wavfile.read(path: Union[str, PathLike], fmt: str = 'int') Tuple[List[List[Union[int, float]]], int, int]

Shortcut function to read a wave file. The audio can be read directly (fmt='native'), converted to integers (fmt='int'), or converted to floating point (fmt='float').

Parameters
  • path – Path to the wave audio file.

  • fmt – Read the file as ‘int’, ‘float’, or ‘native’.

Returns

The audio data, the sample rate, and the bit depth.

wavfile.write(path: Union[str, PathLike], audio_data: List[List[Union[int, float]]], sample_rate: int = 44100, bits_per_sample: int = 16, fmt: WavFormat = WavFormat.PCM) None

Shortcut function to write a wave file. The data should be contained in a list of lists with size (N,C), where 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
  • path – Path to the newly created wave file.

  • audio_data – The data to be written to the file.

  • sample_rate – The sample rate for the new file.

  • bits_per_sample – The number of bits to encode each audio sample (write only).

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

wavfile.split(path: Union[str, PathLike]) None

Split a multichannel wave file in to multiple mono wave files.

Parameters

path – Path to the multichannel wave file.

Submodules