Audio input

Which spoken words decided an audio model’s answer? Each word is a player; silencing it and re-scoring the answer measures its weight. Two examples come first, then each backend’s audio support and cost.

Waveform of a spoken question with one segment per word; the word "constant" is shaded strong blue.

Qwen2-Audio-7B hears “Does the speed of sound vary with changes in frequency at constant temperature?” and says no (reference: yes). “Constant” alone pulls toward “No” (blue).

Waveform of a spoken question; the word "affiliated" is shaded strong red.

“Is Aldi’s affiliated with Trader Joe’s?”: the word “affiliated” carries the “Yes” (red).

Values are log-odds of “Yes” against “No” (label_margin); they sum to the gap between the full and the silenced recording. Notebook: Which spoken word decided the answer?; typed and spoken words on one scale: Visualization.

Backends

A message can carry AudioPart content next to its text. With players: sgpa_segments (Audio alignment) policies cut or silence absent words; the backend decides what the model hears.

kind

Extra

Audio parts

transformers

[transformers,audio]

Sent to audio language models through their processor

api

[api]

Sent as OpenAI input_audio parts (base64 WAV)

lmstudio

[lmstudio]

Refused by default; audio: transcript sends the text parts only

mock_audio

(core)

One token per voiced run, for tests and demos

Audio language models in transformers

TransformersTextBackend reads the checkpoint’s config. A model AutoModelForCausalLM knows loads as a text model and refuses audio with ValueError. Others load their own class (architectures or backend.options.model_class) with AutoProcessor and take audio. Set model_class for a multimodal model AutoModelForCausalLM also knows, such as Gemma 3n.

  • Audio is resampled to the processor’s rate.

  • A chat template that mentions audio gets each message’s audio, then its text. Else each part becomes the processor’s audio_token and the waveforms go to processor(text=..., audio=...) (Granite Speech).

  • Audio emptied by masking is dropped with its token.

  • Audio prompts skip the prefix cache; logprobs and embeddings work as for text.

backend:
  kind: transformers
  model_id: ibm-granite/granite-speech-3.3-2b
  options:
    revision: 4ac2f02f413c6169ae8c0ccc217115a366e552d7
    dtype: bfloat16
    attn_implementation: eager  # Granite's projector fails under SDPA on MPS

explanation:
  players: sgpa_segments
  absence_policy: delete

Cost: exact values over \(n\) spoken words take \(2^n\) generations, no prefix cache. On an Apple M4, Granite Speech scores 64 coalitions of nine words in about a minute (complementary, budget.fraction: 0.125, Choosing an estimator); all 512 take about eight times as long.

Granite needs torchaudio and peft (audio adapter), both in the transformers extra. backend.options.attn_implementation goes to from_pretrained. Notebook: Explaining a spoken sentence with an audio language model.

HTTP API

ApiBackend sends a message’s text, then one input_audio part per audio part. WAV goes as is; other formats become WAV (extra audio).

{"role": "user", "content": [
  {"type": "text", "text": "Transcribe this recording."},
  {"type": "input_audio", "input_audio": {"data": "UklGR...", "format": "wav"}}
]}

A server without audio support answers with an error: BackendUnavailableError.

LM Studio

The LM Studio SDK takes no audio, so LmStudioBackend raises ValueError. backend.options.audio: transcript sends only the text parts and warns once; the run then explains the masked transcript.

Mock

MockAudioBackend (mock_audio) echoes each message’s words, then one token per voiced run of audio: louder than 1% of full scale, split by 10 ms of silence or more. Each token hashes its run’s samples, so silencing a spoken word drops only its token. It reads 16-bit WAV without extras; other formats need audio. Notebook: Audio runs on the mock backend.