Speech platform integration
VoiceStudio exposes a local-first speech platform for automation clients. A caller can discover the service, generate audio, submit audio for transcription or translation, stream live audio, use the wider HTTP command API, or connect an agent through MCP. The Python CLI is the main terminal entry point: it can use a running backend, start the installed desktop app when needed, and keep remote credentials tied to the selected backend.
Platform boundary
The speech platform separates speech data from desktop authority. A client can send audio to the backend without gaining control of the host microphone or the focused application.
flowchart LR
Client[Automation client] --> Discover[Capability discovery]
Client --> Data[Speech data plane]
Client --> CLI[VoiceStudio CLI]
Client --> Agent[Agent interface]
Discover --> Backend[VoiceStudio backend]
Data --> Backend
CLI --> Backend
Backend --> Text[Transcript or audio result]
Agent --> Backend
CLI --> Desktop[Installed desktop app]
The backend advertises relative endpoint paths. This lets the same contract work on loopback, a trusted remote host, or behind a proxy. The CLI is a separate client boundary. It can address the backend directly or ask the installed desktop app to start its own backend; it does not start the Python backend itself. See Backend API platform for the wider service boundary.
References: cli/…/runtime.py• L1-7 cli/…/runtime.py• L42-82 cli/…/desktop.py• L229-254
Capability discovery
Capability discovery is the stable starting point for an integration. A client reads GET /.well-known/voicestudio-speech and learns which transports, audio formats, result events, features, and authentication methods the current service supports.
The backend also accepts GET /v1/audio/capabilities. Both routes return the voicestudio.speech-capabilities schema with protocol voicestudio.speech.v1 and version 1.0.
| Capability | Contract |
|---|---|
| Batch transcription | POST /v1/audio/transcriptions over HTTP |
| Live transcription | WebSocket /v1/audio/transcriptions/stream |
| Agent access | Streamable HTTP POST /mcp, standalone MCP server, or python -m backend.mcp_shim |
| Legacy native dictation control | Advertised only when the retired desktop sidecar is active |
| Stream input | Binary WebM/Opus by default or signed 16-bit mono PCM |
| Stream output | JSON events with partial text and final text |
Clients should use the advertised paths instead of assuming that the backend and sidecar share a port. A missing native-control capability means that the caller must own capture and consume text through the data plane. The current Electron app has no native control API. MCP transport availability is separate from native dictation control.
References: backend/…/speech_platform.py• L23-80 backend/…/speech_platform.py• L82-145 cli/…/__main__.py• L675-683
Speech data plane
The speech data plane converts caller-owned text to audio and caller-owned audio into text. It supports a request-and-response HTTP contract for scripts and a session-oriented WebSocket contract for live interfaces.
Speech synthesis
POST /v1/audio/speech follows the OpenAI audio speech shape. The request supplies text through input and can select a model, voice, output format, speed, language, and engine-specific voice controls. OpenAI voice names remain accepted as aliases, while VoiceStudio voice profile IDs and unique profile names provide product-specific choices. A duplicate profile name is not silently selected; the caller must use its profile ID.
The response is audio in the requested format. Supported formats include MP3, Opus, AAC, FLAC, WAV, and raw PCM. A caller can request chunked audio or server-sent events for a completed clip. GET /v1/audio/voices lists standard aliases, saved voice profiles, and available engines. GET /v1/models lists OpenAI-compatible aliases and installed VoiceStudio engines.
The endpoint keeps the OpenAI request contract while using the active VoiceStudio speech engine. Clients should treat engine availability, missing encoders, load errors, admission limits, and capacity errors as service responses that can require a different format, a retry, or a different model. Validation and service errors use an OpenAI-shaped error object with VoiceStudio's detail field retained for local clients.
The CLI exposes the same product capability through voicestudio speak. It resolves a saved voice by ID or by a unique name, sends the request to the backend, and writes audio to --output. The command also supports text files and per-request engine, language, speed, seed, and instruction choices.
References: backend/…/openai_compat.py• L58-150 backend/…/openai_compat.py• L153-295 backend/…/openai_compat.py• L589-864 cli/…/__main__.py• L736-813
Batch transcription
POST /v1/audio/transcriptions follows the OpenAI audio transcription shape. The request uses multipart form data with a file part and optional model, language, prompt, response format, temperature, and timestamp settings. The response can be plain text, compact JSON, verbose JSON with timed segments or words, SRT, or VTT. POST /v1/audio/translations uses the same result formats to return English text when the active recognition engine supports translation.
OpenAI model names select the active speech-recognition engine. A VoiceStudio engine ID is a concrete selection and must name the active engine. If the selected speech-to-text model is not installed, the endpoint returns a structured 409 response instead of starting a silent large download. A transcription timeout returns 504, while unsupported translation and invalid request fields return typed client errors.
The CLI maps voicestudio transcribe and voicestudio translate-audio to these routes. It accepts a file path or standard input, passes the requested response format, and returns text or structured output. It uses the caller's selected backend rather than creating a separate speech service.
References: backend/…/openai_compat.py• L867-910 backend/…/openai_compat.py• L962-1171 backend/…/openai_compat.py• L1187-1233 cli/…/__main__.py• L179-184 cli/…/__main__.py• L738-744
Streaming transcription
The versioned WebSocket accepts binary audio frames and returns JSON events during one session. WebM/Opus is the default input. A client can request raw signed 16-bit mono PCM with pcm=1&sr=16000; the service bounds unsupported sample rates to a safe range.
When a client finishes sending audio, it sends {"type":"input_audio.end"} and keeps the socket open for the final event. The service sends a session envelope first, then partial text as audio accumulates, and finally an authoritative summary. Some live engines also send utterance finals before that summary.
sequenceDiagram
participant C as Client
participant S as Speech WebSocket
C->>S: Connect to versioned stream
S-->>C: session.started
C->>S: Binary audio frames
S-->>C: partial events
C->>S: input_audio.end
S-->>C: final summary
Every versioned event carries the protocol and session identifier. The legacy /ws/transcribe route remains available for clients that use its older frames and EOF control.
References: backend/…/capture_ws.py• L8-37 backend/…/capture_ws.py• L58-73 backend/…/capture_ws.py• L92-122 backend/…/capture_ws.py• L236-277 backend/…/capture_ws.py• L359-404
Command-line client
The CLI is a dependency-free HTTP client and desktop launcher. The voicestudio package entry point and the frozen console entry point use the same command tree, so a packaged binary and a Python installation expose the same commands.
CLI entrypoints
Running voicestudio without a command opens the desktop app. Speech and automation commands use the backend. The main speech commands are:
voicestudio speak TEXT --voice VOICE_ID --output result.wavvoicestudio transcribe recording.wavvoicestudio translate-audio recording.wavvoicestudio integrations api docsvoicestudio integrations mcp config --client generic
The CLI also exposes the wider backend API through grouped commands for voices, models, engines, projects, dubbing, jobs, audio tools, settings, sharing, calls, and diagnostics. A command can read a JSON object from --file, accept fields through repeated --field NAME=VALUE, and pass query values through repeated --query NAME=VALUE.
The command tree uses plain terminal output by default and unchanged machine-readable JSON with --json. Shell completion is available for bash, zsh, fish, and PowerShell. Completion builds local command data only; it does not contact the backend or start the desktop app.
References: cli/pyproject.toml• L6-24 cli/frozen_main.py• L1-5 cli/…/__main__.py• L90-129 cli/…/__main__.py• L269-375 cli/…/completion.py• L1-8 cli/…/completion.py• L61-99
Backend selection
The CLI first selects a backend URL from the command flag, the environment, or the saved CLI connection. If none is set, it uses the local backend port. For the default local target, the CLI reads the desktop app's backend.json, checks backend health, and starts the installed app in the background when a command needs a backend. Read-only status commands do not start an inactive backend just to report that it is stopped.
The CLI never treats a discovered local record as permission to send traffic away from the machine. A remote backend must be selected as a connection and tested as a remote service. The stop command manages only the local app-owned backend; it cannot stop a backend selected with --url, VOICESTUDIO_URL, or a saved remote connection.
References: cli/…/config.py• L81-101 cli/…/runtime.py• L42-82 cli/…/runtime.py• L104-156 cli/…/runtime.py• L159-189 cli/…/__main__.py• L637-674
Request contracts
The CLI keeps command names separate from route details. A command registry describes the method, route, resource IDs, uploads, binary results, streams, destructive actions, and background tasks. A matching contract record defines the accepted body encoding, fields, query parameters, and required values. This gives automation a stable command interface while the running API remains the source of the full OpenAPI description.
The generic request path validates fields before sending them. It supports JSON bodies, form data, multipart uploads, raw file uploads, and query values. Resource IDs are URL-encoded. Binary results require --output, and downloads use temporary files before the final path is created. Streamed operations report progress and follow background tasks until a finished event; an interrupt asks the backend to cancel the task.
The CLI maps transport and HTTP failures to one error shape with a stable code, status, retry hint, and optional detail. It rejects unsafe paths, redirects, oversized JSON, malformed stream events, and incomplete downloads. Secrets are removed from displayed errors and output.
References: cli/…/registry.py• L5-22 cli/…/registry.py• L182-350 cli/…/contracts.json• L1-41 cli/…/__main__.py• L443-517 cli/…/__main__.py• L872-923 cli/…/transport.py• L23-39 cli/…/transport.py• L57-109 cli/…/transport.py• L154-185 cli/…/errors.py• L5-25
Desktop control plane
The desktop control plane was a narrow way to start, stop, or toggle VoiceStudio dictation. It did not accept audio. This control surface belongs to the retired Tauri desktop shell; the current Electron app has no equivalent control API.
HTTP control
The legacy sidecar exposes POST actions at /v1/dictation/start, /v1/dictation/stop, and /v1/dictation/toggle. GET /v1/status reports recording state and the active output session. The sidecar also exposes capability discovery and JSON-RPC at POST /rpc.
The action model is idempotent at the state boundary. A repeated start or stop does not create a duplicate transition. A toggle also accounts for a session that has been reserved but has not yet updated the visible recording flag.
References: frontend/…/speech_sidecar.rs• L25-39 frontend/…/speech_sidecar.rs• L102-150 frontend/…/speech_sidecar.rs• L236-284 frontend/…/speech_sidecar.rs• L301-339
Command-line control
The current CLI is a backend client and desktop launcher. It does not provide native dictation start, stop, or toggle commands. Live speech integrations must capture audio themselves and use the batch or streaming transcription contract.
The old Python speech-client commands remain a separate compatibility surface where present. They must not be confused with the current voicestudio CLI, which provides backend speech commands and broader API access. The legacy sidecar and its output sessions remain relevant only to deployments that still run the Tauri shell.
References: cli/…/__main__.py• L90-100 cli/…/__main__.py• L269-308 cli/…/runtime.py• L104-115 cli/…/desktop.py• L14-25
Output sessions
An output session binds a transcription result to the focused desktop target. This is the bridge for clients that capture audio themselves but still want the legacy sidecar's native insertion and clipboard-safe delivery.
The session flow is:
- Create
POST /v1/output/sessionson the sidecar before capture. - Send audio to the batch or streaming transcription endpoint.
- Deliver the final string to
POST /v1/output/sessions/{id}/insertwith{"text":"..."}. - Cancel with
DELETE /v1/output/sessions/{id}if capture or transcription stops early.
Only one session can own the focused destination at a time. The sidecar rejects an old or already finished identifier, so a late result cannot insert into a newer target. The current CLI does not perform this flow.
References: frontend/…/speech_sidecar.rs• L181-234 cli/…/__main__.py• L736-744
Agent interface
The MCP interface exposes VoiceStudio speech actions as tools and resources for AI agents. It supports speech generation, voice cloning, voice design, transcription, voice and language discovery, health checks, voice-profile resources, and recent-history resources. It keeps large audio results out of an agent context when file output is configured, while still supporting inline WAV data for clients that need a self-contained response.
MCP server
The backend mounts a Streamable HTTP MCP service at /mcp when the MCP dependency is available. Embedded tool calls use the backend in-process unless OMNIVOICE_API_URL explicitly redirects them to an HTTP backend; standalone calls use the backend over HTTP. The CLI can print an MCP configuration for generic clients, Claude Code, Cursor, and Codex. The generated configuration points to the backend's /mcp/ endpoint and carries X-OmniVoice-Client-Id so the service can apply an agent's voice binding.
Structured tool and resource results use valid JSON encoding. MCP output mode controls whether audio returns inline, through a bounded file or URL, or through both lanes. Path-based audio input and output require OMNIVOICE_MCP_BASE_PATH; without that boundary, path-based audio is refused.
flowchart LR
Agent[AI agent] --> MCP[MCP tools and resources]
MCP --> Backend[VoiceStudio backend]
Backend --> Render[Speech render or transcript]
Render --> Inline[Inline WAV resource]
Render --> File[Bounded requested-format file or URL]
The MCP server can run over stdio or HTTP-based transports. The CLI's MCP configuration command is only a configuration helper. It does not start the MCP service or make an agent call.
References: backend/mcp_server.py• L1-31 backend/mcp_server.py• L434-501 backend/mcp_server.py• L501-580 cli/…/__main__.py• L675-683 cli/…/__main__.py• L687-689
MCP stdio proxy
The python -m backend.mcp_shim entrypoint connects stdio-only MCP clients to the backend's /mcp/ HTTP endpoint. It waits for backend health before forwarding JSON-RPC messages, preserves the MCP session identifier, forwards the optional client ID, and writes protocol messages only to stdout.
The proxy uses OMNIVOICE_URL when set. Otherwise it builds the backend URL from OMNIVOICE_HOST and OMNIVOICE_PORT. It can send OMNIVOICE_API_KEY to a remote HTTPS backend but refuses to send that key over remote plain HTTP.
References: backend/…/__main__.py• L1-29 backend/…/__main__.py• L53-87 backend/…/__main__.py• L164-207
Authentication and trust
Authentication protects non-loopback speech access when the service is used from another host. Loopback callers remain credential-free by default. Remote callers must use the configured bearer key or an allowed short-lived session path.
Durable API key
Set OMNIVOICE_API_KEY to require a bearer credential from non-loopback HTTP and WebSocket clients. Send it as Authorization: Bearer <OMNIVOICE_API_KEY>. The key grants the service's remote API capability; it does not isolate the network or make an untrusted network safe.
The CLI can save a key for one selected backend with voicestudio connection auth set --stdin. A saved key is not reused after a --url override points to another origin. The client and MCP proxy refuse to send credentials to a remote plain-HTTP URL. They also refuse redirects, so a key cannot be forwarded to an unexpected host.
References: backend/…/auth.py• L69-81 backend/main.py• L1569-1644 cli/…/config.py• L81-101 cli/…/__main__.py• L622-655 cli/…/transport.py• L41-55
Browser session and WebSocket ticket
Browser clients should not place the durable API key in a WebSocket URL. An authenticated browser session can call POST /api/auth/ws-ticket with the target path and receive a short-lived ticket. The client then connects with ?ws_ticket=<ticket>.
The ticket is bound to the requested WebSocket path and consumed during authentication. Cookie-based browser requests also pass origin and CSRF checks. This keeps browser credentials separate from the long-lived operator key.
References: backend/…/auth.py• L91-97 backend/…/auth.py• L204-230 backend/…/auth.py• L202-209 backend/…/auth.py• L369-381 backend/main.py• L1631-1643
Network trust
OMNIVOICE_TRUSTED_NETWORKS defines trusted CIDR ranges for consumption access. A trusted network can reach speech consumption routes without the durable API key in the normal desktop deployment, but it does not grant administrative access. Keep remote speech endpoints on a trusted network and use HTTPS/WSS outside a fully trusted LAN.
The legacy native sidecar binds only to 127.0.0.1 and rejects unapproved browser origins. The MCP service has a separate OMNIVOICE_MCP_ALLOWED_HOSTS setting for hosts and origins that may reach its transport.
References: backend/…/auth.py• L90-119 backend/…/dependencies.py• L251-265 backend/mcp_server.py• L461-477 frontend/…/speech_sidecar.rs• L287-299 cli/…/config.py• L94-101
Connection configuration
Configuration selects where an integration sends speech and agent requests. The CLI has a private JSON connection file that is separate from Electron browser storage. The defaults target a local backend on port 3900; the retired desktop sidecar used port 3902.
| Setting | Purpose | Default |
|---|---|---|
--url | One-command backend URL override | Not set |
VOICESTUDIO_URL | CLI backend base URL | Not set |
VOICESTUDIO_CONFIG | CLI connection file location | Platform config directory |
OMNIVOICE_PORT | Local backend port fallback | 3900 |
OMNIVOICE_API_KEY | Durable credential for remote API and MCP access | Not set |
OMNIVOICE_URL | MCP proxy backend base URL | Not set |
OMNIVOICE_API_URL | Embedded MCP tool-call target | Not set |
OMNIVOICE_HOST | MCP proxy host when OMNIVOICE_URL is not set | 127.0.0.1 |
OMNIVOICE_MCP_ALLOWED_HOSTS | MCP transport host and origin allowlist | Empty |
OMNIVOICE_MCP_OUTPUT_MODE | MCP audio return mode: resources, files, or both | resources |
OMNIVOICE_MCP_BASE_PATH | Directory boundary for MCP audio files | Not set |
OMNIVOICE_MCP_TIMEOUT_S | Explicit MCP wait limit | Not set; derived from backend budgets |
OMNIVOICE_TRUSTED_NETWORKS | CIDR ranges allowed for consumption access | Empty |
VOICESTUDIO_SPEECH_URL | Legacy Tauri sidecar base URL | http://127.0.0.1:3902 |
VOICESTUDIO_SPEECH_PORT | Legacy desktop sidecar listen port | 3902 |
The CLI chooses connection sources in this order: --url, VOICESTUDIO_URL, saved configuration, then the local OMNIVOICE_PORT fallback. The saved API key is used only for the URL that stored it. Remote credentials require HTTPS. The legacy sidecar settings apply only to deployments that still run that shell.
The CLI stores its URL, key, and credential URL in config.json. VOICESTUDIO_CONFIG can move that file and its cache. The desktop app has a separate user-data location for backend.json; VOICESTUDIO_USER_DATA selects it when a profile needs to be addressed explicitly.
References: cli/…/config.py• L13-26 cli/…/config.py• L29-55 cli/…/config.py• L81-101 cli/…/runtime.py• L29-58 cli/…/__main__.py• L622-655 backend/…/__main__.py• L53-59 backend/mcp_server.py• L94-124 frontend/…/speech_sidecar.rs• L78-84
Related speech services
The integration surface connects to broader VoiceStudio flows without replacing their product rules. Use the generation API for text-to-speech, the media localization workflow for timed dubbing, and the speech-input service for recognition and model behavior.
- Backend API platform explains the shared backend route and service boundary.
- LLM and agent services explains the wider agent-facing service patterns.
- Voice generation explains text-to-speech requests and audio delivery.
- Electron desktop explains the desktop shell and its local process boundary.
References: backend/…/openai_compat.py• L1-29 backend/…/capture.py• L1-16 backend/…/capture_ws.py• L1-7 cli/…/__main__.py• L269-350
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the capability document aligned with every advertised endpoint, transport, audio format, result event, and authentication path.
- Keep the OpenAI-compatible speech, transcription, and translation fields aligned with their accepted model names, voice aliases, profile IDs and unique names, response formats, and status responses.
- Keep the CLI command registry, request contracts, and backend routes aligned. A route change can silently break generic commands even when the command name stays the same.
- Keep CLI field declarations aligned with required body fields, query fields, upload names, encodings, binary outputs, streams, and background task results.
- Keep the CLI URL precedence and saved credential origin binding aligned when changing ports, proxy paths, or remote connection behavior.
- Keep local backend discovery aligned with the desktop app's backend.json schema and ownership rules. Do not let a local record redirect the CLI to a remote host.
- Keep
voicestudioand frozen console entry points on the same command tree and preserve shell completion without backend access. - Keep streamed task completion, cancellation, output download, and error events aligned across the CLI and backend.
- Keep
OMNIVOICE_API_KEY, trusted-network rules, browser session exchange, WebSocket ticket path binding, and MCP host allowlists aligned across route guards and clients. - Keep MCP output modes, base-path confinement, client identity forwarding, timeout budgets, and streamable HTTP session handling aligned across the server, proxy, and generated CLI configuration.
- Keep legacy sidecar control and output-session claims separate from the current Electron and CLI boundaries.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The CLI uses a stale or invalid backend.json record | It cannot find the app-owned backend or could select the wrong process | Validate the published record and require a healthy backend before sending requests |
| A remote backend is selected with a saved key but uses plain HTTP | The credential could be exposed on the network | Use HTTPS; the CLI rejects remote credentials over plain HTTP |
A --url override points to a different origin | A key saved for another backend must not follow the override | Bind saved credentials to their saved URL and use an explicit environment key when needed |
| A generic command sends a field not declared in its contract | The request is rejected before it reaches the backend | Check contracts.json and use --file, --field, or --query with declared names |
A binary command has no --output path | Audio or another file result cannot be safely written | Set --output; use - only when stdout is not a terminal |
| A streamed task ends without a completion event | The CLI cannot confirm that the render finished | Follow the task stream and inspect job events when the stream is incomplete |
| An old script expects the CLI to toggle native dictation | No desktop dictation action occurs | Capture audio in the caller and use batch or streaming transcription |
A client closes a versioned stream without input_audio.end | It may miss the authoritative final result | Send the end event and wait for the final summary |
| A non-unique voice name is used for synthesis | The request is rejected instead of selecting an arbitrary profile | Use the profile ID returned by voice discovery or the CLI voice list |
| An ASR model is not installed | Transcription returns a structured conflict instead of text | Select an installed engine or handle the model-install response before retrying |
| An agent sends a path without an MCP base path | The tool refuses the file request | Set OMNIVOICE_MCP_BASE_PATH and keep the file inside that directory |
| The MCP server or backend is not ready | Agent calls fail during startup | Start the backend and wait for health before using the MCP endpoint or proxy |
Key files
| File | Why to read it |
|---|---|
| backend/…/speech_platform.py | Defines capability discovery for transports, formats, features, and authentication. |
| backend/…/openai_compat.py | Defines the OpenAI-compatible speech, transcription, translation, model, and voice boundary. |
| backend/…/capture_ws.py | Defines the live transcription session and event contract. |
| cli/…/__main__.py | Defines CLI entrypoints, speech commands, connection commands, MCP configuration, request dispatch, streams, and task handling. |
| cli/…/registry.py | Maps human-facing commands to backend routes and operation types. |
| cli/…/contracts.json | Declares generic request fields, encodings, query values, and required inputs. |
| cli/…/config.py | Defines CLI connection precedence, saved credentials, URL checks, and config locations. |
| cli/…/runtime.py | Defines local backend discovery, desktop startup, health checks, and ownership rules. |
| cli/…/transport.py | Defines HTTP transport, authentication headers, multipart upload, response limits, and atomic downloads. |
| cli/…/desktop.py | Defines desktop executable discovery and the boundary between CLI commands and Electron. |
| backend/mcp_server.py | Defines agent tools and resources, output modes, file boundaries, timeouts, and HTTP forwarding. |
| backend/…/__main__.py | Defines the stdio-to-HTTP MCP proxy and its backend selection and authentication rules. |
| frontend/…/speech_sidecar.rs | Defines the legacy native dictation control and output-session boundary. |
| backend/…/auth.py | Defines loopback, trusted-network, API-key, session, and WebSocket-ticket identities. |
| cli/pyproject.toml | Defines the Python package and the voicestudio console entry point. |