Introducing a new way to review your PRs.

Read the announcement

debpalash / voicestudio

VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.

View on GitHub

26 documents · Updated Nov 23, 2026

docs / media-localization

Media dubbing and long-form production

Media localization turns recorded media or a long script into a new spoken-language artifact. It links media preparation, speech recognition, translation, speaker-aware voice generation, timing, and export through durable asynchronous jobs. The backend API platform owns these workflows, while voice generation, speech input, speech platform integration, voice calls, and LLM and agent services describe the shared speech and model systems around them.

Media localization flow

The dubbing workflow keeps source text, translated text, voice assignments, audio, and time ranges related through stable segment identities. This lets upload, editing, generation, and export work as one chain for both video and audio-only jobs.

flowchart LR
    A[Audio or video source] --> B[Prepare media]
    B --> C[Recognize speech]
    C --> D[Assign speakers and timings]
    D --> E[Translate or edit segments]
    E --> F[Synthesize timed speech]
    F --> G[Fit the dub]
    G --> H[Export audio, video, or subtitles]

Job preparation

Job preparation accepts a local audio or video file or a remote media URL. The system validates the source, creates a job, and returns before preparation finishes. It then reports download, extraction, separation, scene, and readiness events through a task stream. Audio-only jobs use the same transcript, translation, and speech path as video jobs, but skip scene work and produce a standalone audio artifact.

Local video can be normalized for in-app playback. Preparation extracts an ASR track and can create a higher-quality source track for speech and background separation. Remote sources can provide original-language captions during download, and a source-language choice can override automatic detection. Matching prepared media can reuse safe separation and scene artifacts from an earlier job.

Background separation is optional. When it is unavailable, the workflow keeps the mixed source as the speech input and exports speech-only audio instead of making a finished dub unusable. Preview uploads use the same media checks without creating a dubbing job, and their extraction runs outside the main API path so a large upload does not block unrelated requests.

References: backend/…/dub_core.py• L801-848 backend/…/dub_core.py• L927-1142 backend/…/dub_pipeline.py• L1670-1779 backend/…/dub_pipeline.py• L1781-1955 backend/…/dub_pipeline.py• L1957-2109

Transcript and speaker map

Recognition turns prepared audio into timed text segments. The workflow can use speech recognition, an imported SRT file, pasted timed subtitle text, or downloaded original-language captions. Each source is normalized into the same segment shape so later stages can work from one timeline.

Speaker assignment uses diarization when it is available. Some speech engines provide speaker turns directly, while silence-gap estimates provide a weaker fallback. An explicit speaker-count request can use the diarization path when the engine supports it. Fallback labels remain approximate because they do not identify a voice from the audio.

The resulting speaker and reference assignments guide per-line or consistent-speaker voice generation. Imported captions provide text and timing but no trusted speaker evidence, so they do not keep stale voice references. Replacing subtitles preserves references only when a new cue overlaps the matching old cue. Downloaded captions with an unknown language remain unknown until the user selects a source language.

Transcription can be replayed from the saved job after a connection loss. A later subtitle import, cleanup, or editor change takes precedence over an older transcription or render that finishes afterward.

References: backend/…/dub_core.py• L261-477 backend/…/dub_core.py• L480-629 backend/…/dub_core.py• L1690-1752 backend/…/dub_core.py• L2001-2182 backend/…/dub_pipeline.py• L453-509

Translation and timing

Translation works on timed segments rather than on one undivided transcript. The engine registry tells the client which local, remote, and language-model providers are installed, configured, and ready. This lets the user choose a usable path before segment work starts.

Each result stays tied to its segment. Target language, regional dialect, glossary terms, script checks, and optional spoken-language refinement travel with the translation request. A direct translation remains usable when an optional refinement or fitting pass fails. The workflow also estimates speech duration before synthesis so the editor can see tight or impossible lines and choose a fit strategy.

Before synthesis, the workflow compares translated speech length with each source slot and nearby gaps. It can retain natural timing, fit speech to the slot, or plan changes to the video timeline. The selected timing strategy is carried into generation, preview, subtitle output, and export.

References: backend/…/dub_translate.py• L320-405 backend/…/dub_translate.py• L487-537 backend/…/dub_translate.py• L787-946 backend/…/dub_translate.py• L1155-1503

Timed speech production

Generation turns edited target text into speech one segment at a time. Each segment uses its language, time slot, delivery controls, and assigned voice reference. Per-line matching favors source prosody, while consistent-speaker matching favors one reference for a speaker across the dub.

Each language track has its own segment text, audio, fingerprints, natural-rate data, and timing state. This keeps subtitle text and cached speech aligned when a job contains more than one language. Partial regeneration reuses unchanged segments only when their language and inputs match. A new language cannot reuse ambiguous audio from another track.

Natural-rate audio stays complete until assembly. The selected strategy can then leave speech natural, fit it within a slot, or share timing changes with the video. Smart Fit can divide timing changes between speech and video. The older video-stretch path changes the visual timeline to follow the generated speech.

