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 class

AudioContext

AudioContext

class max.pipelines.context.AudioContext(*, tokens, request_id=<factory>, model_name='', negative_tokens=None, audio_duration, num_inference_steps, guidance_scale=None, seed=None, audio_format='wav', waveform=None, status=GenerationStatus.ACTIVE)

source

Bases: object

A model-ready context for audio generation requests.

Like PixelContext, this carries only what the model executes against: the caller’s text has already been through the tokenizer, and what is left is token ids plus the numbers that size the generation.

Parameters:

  • tokens (TokenBuffer) – The conditional prompt’s token ids.
  • request_id (RequestID) – A unique identifier for this generation request.
  • model_name (str) – Name of the model being used.
  • negative_tokens (TokenBuffer | None) – The unconditional prompt’s token ids, for models that generate with classifier-free guidance.
  • audio_duration (float) – Upper bound on the generated audio, in seconds. A model may stop earlier, so the waveform’s own length is the authority on what was produced. Required, because what a request leaves unset is the checkpoint’s default rather than any value this framework could pick, and the tokenizer resolves it.
  • num_inference_steps (int) – Denoising steps, for models whose audio comes from a diffusion or flow-matching stage. Required, for the same reason as audio_duration.
  • guidance_scale (float | None) – Classifier-free guidance scale, or None to leave it to the model. Audio models often bake distinct scales into distinct stages, and a single request-level number cannot say which one it means.
  • seed (int | None) – RNG seed for the sampling the model does.
  • audio_format (str) – Container the waveform is encoded into for the response.
  • waveform (ndarray[tuple[Any, ...], dtype[float32]] | None) – The generated samples, once there are any.
  • status (GenerationStatus)

audio_duration

audio_duration: float

source

audio_format

audio_format: str = 'wav'

source

compute_num_available_steps()

compute_num_available_steps(max_seq_len)

source

Returns the denoising steps, for scheduler compatibility.

Parameters:

max_seq_len (int)

Return type:

int

guidance_scale

guidance_scale: float | None = None

source

is_done

property is_done: bool

source

Whether the request has completed generation.

model_name

model_name: str = ''

source

negative_tokens

negative_tokens: TokenBuffer | None = None

source

Unconditional prompt tokens. None for models that do not guide.

num_inference_steps

num_inference_steps: int

source

request_id

request_id: RequestID

source

reset()

reset()

source

Resets the context’s state.

Return type:

None

seed

seed: int | None = None

source

status

status: GenerationStatus = 'active'

source

tokens

tokens: TokenBuffer

source

Conditional prompt tokens.

update()

update(waveform)

source

Stores the generated samples on the context.

Parameters:

waveform (ndarray[tuple[Any, ...], dtype[float32]])

Return type:

None

waveform

waveform: ndarray[tuple[Any, ...], dtype[float32]] | None = None

source

Generated samples in (channels, samples) layout, in [-1, 1].