Audio MCP: transcription backend configuration¶
The audio MCP exposes the same tools regardless of the ordinary STT backend:
transcribe_audio(file_path, language?), transcribe_audio_diarized(...),
generate_speech(...), and send_voice_note(...). Ordinary transcription still
returns one text result. Agents do not select a provider in tool arguments.
Short calls and durable long-running jobs¶
Keep transcribe_audio for short recordings (roughly under 45 seconds). It remains
synchronous and returns text directly: no job queue, new probing step or polling.
For longer recordings, use the new ordinary-STT job tools instead:
start_transcription_job(file_path, language?)snapshots the UID-owned input and returns JSON withidandstate: queuedimmediately after the bounded copy.status_transcription_job(job_id)reports queued/running/completed/failed/ cancelling/cancelled andcompleted_seconds. This is completed audio, not a heartbeat or provider health guarantee. Poll between turns, not in a blocking loop with a whole-job codemode deadline.result_transcription_job(job_id, start_chunk?, limit?)pages ordered timestamped chunks, including partial results; default/max 20 chunks per page. Only call the result complete when state is completed.next_chunkis the next page offset.cancel_transcription_job(job_id)requests cancellation; the worker kills actual in-flight processing (including subprocess descendants) and keeps saved chunks.resume_transcription_job(job_id)explicitly resumes failed/cancelled/interrupted work. Committed chunks are not retranscribed. Backend/model/language or recipe changes refuse resume rather than silently changing provider or mixing versions. Credential rotation does not invalidate the recipe.
The job worker is a separate per-agent system-manager service, triggered by a
.path unit only while queued markers exist. It is not a detached subprocess in the
socket service cgroup, needs no systemd user bus and runs under the same agent UID.
Both worker and MCP use the existing managed environment files; credentials are not
copied into job JSON, new environment files or command-line arguments. No idle Python
worker daemon is kept running. The ordinary short-call server can remain responsive
while a background job is processing.
There is no total job-duration deadline or one-hour whole-recording rejection. Jobs use sequential sections of at most five minutes, bounded per-operation deadlines, 16kHz mono PCM16 and incremental per-section conversion. Decoding continues until actual EOF, not ffprobe/container duration metadata. There is no endpoint/vendor substitution. The existing MAI per-session bound is retained. This first version uses exact non-overlapping time sections and does not attempt word-level overlap merging/deduplication; context/word accuracy at a hard section boundary needs separate speech-quality evaluation. No global diarization/speaker continuity is claimed.
Input must be a real non-symlink regular file owned by the calling UID. The source is
copied privately (0700 directories/0600 files), so deleting the attachment afterwards
does not invalidate queued work. State and chunks are atomic/fsynced local records
under ~/.cache/agentctl/audio-jobs/. Default limits: 512 MiB input, 2 GiB retained
storage, eight outstanding jobs, one worker per agent; each transcript chunk is capped
at 128 KiB, and result pages are bounded. The worker has 512 MiB memory / 64 MiB
per-file / 64-task systemd limits and lower CPU/I/O priority than interactive calls.
These are explicit resource constraints, not silent transcript truncation. Failures
stop the job; retries are explicit via resume, not an unbounded automatic loop.
Inputs/results remain until the owner explicitly removes finished job directories.
FFmpeg file/pipe-only protocols prevent media playlists from fetching arbitrary URLs.
Deployment: package upgrade alone is insufficient. Apply/re-add the effective
per-user audio catalog so the staged worker and mcp-audio-jobs-<agent>.path/.service
are installed and the path unit is enabled. An old overlay can shadow the new payload.
Unwiring audio stops the path/worker but preserves job evidence; rewire can resume
interrupted queued work. A service restart/reboot picks up queued markers and saved
chunks. This does not remove the old synchronous MCP/CLI timeout limits: callers that
explicitly keep using transcribe_audio for long files can still time out.
Offline verification uses generated local TLS credentials, real FFmpeg, process cancellation and a synthetic HTTP-compatible backend. A logical >1-hour job test is accelerated; it is not a multi-hour live inference or a deployed systemd activation proof. Pilot deployment must verify path activation, connection closure/restart, actual long MAI input, and a short call during a running job before broader rollout.
Common configuration for all three capabilities¶
Every capability uses <PREFIX>_BACKEND, <PREFIX>_MODEL, optional
<PREFIX>_BASE_URL, and <PREFIX>_API_VERSION, with prefixes STT, TTS,
and DIARIZE. An unset capability base reuses OPENAI_BASE_URL. All currently
implemented adapters reuse OPENAI_API_KEY. Backend defines protocol/auth;
base URL defines destination and remains independently configurable.
| Capability | Supported backends | Default |
|---|---|---|
| STT | openai, azure-openai, mai-realtime |
legacy-compatible unset |
| TTS | openai, azure-openai |
openai |
| Diarization | openai |
openai |
openai means OpenAI-compatible HTTP, including Azure v1, not necessarily the
public vendor. azure-openai means deployment-specific REST with api-key.
TTS uses JSON input/voice/format/speed, includes model for v1, and omits model
when the deployment URL already selects it. Diarization uses multipart model,
file, diarized_json, chunking_strategy=auto, optional language and paired
known-speaker references. Unsupported combinations fail before a network call;
MAI streaming is not claimed to implement diarization. DIARIZE_API_VERSION is
reserved and unused by its current v1 backend.
DIARIZE_MODEL takes precedence over the deprecated STT_DIARIZE_MODEL alias.
Default remains gpt-4o-transcribe-diarize. No automatic model guessing or fallback.
TTS API version defaults to 2025-04-01-preview for deployment REST. Shared
v1 base can be used as-is; the deployment adapter strips /openai/v1 before
constructing the deployment route. An alternate approved v1 API root can be
provided per capability without redirecting the other two.
Backend selection¶
Selection is explicit, not inferred from the model name:
| Variable | Default | Purpose |
|---|---|---|
STT_BACKEND |
unset | Explicit openai, azure-openai, or mai-realtime. Unset preserves legacy configuration. |
STT_MODEL |
gpt-4o-mini-transcribe |
HTTP model or MAI Foundry deployment name. |
STT_BASE_URL |
unset | Optional STT-only endpoint override; otherwise reuse OPENAI_BASE_URL. |
OPENAI_API_KEY |
required | Existing key; MAI sends it in the api-key header. |
STT_API_VERSION |
2025-04-01-preview |
Azure deployment REST API version; unused by OpenAI v1 and MAI. |
AZURE_OPENAI_TRANSCRIPTIONS_URL |
unset | Deprecated fallback only when both STT_BACKEND and STT_BASE_URL are unset. |
OPENAI_BASE_URL |
public OpenAI v1 | Existing HTTP root for TTS, diarization and non-Azure ordinary HTTP STT. |
STT_LANGUAGE |
unset | Optional default language hint; tool-call hint takes precedence. |
Enable MAI with the backend and deployment name. Keep the shared URL unchanged;
STT_BASE_URL is optional if the shared endpoint is already the same Azure resource.
The following example shows an explicit override:
STT_BACKEND=mai-realtime
STT_BASE_URL=https://<resource>.services.ai.azure.com
STT_MODEL=MAI-Transcribe-2-Streaming
Use the actual deployment name if it differs. For MAI/Azure, resource roots or the
shared /openai/v1 URL are accepted; /models and deployment-specific paths are not.
MAI strips the shared API path and normalizes Azure's .openai.azure.com hostname to
.services.ai.azure.com for the same resource. It constructs the WSS route
/mai/v1/realtime?intent=transcription. Keys never appear in URLs.
OpenAI v1 appends /audio/transcriptions to its API root. Azure deployment REST
constructs /openai/deployments/<STT_MODEL>/audio/transcriptions?api-version=<STT_API_VERSION>
and authenticates with api-key. Thus new settings need no separate Azure full URL.
Unknown backends fail explicitly. Setting only STT_MODEL does not select MAI.
Any explicit backend or STT base overrides the deprecated Azure full URL.
There is no silent fallback to another model/provider.
TTS stays on the existing OpenAI-compatible backend (TTS_MODEL, TTS_VOICE,
TTS_SPEED, TTS_FORMAT). Diarization stays on its existing backend
(STT_DIARIZE_MODEL); MAI streaming does not replace speaker-labelled
transcription or known-speaker reference matching. Do not change
OPENAI_BASE_URL when switching ordinary STT.
Managed configuration and rollout¶
Use the existing encrypted environment store. Prefer a per-agent pilot over shared fleet values. An admin/operator can set the non-secret values with:
agentctl secret set STT_BACKEND --agent <agent> --value mai-realtime
agentctl secret set STT_BASE_URL --agent <agent> --value https://<resource>.services.ai.azure.com
agentctl secret set STT_MODEL --agent <agent> --value MAI-Transcribe-2-Streaming
Reuse OPENAI_API_KEY; do not copy keys into the ledger or shell argv.
Supported hints remain de, en, fr, it; leave STT_LANGUAGE unset for
auto-detection by default.
A merge is not a deployment: release the package, upgrade the target host,
converge with apply, then verify the runtime and a real MCP transcription.
audio uses the established per-user uvx staging path: pyproject.toml and
uv.lock ship in the payload, and activation/convergence installs locked deps
in the staged runtime. Runtime runs uv --offline with the staged interpreter:
no dependency installation or resolution inside a tool call. Existing audio
activations must converge from the old in-place Python command to the staged
uv command. An overlay mcp/audio can shadow the package; check the effective
catalog. Verify masked variable presence and the effective unit command.
Rollback: restore the previous STT_MODEL and backend/base configuration, converge, verify. For an unmigrated legacy Azure setup, unset STT_BACKEND and STT_BASE_URL to restore the old full-URL fallback. For unified Azure, use STT_BACKEND=azure-openai and the previous deployment name. Explicit openai selects OpenAI v1, not the old Azure fallback. Upgrade alone does not prove convergence or inference.
Limits and compatibility¶
- Requires ffmpeg; its stdin is disconnected from the MCP socket.
- ffmpeg-supported inputs normalize to raw 16kHz mono PCM16.
- Audio is decoded to temporary disk, not loaded entirely into Python memory.
- Sends bounded 100ms chunks, commits every 15 seconds and at end, receives concurrently. Waits for each commit's completion before sending the next segment: one commit in flight, ordered output and no unbounded provider buffer. Does not burst to catch up after pauses.
- Uses completed transcripts only; provisional suffixes/deltas are not duplicated.
- Audio is paced at real-time speed: processing takes roughly the recording's duration plus finalization. Latency is not identical to fast HTTP upload.
- Synchronous MAI sessions over one hour fail clearly. Use the job tools for a longer recording; their per-session sections preserve this bound. No silent truncation.
- Conversion, socket operations, setup and finalization have bounded deadlines.
- Transport failure returns an error, not a partial successful transcript.
- Temporary audio and sockets are cleaned up on success and failure.
- Uses host proxy settings and TLS verification; never disable certificate checks.
Microsoft marks streaming public preview, without an SLA, and not recommended for production. Global routing can serve outside the resource region: residency and production readiness need separate review. Plain MAI-Transcribe-2 through Azure Speech Fast Transcription is a different API, not this adapter.
Example shared fleet configuration after installation¶
After all target hosts have the release, set shared values (no --agent):
agentctl secret set STT_MODEL --value MAI-Transcribe-2-Streaming
agentctl secret set STT_BACKEND --value mai-realtime
agentctl secret set TTS_MODEL --value tts
agentctl secret set TTS_BACKEND --value openai
agentctl secret set DIARIZE_MODEL --value gpt-4o-transcribe-diarize
agentctl secret set DIARIZE_BACKEND --value openai
agentctl fleet apply
This example assumes the shared OpenAI v1 endpoint and key for the same Foundry resource; no capability-specific base override is needed. Check and remove redundant per-agent overrides before fleet apply, since they override shared values. Do not remove intentional alternate-endpoint overrides. Apply may restart affected agents. Check masked rendered keys, staged runtime, and real calls on each host.
Deployment prerequisite: a model choice is not a deployed model. The deployment
name tts must exist. gpt-4o-transcribe-diarize must also be deployed before
diarization can work; an HTTP 404 DeploymentNotFound is not repaired by setting
configuration alone. Alternatively set DIARIZE_BASE_URL to another approved v1
endpoint exposing that deployment and accepting the reused key. Different credentials
per capability are not implemented in this change.
Verified on the owner's configured resource during development: MAI completed a
synthetic transcription; TTS tts returned valid Opus via both v1 and Azure deployment
REST. Diarization gpt-4o-transcribe-diarize returned 404 DeploymentNotFound, so live
speaker attribution remains unverified pending deployment. Mocked request fields and
speaker-labelled response normalization are tested; they do not establish live support.
Verification¶
bash test/audio-mcp-config_test.sh
bash test/audio-mcp-jobs_test.sh
bash test/audio-mcp-mai-realtime_test.sh
bash test/audio-mcp-azure-transcription_test.sh
bash test/audio-mcp-openai-base-url_test.sh
bash test/audio-mcp-voice-delivery_test.sh
Offline tests use synthetic sockets/keys. Live verification must send synthetic
speech through tools/call on the changed MCP and inspect its text result;
a models listing or handshake is not proof of transcription.
Sources: Microsoft Realtime protocol, Microsoft streaming overview.