Fresh speech is staged until the render is safe to publish. The source revision is checked before commit, so a late render cannot replace subtitles that a user imported or edited while it ran. Interrupted renders can recover finished segments when their inputs still match. Completed segment work can remain available after cancellation or failure when the track can be assembled safely.

References: backend/…/dub_generate.py• L221-313 backend/…/dub_generate.py• L448-498 backend/…/dub_generate.py• L509-639 backend/…/dub_generate.py• L659-718 backend/…/dub_generate.py• L843-914 backend/…/dub_generate.py• L1861-1962 backend/…/dub_generate.py• L2160-2243

Artifact export

Export combines generated language tracks with source media and optional background audio. A video can include the original audio and several dubbed tracks. An audio-only job exports a selected dub as WAV, M4A, MP3, or FLAC.

Subtitle output uses the selected language track and its stored segment text. SRT, VTT, and ASS provide timed sidecar cues, while burned subtitles and karaoke output use the same selected timeline. Smart Fit carries fitted cue times into the video and subtitle output. The older video-stretch path does not burn subtitles in the same pass when it cannot provide matching cue times.

Preview and download use the selected language, background choice, timing plan, and subtitle rules. A missing separated background produces a valid speech-only result. Audio-only export can mix the separated background into the chosen dub. A failed video retime falls back to an un-retimed artifact with a visible warning instead of hiding valid dubbed audio. Quality control can re-recognize a generated track and mark lines for review without replacing the target text.

flowchart TD
    A[Generated language track] --> B{Artifact type}
    B --> C[Dubbed video]
    B --> D[Dubbed audio]
    B --> E[SRT, VTT, or ASS subtitles]
    C --> F[Optional background and subtitle burn-in]
    D --> G[Optional background mix]
    E --> H[Language-specific timed cues]

References: backend/…/dub_export.py• L429-501 backend/…/dub_export.py• L504-713 backend/…/dub_export.py• L753-887 backend/…/dub_export.py• L892-1222 backend/…/dub_export.py• L1278-1533 backend/…/dub_export.py• L1754-1886 backend/…/dub_export.py• L2004-2059 backend/…/dub_export.py• L2135-2283

Audiobook production

Audiobook production applies long-form speech generation to a chaptered script instead of source-media timestamps. It exposes a plan before synthesis, renders chapters from spoken spans and pauses, and produces a chapterized listening artifact.

Script planning

The audiobook front door accepts a chapter-delimited script. Markdown headings define chapters, voice tags select cast members, and pause or style markers shape delivery. Text, Markdown, EPUB, and PDF imports are converted into this shared script form before the plan is shown.

The plan is a preview step with no synthesis. It exposes the chapter structure before the user spends compute. A chapter preview uses the same render rules and cache as the full book, so it can also prepare work for the later render.

Voice maps, language, pronunciation rules, expressive controls, metadata, cover art, and loudness choices travel with the render plan. Missing cast names use the book's default voice instead of silently selecting an unrelated profile.

References: backend/…/audiobook.py• L158-259 backend/…/audiobook.py• L1044-1096

Chapter rendering

The shared long-form render core turns chapter spans into chapter audio and then joins the chapters into one book. Unchanged chapters and spans can reuse prior audio, while changed chapters reuse any spans that remain unchanged. This gives audiobook and other chapter-based products the same resume and cache behavior.

The render keeps completed work and its plan after a stop or failure. A later retry can continue from that partial work. Cache inputs stay protected while a render is active, and incomplete or damaged audio is treated as a cache miss rather than as a valid chapter.

References: backend/…/longform_render.py• L60-101 backend/…/longform_render.py• L130-184 backend/…/longform_render.py• L189-221 backend/…/longform_render.py• L377-405 backend/…/longform_render.py• L408-613

Long-form artifacts

The completed book exports as a chapterized M4B by default and can also use MP3. Player-visible metadata and valid cover art can travel with the book. Optional loudness treatment prepares the final program for its target listening context.

The render can report a partial result when some chapters fail. If all chapters fail, the job records a terminal failure and keeps its plan for retry. Finished audiobook and Story renders appear in a shared download library only when their job records contain a valid completed output.

References: backend/…/longform_render.py• L616-875 backend/…/longform_render.py• L897-937 backend/…/audiobook.py• L1099-1113 backend/…/audiobook.py• L1371-1529 backend/…/audiobook.py• L1662-1751

Asynchronous job behavior

Both dubbing and audiobook production are long-running jobs. They report stage progress, retain state that can restore the visible job, and support cancellation or retry without discarding safe completed work.

Progress and recovery

Dubbing preparation, transcription, generation, and export report progress through Server-Sent Events. Persisted event tails let a client replay progress after reconnect or server restart, and job records expose the saved state outside the live stream. Keepalives keep a stream open while media tools or models are busy, and each job ends with a named terminal state.

Job deletion is treated as a withdrawal, not as a transient cache miss. An in-flight task stops without writing the deleted job back to history. A later request can create a new job, while a render that started before deletion cannot resurrect the old one.

Audiobook rendering reports chapter completion and keeps a resume plan when a render stops. A client disconnect stops new chapter scheduling while preserving completed cache work. The long-form library rebuilds its list from completed job records and valid terminal output rather than treating any saved job as downloadable.

