IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python function

encode_wav_bytes

encode_wav_bytes()

max.serve.media.encode_wav_bytes(samples, sample_rate)

source

Encodes a float waveform as a 16-bit PCM WAV payload.

16-bit is what the format’s ubiquitous reader path expects and what every client can play; a generative model’s own noise floor sits well above the quantization step, so the width costs nothing audible.

Parameters:

  • samples (ndarray[tuple[Any, ...], dtype[float32]]) – [channels, samples] float array with values in [-1, 1]. Values outside that range are clipped, which is what a decoder would do to them anyway.
  • sample_rate (int) – Sample rate of the waveform, in hertz.

Returns:

The complete WAV file, header included.

Raises:

ValueError – If the waveform is not 2D, has no channels or no samples, or the sample rate is not positive.

Return type:

bytes