Skip to Content
FeaturesModulesLLM IntegrationTranscription

Transcription

django_llm.features.transcribe turns audio into text through a chain of models. A provider’s content filter does not fail the job: the piece moves to the next model, then to smaller pieces, and at worst becomes a recorded gap.

from django_cfg.modules.django_llm.features.transcribe import ( DEFAULT_CHAIN, Policy, make_ask, transcribe, ) result = transcribe( duration_s, # length of the recording cut, # cut(offset_s, seconds) -> audio bytes (mp3) make_ask(call), # call(path, payload) -> decoded JSON; raises with .status DEFAULT_CHAIN, policy=Policy(chunk_s=300), done=earlier_segments, # optional: keep finished pieces, ask only the rest on_progress=lambda covered, total: ..., ) result.text; result.language; result.segments; result.gaps result.cost_usd; result.models; result.complete

cut and call are yours (ffmpeg and your HTTP client), so the policy runs without network in tests.

What happens to one piece

AnswerTreatment
TextDone. The segment names the model that answered.
Block: PROHIBITED_CONTENT, finish_reason content_filter, promptFeedback.blockReason, content_policy_violationContentBlocked. That model is never asked again for this audio (it would answer the same). Next entry.
429, 5xx, dropped connectionTransient. Waits pause_s · 2^round · jitter, asks the models that are still in play.
404 or an answer shape we do not knowModelUnavailable. That entry is skipped.
401, 402Fatal. No model helps; stops at once.
Cut short (finish_reason length)Next entry is tried; the last answer is kept.

A block is a status 200 body, not an HTTP error: treating it as an “unexpected response” and retrying is the usual mistake.

If every entry blocked a piece, it is halved (while each half stays at least floor_s, at most max_depth times; offsets stay correct) and the halves run on their own. A piece still blocked at the floor becomes Gap(reason="blocked") and the rest continues. If time-mendable faults outlast rounds, the piece is a Gap(reason="failed", retryable=True): rerun with done=result.segments to ask only the missing ranges. NothingTranscribed is raised only when no text came out at all.

Cost

A refused call is often billed. Every attempt is counted: result.cost_usd is the whole bill, and each Segment.cost_usd is everything spent on that piece, with model set to the model that finally answered. A Gap carries what its refused attempts cost.

The chain

DEFAULT_CHAIN is data in defaults.py: a speech-to-text model first, then cheap chat models alternating vendors, because filters differ by vendor. Pass your own tuple of ChainEntry(model, engine, diarize), or chain_for(slugs) to build one from slugs (an STT slug that can label speakers is asked with labels on, the rest as chat); engine="stt" posts to /audio/transcriptions (a dedicated speech-to-text model) instead of /chat/completions. OpenRouter serves that route; SDKRouter does not (404 on /v1/audio/transcriptions, probed 2026-11-05), so probe your own gateway before relying on stt.

Speaker labels

The first entry is microsoft/mai-transcribe-2 with diarize=True: it labels who speaks (provider.options.azure.diarization.enabled, response_format=verbose_json; the options live in engines.DIARIZATION). Measured 2026-11-12 on 8 minutes of a two-voice Russian call: two speakers, 50 segments, 3 s, $0.10 per audio hour (x-ai/grok-stt-1.0 returned one unlabelled segment). The answer text reads as turns, numbered from 1 in order of first appearance, one paragraph each:

Speaker 1: ... Speaker 2: ...

One voice, or an answer without speaker ids, stays plain text. Numbers are per piece: the same person can be Speaker 1 in one piece and Speaker 2 in the next, so a consumer that reads a long recording must decide who is who from what is said. The chat models behind it return unlabelled text; they take over when the STT model refuses or is down. STT takes no earlier text as context, so short consecutive pieces of a live capture should be asked of the chat entries only.

The chat part of the default chain (qwen/qwen3.8-omni-flash, openai/gpt-audio-mini, google/gemini-3.5-flash-lite, google/gemini-3.1-flash-lite) comes from trying each model on a real 10-minute Russian piece that google/gemini-2.5-flash refused: the 2.5 family blocks it, the four above pass (about $0.0015 to $0.0096 for the piece), Voxtral answered 429 and the free NVIDIA model was unusable. Choose your own order the same way: on a real blocked recording, not from price lists.

Troubleshooting

  • PROHIBITED_CONTENT with HTTP 200. A content filter, not a fault. The chain handles it; if every entry blocks, check result.gaps for the time ranges.
  • A note stuck “pending” after a 429. The 429 is the fallback’s rate limit passed through the gateway. It is Transient: widen rounds and pause_s, and rerun with done= later.
  • Charged for a failed piece. Expected: refusals are billed. It is in result.cost_usd and the gap’s cost_usd.
Last updated on