DramaBox Documentation

repository·master·Indexed 19 days ago

https://github.com/resemble-ai/dramabox

An expressive Text-to-Speech (TTS) system with voice cloning capabilities built on the LTX-2.3 audio model. DramaBox allows control over emotion, delivery, and non-verbal sounds via a specific prompting pattern of stage directions and quoted dialogue. It features the TTSServer for long-form generation with automatic chunking, RE-USE voice reference denoising, and support for LoRA fine-tuning to add specific speakers or styles. All generated audio is automatically watermarked using Resemble Perth.

Tokens
12.8K
Snippets
29
Records
48
Agent score
63%

What's inside DramaBox

  1. How to define speakers in DramaBox prompts

    master

    When defining a speaker, use a generic noun phrase combined with at most one optional adjective. Do not use professional roles, as the model may attempt to speak the role name itself.

    StrategyExampleNotes
    GoodA man, A woman, A young woman, An elderly man, A childUses generic nouns.
    GoodA weary man, A grieving woman, A nervous young womanUses exactly one adjective.
    BadA radio host, A spy, A detective, A teacherThe model may speak the role noun.
    BadA late-night radio host with a warm, smoky voiceAvoid stacking multiple adjectives or long descriptions.
  2. The DramaBox prompting pattern

    master

    To ensure reliable delivery, use a multi-segment pattern that combines stage directions with quoted dialogue. The model uses unquoted text as stage directions to shape delivery and quoted text as the literal spoken content.

    The Pattern: A <speaker> <verb>, "<dialogue>" <pronoun> <verb>, "<dialogue>"

    Key Rules:

    • Quoted text is spoken literally: This includes non-verbal sounds like Hahaha, Mmmm-mmm, or Woooo.
    • Unquoted text is stage direction: This shapes the delivery but is not spoken.
    • End at the last closing quote: Any description following the final quote may be ignored or read incorrectly.
    • Use multi-segment beats: For high emotional contrast, use a calm setup followed by an emotional shift rather than a single expressive verb.

    Example:

    A man speaks evenly, "I gave you one job."
    His voice rises with fury, "AND YOU MESSED IT UP!"
    A man speaks evenly, "I gave you one job."
    His voice rises with fury, "AND YOU MESSED IT UP!"
  3. Install optional RE-USE dependencies

    master

    The REUSEUpsampler class requires optional dependencies for speech enhancement and bandwidth extension. If these are not installed, the class will fail to initialize. To enable denoising, install the required packages using the provided requirements file:

    pip install -r requirements-reuse.txt

    Note: mamba-ssm and causal-conv1d do not have pre-built wheels for macOS or Windows and require matching CUDA and nvcc on Linux. If you cannot install these, you can run the pipeline without RE-USE by setting denoise_ref=False in the server configuration or unticking 'Denoise voice reference' in the Gradio UI.

    pip install -r requirements-reuse.txt
  4. Quick Start with TTSServer (Recommended)

    master

    For the best performance and easiest integration, use the TTSServer class. It supports automatic long-form generation (text chunking) and optional voice reference denoising.

    Key features:

    • Automatic Chunking: For prompts longer than ~45s, the server automatically splits text at sentence/quote boundaries and concatenates them with a 50ms crossfade to maintain speaker coherence.
    • Voice Reference: Provide a 10+ second audio file to clone the target timbre.
    • Denoising: If nvidia/RE-USE dependencies are installed, you can enable denoise_ref=True for cleaner voice cloning.
    from src.inference_server import TTSServer
    
    server = TTSServer(device="cuda")
    
    server.generate_to_file(
        prompt='A woman speaks warmly, "Hello, how are you today?" She laughs, "Hahaha, it is so good to see you!"',
        output="output.wav",
        voice_ref="reference.wav",   # optional, 10+ seconds
    )
  5. Enable Voice Reference Denoising (RE-USE)

    master

    To improve voice cloning quality, you can opt-in to nvidia/RE-USE denoising. This requires additional dependencies that are not included in the base installation to avoid compatibility issues on macOS/Windows.

    1. Install dependencies:

    pip install -r requirements-reuse.txt

    2. Use in code: Set denoise_ref=True in your generate_to_file call. If dependencies are missing, the server will log a warning and fallback to standard generation without denoising.

    server.generate_to_file(
        prompt='A woman speaks warmly, "Hello."',
        output="out.wav",
        voice_ref="ref.wav",
        denoise_ref=True,
    )
  6. Train a LoRA on top of DramaBox

    master

    You can fine-tune a LoRA using DramaBox as a base to add specific speakers or styles.

    1. Prepare Dataset

    The preprocessor supports four formats. The text field should be the target transcript. For prompted training, prepend the scene description: A woman speaks warmly, "<transcript>".

    • Format A (Manifest/JSONL): {"audio_filepath": "path.wav", "text": "transcript"} (Recommended)
    • Format B (TSV): path.wav\ttranscript
    • Format C (Gemini Synthetic): id~speaker~lang~sr~samples~dur~phonemes~text
    • Format D (Libriheavy): id~speaker~lang~samples~dur_ms~phonemes~text

    2. Preprocess

    Run src/preprocess.py to generate training-ready .pt files (audio latents, text embeddings, and dummy video latents).

    python src/preprocess.py \
      --dataset-type manifest \
      --index your_data.jsonl \
      --audio-dir /path/to/wavs \
      --output-dir /path/to/preprocessed/ \
      --checkpoint /path/to/dramabox-audio-components.safetensors \
      --gemma-root /path/to/gemma-3-12b-it-bnb-4bit/ \
      --max-duration 20.0 --min-duration 2.0

    3. Train

    Use accelerate launch src/train.py with a configuration file (e.g., configs/training_args.example.yaml). The trainer targets 288 LoRA pairs across 48 transformer blocks.

    4. Inference with LoRA

    Important: Always load the LoRA at inference time rather than pre-merging it to avoid output degradation.

    python src/inference.py \
      --lora /path/to/your/lora_step_5000.safetensors \
      --voice-sample reference.wav \
      --prompt 'A woman speaks warmly, "..."' \
      --output output.wav
  7. Detect Watermarks in Audio Output

    master

    All audio generated via inference.py or TTSServer.generate_to_file is automatically watermarked using Resemble Perth. This watermark is imperceptible and survives compression/editing.

    To detect the watermark, use the perth library:

    ```python
    import perth, librosa
    wav, sr = librosa.load("output.wav", sr=None, mono=True)
    detector = perth.PerthImplicitWatermarker()
    print(detector.get_watermark(wav, sample_rate=sr))   # confidence ≈ 1.0

    To disable watermarking for debugging, pass --no-watermark to the CLI or watermark=False to generate_to_file.

  8. Write Effective Prompts for DramaBox

    master

    DramaBox uses a prompt-driven approach where the text controls emotion, delivery, and non-verbal sounds.

    Structure: <speaker description>, "<dialogue>" <action direction> "<more dialogue>"

    Guidelines:

    • Inside Quotes (Actual Sounds): Use for laughs ("Hahaha", "Hehehe") and sounds ("Mmmmm", "Ugh", "Ahhh"). Note: Laughs must be a single word.
    • Outside Quotes (Stage Directions): Use for emotional cues or physical actions (e.g., She sighs deeply., He gulps nervously., A long pause.).
    • Avoid inside quotes: Do not write words like Ahem, Sigh, or Cough inside quotes, as the model may attempt to speak them literally.
    • Consistency: Match the gender/age in the speaker description to your voice_ref.
    • Termination: End the prompt at the last closing quote mark; do not add trailing descriptions.
  9. Apply styles and emotions using two-span prompts

    master

    For the best emotional results, use a two-span prompt structure: a calm setup followed by an emotional payoff. When continuing a prompt, use the speaker's gendered pronoun (He or She) in the continuation verbs.

    TonePattern
    Angry / loudA man speaks evenly, "<setup>" His voice rises with fury, "<LINE-IN-CAPS>"
    TenderA woman speaks tenderly, "<setup>" She hums quietly, "Mmmm-mmm, <follow-up>"
    MenacingA man speaks with cold menace, "<setup>" He chuckles darkly, "<follow-up>"
    SadA grieving woman weeps softly, "<setup>" She sighs with despair, "<follow-up>"
    JoyfulA man bursts into uncontrollable laughter, "Hahaha! <line>"
    FearfulA terrified woman speaks shakily, "<setup>" She begins to cry, "<follow-up>"
    NervousA young man clears his throat, "<setup>" He stammers nervously, "<follow-up>"
    AweA man speaks with quiet awe, "<setup>" He breathes out slowly, "<follow-up>"
    SmugA man speaks with smug pride, "<setup>" He chuckles confidently, "<follow-up>"
    FlirtyA flirtatious woman purrs flirtatiously, "<setup>" She laughs softly, "<follow-up>"
  10. Configure REUSEUpsampler parameters

    master

    When initializing REUSEUpsampler, you can tune several parameters to balance VRAM usage and processing quality:

    • target_sr (int): The target sampling rate for enhancement/extension (default: 48000).
    • config_path (str, optional): Path to a specific YAML configuration file. If not provided, it defaults to a standard recipe from the RE-USE repository.
    • chunk_size_s (float): The duration of each processing chunk in seconds. Smaller values reduce VRAM usage but may affect continuity. (default: 1.0).
    • hop_portion (float): The portion of the chunk size used for the hop length in the overlap-add process. (default: 0.5).
    • device (str | torch.device): The device to run inference on (default: "cuda").
    up = REUSEUpsampler(
        target_sr=48000,
        config_path="/path/to/custom_config.yaml",
        chunk_size_s=2.5,
        hop_portion=0.5,
        device="cuda"
    )
  11. Configure long-form generation (chunking and crossfade)

    master

    For prompts that result in estimated durations longer than the model's stable regime (typically >45s), DramaBox uses a chunking mechanism to maintain quality.

    • Max chunk duration (max_chunk_duration): The hard cap for a single audio chunk. Chunks exceeding this are rare and may exhibit degradation.
    • Target chunk duration (target_chunk_duration): A soft cap. The system stops adding new sentences to a chunk once it approaches this duration, providing a buffer (headroom) before the hard cap.
    • Crossfade (crossfade_ms): The amount of equal-power overlap between adjacent chunks. A value of 50.0 ms is generally inaudible and provides smooth transitions. 0.0 ms results in a hard cut.
  12. How IC-LoRA training works (Conceptual)

    master

    The IC-LoRA (In-Context LoRA) training pattern for DramaBox follows these steps:

    1. Target Preparation: A target audio latent is loaded and optionally prepended with 0-25 random frames of a real silence latent (to regularize boundaries and reduce hallucinations).
    2. Noise Application: Flow-matching noise is applied to the target latent based on a sampled sigma value.
    3. Reference Appending: Reference audio tokens are appended to the end of the noisy target sequence using AudioConditionByReferenceLatent.
    4. Masking: The denoise_mask is set to 1.0 for target tokens and 0.0 for reference tokens. This ensures the loss is computed only on the target tokens, forcing the model to learn how to generate the target audio conditioned on the provided reference identity.
    5. Special Cases: For SFX (speaker starts with sfx_) or Suno music samples, the reference is dropped (zero-length), training the model to generate those categories without voice cloning.