# Workflows & Batch Jobs

Automate repetitive tasks using reusable audio and text recipes for batch processing.

VoiceStudio supports automating large-scale voiceover and localization tasks using sequential batch processing and custom visual workflows.

## Batch Processing

The batch processor operates as a sequential dubbing pipeline. It is ideal for localizing high volumes of video or audio files using a unified voice setup. You can access batch dubbing through the command search (`Ctrl/⌘ K` -> Workflows) or the cloning sidebar.

### Queue Architecture

Batch jobs are managed through a lightweight orchestrator with an in-memory queue. Because GPU-bound generation tasks cannot be safely resumed mid-operation, the active queue restarts empty if the backend process restarts. However, job histories and progress records persist locally in the SQLite `jobs` table.

The pipeline serializes execution to prevent competing model loads and GPU Out-Of-Memory (OOM) errors. Large uploads are streamed using 1 MiB chunk allocations to prevent mirroring entire gigabyte-scale videos in system memory.

### The Batch Dubbing Pipeline

When a media file is enqueued, it progresses through several stages:

1. **Extract**: `ffmpeg` extracts the audio stream into a single-channel, 16-bit PCM WAV file sampled at 22.05 kHz. If the input file has no audio stream, the upload is rejected.
2. **Transcribe**: An active Automatic Speech Recognition (ASR) engine detects the source language, segments the transcript, and assigns speaker indices. Transcription is run-guarded on a GPU pool with built-in timeouts to prevent wedged model jobs from starving system resources.
3. **Translate**: The segmented transcript is translated using the selected provider (such as local Argos or NLLB engines). The system verifies that the required translation language packs are installed before admitting the job.
4. **Generate**: VoiceStudio synthesizes the translated segments in the target languages.
   - **Voice Presets & Designs**: Jobs can use saved clones, designed voices, or legacy presets (such as `preset:narrator` for a middle-aged male with a British accent). 
   - **Native Batching**: If the selected TTS engine supports batch execution, multiple segments are processed concurrently up to a safe batch width to amortize setup costs. Other engines fall back to segment-by-segment generation.
   - **Failures & Gaps**: If a single segment fails to synthesize, it is left silent and a warning is appended to the job record rather than terminating the entire run. If a segment times out or is dropped, the job fails loudly to prevent shipping incomplete silent audio.
5. **Mix**: Edges are crossfaded using a 15-millisecond window. VoiceStudio embeds a repeat synthetic watermark throughout the track using `AudioSeal` on a dedicated CPU worker pool, avoiding VRAM overhead. The finalized speech is peak-normalized (target −2 dBFS) and mixed with the original background audio using `ffmpeg` filters (unless background preservation is disabled, which replaces the audio entirely).

### Job Control & Retries

The user interface displays active, completed, and failed jobs:

* **Cancellation**: Active jobs can be cancelled from the dashboard.
* **Deletion**: Finished jobs require confirmation before they are deleted. Deleting a job removes all cached outputs and uploaded files from the backend directory.
* **Retries**: If a job fails or is cancelled, you can retry it. The orchestrator resets the output directory and re-runs the process using the original video upload and settings. Retries verify available models, translation configurations, and voice leases before execution begins.

---

## Visual Workflows

The **Workflows** canvas lets you build visual, step-by-step audio and text recipes. You can pan, zoom, use a minimap, and position canvas blocks with drag-and-drop or arrow keys.

### Executable Steps & Typed Contracts

Workflows pass data sequentially between typed nodes. The canvas enforces strict connection contracts. Incompatible connections or cycles are rejected before execution can start:

* **Start** / **Audio**: The entry points. **Start** consumes text scripts (up to 50 items per run, separated by `---` or loaded from imported TXT, MD, PDF, EPUB, or DOCX files; max 20,000 characters per script). **Audio** accepts uploaded clips (up to 50 clips per run; max 64 MiB per clip).
* **Speak**: Consumes text and outputs synthetic speech in a chosen language, voice, and speed.
* **Convert**: Consumes audio and performs voice conversion to match a saved clone or designed voice.
* **Transcribe**: Consumes audio and uses local speech-to-text to output a transcription.
* **Translate**: Consumes text and translates it via Argos or NLLB engines.
* **Normalize**: Consumes generated or converted synthetic speech and applies peak normalization (−24 to −1 dBFS, default −2) while preserving synthetic-audio markings.
* **End**: The terminal step that gathers exportable outputs.

> **Note:** **Agent** and **Call** are design-only steps. You can place them on the canvas as drafts, but a workflow containing them cannot be executed.

### Routing with Conditions

The **Condition** step routes text processing down a `yes` or `no` branch based on a phrase match.

* **Matching rules**: You can configure conditions to use *Contains*, *Is exactly*, *Starts with*, or *Ends with*. The matching engine ignores casing and surrounding whitespace.
* **Canvas constraints**: Both the `yes` and `no` branches must be connected to downstream steps. Conditions only accept text inputs. Branches can eventually rejoin, but the paths meeting at a shared step must carry the same data type (for example, rejoining a text branch and an audio branch at a shared step is rejected).
* **Execution**: Items walk the graph independently; one item can go down the `yes` path and another down `no`. Conditions are re-evaluated rather than static; because the input text is checkpointed, resuming an interrupted run evaluates the same branch.

### Durable Checkpoints

Execution is strictly serial and processes one item at a time. Every completed step is checkpointed in local IndexedDB. 

* **Resuming Work**: If a run fails, is cancelled, or the application is closed, all finished steps are preserved. Pressing **Retry** resumes processing from the last saved checkpoint instead of regenerating completed segments.
* **Invalidation**: Progress is tied directly to the executable configurations. Changing voices, languages, speeds, normalization targets, condition phrases, or graph paths invalidates the current run's cached checkpoints. However, cosmetic changes such as moving nodes on the canvas or renaming a step do not invalidate completed outputs.
* **Exporting**: Finished outputs can be exported using the native save dialog (`.txt` for text, `.wav` for audio). Files are not saved to disk automatically.

---

## Call Drafts

Workflows can be used to draft automated voice calls for phone-based tasks, such as restaurant bookings, appointment rescheduling, and business-hours inquiries.

* **Drafting**: Connecting a **Start** node to a **Call** node creates a call draft. 
* **Preparation**: Clicking **Prepare call** populates the phone number, voice selection, and brief parameters directly into the interactive dialing form.
* **Integration**: The workflow runner does not dial automatically. Actual calls require manual verification, voice ownership validation, and final confirmation. 

For full call setup details, Twilio configuration, and voice verification requirements, refer to the [Phone Calls](/guides/telephony) documentation.