References: backend/…/dub_pipeline.py• L421-509 backend/…/dub_pipeline.py• L558-755 backend/…/dub_pipeline.py• L1670-2145 backend/…/dub_core.py• L1690-1752 backend/…/dub_export.py• L303-355 backend/…/dub_export.py• L361-417 backend/…/audiobook.py• L1099-1113 backend/…/audiobook.py• L1172-1419

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep one segment identity across transcript edits, per-language text, segment audio, subtitle cues, preview playback, quality checks, and partial regeneration.
  • Keep each language's text, timing plan, segment audio, fingerprints, and subtitle output isolated. Do not reuse ambiguous legacy audio after a second language exists.
  • Keep subtitle replacement voice references tied to temporal overlap. Do not inherit a clone because a new cue has the same numeric id.
  • Keep source-language normalization conservative. An unknown ASR or caption value must stay unknown rather than map to a nearby language.
  • Keep translation-engine readiness, provider configuration, language-pack status, and translate-time dispatch in agreement.
  • Keep dialect and script checks aligned with the final target language. A regional target must reach the same provider and per-segment paths as its base language.
  • Keep timing strategy changes aligned across translation, generation, preview, burned subtitles, and SRT/VTT/ASS export.
  • Keep preview and full export on the same language, background, retime, and subtitle rules. Replace preview files only after a complete mux.
  • Keep fresh dub publication behind the source-revision check. A late render must not replace imported or edited subtitles.
  • Keep staged segment audio and fingerprints committed together. A failed render must not leave new speech under an old identity.
  • Keep audiobook voice-map names and stored profile IDs aligned across parsing, preview, rendering, resume, and cache keys.
  • Keep audiobook render settings, language, pronunciation, cast mapping, and metadata in resume state and cache inputs.
  • Keep terminal event behavior stable for SSE clients. A failure, cancellation, or disconnect must produce a visible job state.
  • Keep long-form library records tied to completed jobs with valid terminal output. Deleting a record must not delete the audio needed for download.

Important failure modes

TriggerConsequenceGuard
The source language is unknownTranslation can use the wrong source languagePreserve the unknown state and require a source-language choice
Diarization is unavailableRapid speaker turns can merge and automatic voice references can be weakMark fallback labels as approximate and warn before relying on auto-clones
A replacement cue has no temporal matchThe new line can inherit the wrong speaker or cloneCarry voice metadata only from the strongest overlap
A translation engine is installed but not configuredTranslation fails after the user selects itShow separate installed, configured, and ready states before translation
A required offline language pack is missingArgos cannot translate the requested pairCheck the requested pairs before segment work starts
A translation or optional fit pass failsA line can remain literal or tightKeep the usable prior text and mark the degraded step
A second language reuses an unscoped segment cacheOne language can enter another language trackScope cache data by language and reject ambiguous legacy reuse
A render finishes after the source subtitles changePublished speech no longer matches the editorCompare source revisions before publication
A video retime failsThe export loses visual fit even though dubbed audio is validReturn an un-retimed artifact with a structured warning
The task stream disconnects during model load or exportThe client loses progress or starts duplicate workSend keepalives and replay persisted events after reconnect
A client stops an audiobook render mid-bookThe book is incomplete but finished chapters may remain usefulStop scheduling new chapters and retain the cache and resume plan
Every audiobook chapter failsThe job can remain falsely marked as runningRecord a terminal failure and retain the plan for retry
FFmpeg is unavailable during exportSynthesis can finish without a final artifactCheck media-tool readiness before the export stage
A long-form job has no valid terminal outputA finished render is missing from the download librarySkip the record instead of exposing an unusable download

Key files

FileWhy to read it
backend/…/dub_core.pyDubbing intake, subtitle replacement, caption use, transcription, speaker assignment, and job control
backend/…/dub_pipeline.pyShared job state, media preparation, content reuse, background separation, process control, persistence, and SSE helpers
backend/…/dub_translate.pySource-language resolution, translation providers, dialect handling, quality passes, and segment results
backend/…/translation_engines.pyProvider inventory, install state, configuration state, readiness, and offline language-pack checks
backend/…/dub_generate.pySpeaker-aware speech generation, language tracks, partial regeneration, timing plans, and staged publication
backend/…/dub_export.pyTask recovery, language-specific subtitles, previews, retime, background mixing, quality checks, and audio or video export
backend/…/longform_render.pyShared chapter and segment cache, metadata, cover handling, loudness, and M4B or MP3 assembly
backend/…/audiobook.pyAudiobook import, planning, chapter preview, rendering, export, and resume lifecycle
backend/…/audiobook.pyShared chapter and spoken-span model plus long-form synthesis behavior
docs/backend-api-platform.mdParent page for API jobs, persistence, and platform-wide request and task behavior
docs/voice-generation.mdShared voice profiles, cloning, and speech-engine choices
docs/speech-input.mdShared speech recognition and audio-input behavior
docs/account-cloud-sync.mdRelated account and data-storage behavior for saved work