OmniVoice inference and CLI
OmniVoice inference turns text into speech with a selected language and voice style. It supports voice cloning from reference audio, voice design from speaker attributes, and automatic voice selection. The same generation path serves the Python API, the interactive demo, single-item synthesis, batch work, and the dubbing workflow. For the model’s role and training context, see the OmniVoice model and OmniVoice training pages; for engine routing and related voice flows, see engine routing and voice generation.
Inference modes
The inference API accepts target text and optional voice context. It maps each request to one of three modes before it plans the output length and decodes audio.
| Mode | Voice context | Main result |
|---|---|---|
| Voice clone | Reference audio with matching text, or a reusable clone prompt | Speech that follows the reference voice |
| Voice design | A validated set of speaker attributes | Speech in a described voice style |
| Auto voice | No reference or design instruction | Speech with a model-selected voice |
Language can be given as a name, an ID, or a regional form that resolves to a base language. If it is omitted or unknown, generation uses language-agnostic behavior. A known language helps the model select the right speech pattern across the supported language set. OmniVoice.generate() also accepts one request or a list of requests for batch generation. References: omnivoice/…/omnivoice.py• L841-875, omnivoice/…/omnivoice.py• L1430-1565, omnivoice/…/omnivoice.py• L1874-1926
Voice clone prompts
Voice cloning uses a short spoken reference as the voice signal and its transcript as the text alignment. create_voice_clone_prompt() prepares the reference once and returns a reusable VoiceClonePrompt, which can be saved and loaded for later requests. A supplied prompt takes priority over raw reference audio and reference text.
When the transcript is absent, an optional Whisper model transcribes the reference. The model first reuses a complete local speech-to-text snapshot when one is available, so implicit transcription does not need to download a model. It releases an implicitly loaded recognizer before synthesis and protects overlapping clone preparation with a per-model lock. The normal input is a clear three-to-ten-second speech passage. Empty, silent, invalid, or excessively long references fail with an actionable error instead of producing an unvoiced result. References: omnivoice/…/omnivoice.py• L646-736, omnivoice/…/omnivoice.py• L989-1236
Voice design instructions
Voice design expresses the desired speaker through a small set of tags. The tags cover gender, age, pitch, whisper style, English accent, and Chinese dialect. One value is allowed from each category, and the instruction language follows the speech language: English accents use English tags and Chinese dialects use Chinese tags.
The validator accepts both comma styles, normalizes the selected language, rejects unknown or conflicting tags, and suggests close matches for misspellings. Stored profile values use a more forgiving healing path so bad legacy data does not erase the intended design. The model also drops a known invalid frontend object sentinel before validation. References: omnivoice/…/omnivoice.py• L1929-2062, omnivoice/…/voice_design.py• L99-154
Duration and audio handling
The generation path uses duration as a planning input rather than as a later edit. It estimates a target frame count from the text and reference speech, then uses that count to control decoding and long-text splitting. The returned audio is a mono tensor with the model tokenizer’s sample rate, normally 24 kHz.
Duration estimation
Without a fixed duration, RuleDurationEstimator compares weighted text length with the reference text and reference duration. The weights account for script and character type, so the estimate does not treat all writing systems as if they had the same speaking density. A speed factor changes the estimate while preserving the language-aware baseline.
An explicit duration overrides speed. The request then sets the target frame count for that duration and derives the matching speed ratio for chunk planning. A duration of None keeps the natural estimate, while a speed above one is faster and a speed below one is slower. References: omnivoice/…/duration.py• L18-23, omnivoice/…/duration.py• L204-259, omnivoice/…/omnivoice.py• L1513-1579
Long-text chunking
The model uses direct iterative generation for short requests and punctuation-aware chunking for requests whose estimated duration passes the chunk threshold. Text is split near sentence punctuation, with common abbreviations protected from false sentence breaks. Chunk audio is joined with a short gap and fades so a long result does not expose hard cuts.
Reference-free long generation uses the first generated chunk as the voice reference for later chunks. Reference-based long generation reuses the supplied reference for each chunk. A batch with long items must use one reference policy for all items in that chunked group. References: omnivoice/…/omnivoice.py• L197-216, omnivoice/…/omnivoice.py• L1319-1428, omnivoice/…/text.py• L120-205, omnivoice/…/audio.py• L398-447
Audio preparation and output
Reference audio can be a file or a waveform with a sample rate. The audio path loads it, resamples it to the model rate, converts it to mono, checks that it contains usable sound, and removes long edge or middle silences when prompt preprocessing is enabled. The prepared audio is aligned to the tokenizer frame size before it becomes the clone prompt.
Generated tokens are decoded by the audio tokenizer. Output post-processing can remove long silences, adjust volume against the clone reference, normalize designed voices, and add short fades and silent edge padding. These steps aim to make the audio safe to hand to a WAV writer or to a downstream mix. References: omnivoice/…/omnivoice.py• L1022-1236, omnivoice/…/omnivoice.py• L1238-1317, omnivoice/…/audio.py• L45-80, omnivoice/…/audio.py• L83-183, omnivoice/…/audio.py• L296-345
Iterative inference
OmniVoice generates audio tokens with an iterative unmasking process. It prepares a conditional sequence from style, language, instruction, text, optional reference tokens, and masked target audio. An unconditional target sequence provides the comparison used by classifier-free guidance.
The main stages are shown below.
flowchart LR
A[Text and voice context] --> B[Normalize language and instruction]
B --> C[Estimate target duration]
C --> D{Long request?}
D -- No --> E[Prepare conditional and unconditional inputs]
D -- Yes --> F[Split at punctuation]
F --> E
E --> G[Iteratively fill masked audio tokens]
G --> H[Decode audio tokens]
H --> I[Join chunks and post-process waveform]
I --> J[Return audio tensors]
Token generation
At each step, the model predicts audio codebook tokens for the conditional and unconditional inputs. Guidance combines their scores, then the decoder selects high-confidence masked positions and repeats the process until the target is filled. Generation settings control the number of steps, guidance strength, time schedule, sampling temperatures, and optional denoising.
The model keeps the conditional and unconditional sequences separate in the baseline path so each can attend only to its own context. This preserves the relationship between voice context and target speech while allowing a batch of independent texts. A request seed isolates its random draws from other requests that share the model. References: omnivoice/…/omnivoice.py• L1677-1854, omnivoice/…/omnivoice.py• L937-942
Input conditioning
The model builds separate conditional and unconditional views of each request. The conditional view carries language, design instruction, target text, optional reference text, reference audio tokens, and masked target audio. The unconditional view keeps the target region so guidance compares the requested context with a target-only prediction. References: omnivoice/…/omnivoice.py• L1596-1675, omnivoice/…/omnivoice.py• L1705-1749
Runtime execution
OmniVoice can run in the application process, in a killable sidecar process, or through a separate GGUF runtime. Engine routing chooses the safest available path while keeping the public synthesis contract centered on the same model and 24 kHz mono audio surface.
Engine selection
The default cloning engine prefers the GGUF runtime only when its platform binary is present, usable, and able to complete a startup probe. If that optional path is not ready, routing falls back to the in-process OmniVoice engine so a missing binary or failed probe does not block synthesis.
The GGUF backend supports voice cloning and the core timing and decoding controls. It does not support voice design. Requests that need design instructions therefore use an engine with native voice-design support. The explicit subprocess-isolated engine remains available on every host when an operator wants crash containment without changing the model surface. References: backend/…/backend.py• L341-367, backend/…/backend.py• L381-455, backend/…/backend.py• L854-888, backend/…/__init__.py• L45-71, backend/…/__init__.py• L102-118
The selection flow keeps optional runtime failures separate from the normal inference path.
flowchart LR
A[OmniVoice request] --> B{Selected engine}
B -->|Default| C{GGUF binary and probe ready?}
C -->|Yes| D[GGUF runtime]
C -->|No| E[In-process OmniVoice]
B -->|MPS or explicit isolation| F[OmniVoice sidecar]
B -->|Voice design| E
D --> G[24 kHz mono audio]
E --> G
F --> G
Crash-isolated inference
The subprocess engine runs the same OmniVoice model in a child process under the parent application’s Python interpreter. Its purpose is crash isolation rather than a separate dependency environment. The parent can hard-kill a child that exceeds its receive budget and start a fresh one, which protects the API process from native crashes and releases device memory after a stuck operation.
The sidecar announces readiness before loading heavy model code. It loads the model on the first synthesis request, reports load progress, and returns audio as a bounded message containing PCM data and its sample rate. The child uses the same device-aware model loading policy as the direct inference paths. The sidecar allows a longer startup and receive window for valid cold loads and long renders, while a timeout still enables hard recovery. On MPS, the public omnivoice engine ID uses this isolated path so settings and saved projects keep the same engine name. References: backend/…/__init__.py• L45-99, backend/…/__init__.py• L102-134, backend/…/main.py• L8-28, backend/…/main.py• L119-190, backend/…/main.py• L213-261, omnivoice/…/dtype.py• L1-30
GGUF inference
The GGUF backend uses a platform-specific C++ runtime as an OS process. For each request, it resolves a hardware-appropriate pair of cached model files, passes text and supported voice controls to the runtime, and reads the generated WAV back as a model-shaped audio tensor.
The runtime keeps the same multilingual and cloning surface as OmniVoice, but voice design is not available on this backend. Reference audio is limited to approved voice, dubbing, or temporary locations before it reaches the child process. The backend validates the bundled executable and uses a hard process deadline so a broken or wedged runtime becomes a contained engine failure. References: backend/…/backend.py• L471-541, backend/…/backend.py• L543-592, backend/…/backend.py• L596-672, backend/…/backend.py• L674-803
GGUF runtime distribution
The GGUF runtime is built from a pinned upstream commit for each supported platform. The build places the executable and any required shared libraries together with a checksum manifest, so the application can verify the runtime before it selects the engine.
The build workflow covers Linux x86-64, Linux ARM64, Windows x86-64, and macOS ARM64. The macOS Intel leg is not built in this workflow and uses the in-process fallback. The Linux ARM64 build can use Vulkan when its build dependencies are available; other supported builds use their platform-specific or CPU path. References: scripts/build-omnivoice-tts.sh• L1-21, scripts/build-omnivoice-tts.sh• L106-177, scripts/build-omnivoice-tts.sh• L179-201, .github/…/build-omnivoice-tts.yml• L19-69, .github/…/build-omnivoice-tts.yml• L74-121
Command-line entrypoints
The package exposes four commands. They share the OmniVoice model and generation behavior, but each command serves a different operating pattern.
Single-item synthesis
omnivoice-infer synthesizes one text input and writes one WAV file. It supports voice cloning through reference audio and reference text, voice design through an instruction, and auto voice when neither is supplied. It accepts an optional language plus controls for duration, speed, iterative decoding, guidance, denoising, and output post-processing. When no device is given, it selects CUDA, Apple MPS, or CPU and loads the model with a device-appropriate numeric type before it calls OmniVoice.generate(). References: omnivoice/…/infer.py• L42-119, omnivoice/…/infer.py• L122-157, omnivoice/…/dtype.py• L1-30
Use this command for a focused render or a quick check of a voice and text combination.
Batch synthesis
omnivoice-infer-batch reads a JSONL file and writes one WAV file per item. Each item needs an ID and text. It can also carry reference audio and text, a voice-design instruction, language values, duration, and speed. The shared JSONL reader skips blank lines and warns on malformed JSON while preserving the supported fields for valid items. References: omnivoice/…/data_utils.py• L18-64
The command starts worker processes across the available devices. Each worker loads its own model and can run warmup requests before it handles real work. The scheduler sorts items by estimated total duration and groups them by a duration budget, or uses a fixed batch size when requested. Batched calls preserve per-item voice, language, timing, and design inputs. The command reports total audio time, synthesis time, and average real-time factor. References: omnivoice/…/infer_batch.py• L68-200, omnivoice/…/infer_batch.py• L203-253, omnivoice/…/infer_batch.py• L256-346, omnivoice/…/infer_batch.py• L349-403, omnivoice/…/infer_batch.py• L406-524, omnivoice/…/dtype.py• L1-30
Interactive demo
omnivoice-demo starts a Gradio interface with separate voice-clone and voice-design tabs. The clone tab accepts target text, reference audio, optional reference text, and language. The design tab presents the supported speaker categories and turns the selected values into an instruction before generation.
The demo requires the optional UI dependency. Source users install it with uv sync --extra ui, while package users install the omnivoice[ui] extra. It can auto-load ASR for reference transcription, or skip ASR when every clone request supplies its own transcript. Its settings expose speed, fixed duration, inference steps, guidance, denoising, reference preprocessing, and output post-processing. The model loads with a device-appropriate numeric type for the selected or auto-detected device. References: omnivoice/…/demo.py• L17-24, omnivoice/…/demo.py• L31-37, omnivoice/…/demo.py• L46-53, omnivoice/…/demo.py• L58-109, omnivoice/…/demo.py• L121-154, omnivoice/…/demo.py• L162-229, omnivoice/…/demo.py• L245-307, omnivoice/…/demo.py• L309-505, omnivoice/…/demo.py• L515-546, omnivoice/…/dtype.py• L1-30
Headless dubbing
omnivoice-dub drives a media dubbing job through the running backend. It accepts a local video or a remote URL, then follows the same high-level path as the UI: ingest media, prepare audio, transcribe speech, translate the segments, generate target-language speech, and export the result.
The command streams task events while preparation and generation run. A target language is required. An optional voice profile applies one saved voice to the segments, while a glossary or quality mode shapes translation. The backend keeps segment timing and audio tracks so the final export can include the dubbed track and, when requested, the original or background audio. References: omnivoice/…/dub.py• L1-22, omnivoice/…/dub.py• L85-108, omnivoice/…/dub.py• L110-224, backend/…/dub_pipeline.py• L491-533, backend/…/dub_core.py• L414-533, backend/…/dub_translate.py• L273-360, backend/…/dub_generate.py• L481-505, backend/…/dub_export.py• L570-699
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
OmniVoice.generate()input modes aligned with the single-item CLI, batch JSONL fields, and demo controls. A new request field that is not forwarded by one entrypoint can silently produce a different voice or duration. - Keep the language names and IDs in omnivoice/…/lang_map.py aligned with the demo language list and the model’s language resolver.
- Keep voice-design tags, category conflict rules, and the demo’s dropdown values aligned. Stored profile healing must preserve the same tag meaning as live validation.
- Keep duration estimation, frame-rate conversion, long-text thresholds, and batch duration grouping consistent. A mismatch can cause the batch planner to size work differently from the model.
- Keep reference-audio error markers aligned with the UI error handling. These markers are part of the cross-layer contract for clone failures.
- Keep the dubbing CLI’s HTTP paths and event names aligned with the backend routers and task stream. The CLI depends on terminal
ready,done,error, andcancelledevents. - Keep the dubbing segment language and voice-profile fields aligned with per-track audio and subtitle export. A field mismatch can render a track with the wrong voice or language label.
- Keep the engine IDs, voice-design support flags, and default-engine fallback aligned with engine routing. A mismatch can send a design request to a backend that cannot honor it.
- Keep the sidecar ready, progress, audio, and error frames aligned with the parent subprocess contract. A frame change can turn a recoverable child failure into a lost engine session.
- Keep the sidecar’s parent-interpreter assumption, startup window, receive deadline, and MPS engine alias aligned with process supervision and host routing. A mismatch can cause valid cold starts to be killed or can change the engine ID used by saved projects.
- Keep the device-to-model-type policy aligned across the direct CLI paths and the subprocess loader. A mismatch can make one entrypoint fail on CPU or use a different model load behavior on the same host.
- Keep GGUF platform names, shared-library files, checksum entries, and quant pins aligned across the build script, workflow, and backend resolver. A missing artifact can silently select the in-process fallback.
- Keep the declared 24 kHz mono output contract aligned across the in-process engine, sidecar, GGUF WAV reader, and downstream audio consumers.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Generation uses a model that was not loaded with its text and audio tokenizers | generate() cannot prepare inputs or decode output | Load inference models through OmniVoice.from_pretrained() |
| Clone reference is empty, digitally silent, non-finite, or unusable after trimming | The request fails instead of producing a valid clone | Validate the clip and use a clear spoken passage |
| Clone transcript is missing while ASR is disabled or unavailable | The reference cannot be aligned to text | Supply ref_text, or load ASR before automatic transcription |
| Design instruction contains an unknown tag or two values from one category | Generation rejects the request | Use the supported tags and one language-consistent value per category |
| Long batch items mix reference and non-reference inputs | Chunked generation cannot use one reference policy for the group | Group requests by the same clone mode before long generation |
| A CLI or sidecar loads a model type that is not suited to its selected device | Model loading or inference can fail on CPU or vary across entrypoints | Use the shared device-to-model-type policy |
| GGUF binary is missing, invalid, quarantined, or fails its startup probe | The optional engine is unavailable and default routing uses the in-process engine | Build or reinstall the matching platform runtime, or select the in-process engine explicitly |
| GGUF build omits a required shared library | The child process fails at startup even though the executable exists | Ship the libraries with the binary and keep the loader path in the backend launch contract |
| Voice-design input is sent to the GGUF backend | The request cannot produce the requested designed voice | Route voice-design work to an engine that advertises native voice-design support |
| Sidecar startup or synthesis exceeds its host-specific budget | The request fails, but the parent can hard-kill and replace the child process | Keep the startup and receive budgets aligned with cold-load and render time; use the parent interpreter and matching host dependencies |
| Sidecar closes during generation under host memory pressure | The request fails with a recoverable engine error instead of taking down the backend | Reduce competing memory use or select a smaller engine, then retry |
| Batch JSONL contains malformed lines or missing required item data | Malformed lines are skipped, while later missing data can fail the batch task | Validate each input object before submission and inspect warnings |
| Dubbing CLI cannot reach the backend or the backend has no usable media | The job stops before synthesis or export | Start the backend and check the ingest event stream for the first failed stage |
| Dubbing export has no generated track | The download endpoint returns no output | Wait for generation to emit done before requesting the export |
Key files
| File | Why to read it |
|---|---|
| omnivoice/…/omnivoice.py | Defines the public generation contract and the complete inference flow from request preparation to decoded audio. |
| omnivoice/…/omnivoice_flashinfer.py | Shows the optional accelerated execution path and its requirement to preserve baseline decoding behavior. |
| omnivoice/…/voice_design.py | Defines the supported voice-design vocabulary and the rules that make stored and live instructions safe. |
| omnivoice/…/duration.py | Explains language-aware duration planning when callers do not set a fixed duration. |
| omnivoice/…/audio.py | Defines reference validation, silence handling, waveform preparation, fades, padding, and chunk joining. |
| omnivoice/…/text.py | Defines punctuation-aware long-text splitting and text pause handling used by speech flows. |
| omnivoice/…/dtype.py | Defines the shared model type choice used by CPU, MPS, and CUDA inference paths. |
| omnivoice/…/data_utils.py | Defines the JSONL input contract used by batch inference. |
| omnivoice/…/infer.py | Provides the smallest end-to-end command for one synthesis request. |
| omnivoice/…/infer_batch.py | Shows JSONL batch input, duration-aware scheduling, multi-device workers, warmup, and output reporting. |
| omnivoice/…/demo.py | Connects the model’s clone and design modes to the interactive user flow. |
| omnivoice/…/dub.py | Shows the headless media dubbing lifecycle and its event-stream contract. |
| backend/…/backend.py | Defines the hardware-adaptive GGUF engine, its fallback probe, and its external runtime boundary. |
| backend/…/__init__.py | Defines the resident crash-isolated OmniVoice engine, parent-interpreter execution, timeout recovery, and MPS engine alias. |
| backend/…/main.py | Defines the sidecar lifecycle and the message contract for model loading and audio return. |
| scripts/build-omnivoice-tts.sh | Builds platform runtimes and records the files needed for verified GGUF execution. |
| .github/…/build-omnivoice-tts.yml | Defines when supported platform runtime artifacts are built and uploaded. |
| backend/…/dub_pipeline.py | Explains the shared job, ingest, artifact, and task-state model used by the dubbing API and CLI. |
| backend/…/dub_translate.py | Shows how transcript segments become target-language text before speech generation. |
| backend/…/dub_generate.py | Shows how timed translated segments become per-track speech audio. |
| backend/…/dub_export.py | Shows how generated tracks and optional background audio become downloadable media. |
| pyproject.toml | Defines the four installed command names and their CLI entrypoints. |