Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +25 -7
- app.py +160 -0
- female_shadowheart4.flac +3 -0
- requirements.txt +18 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
female_shadowheart4.flac filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,13 +1,31 @@
|
|
| 1 |
---
|
| 2 |
-
title: Chatterbox
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.26.0
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Chatterbox-Flash TTS
|
| 3 |
+
emoji: 🎙️
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.26.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
short_description: Block-diffusion zero-shot text-to-speech by Resemble AI
|
| 10 |
+
python_version: "3.12"
|
| 11 |
+
startup_duration_timeout: 30m
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Chatterbox-Flash TTS
|
| 15 |
+
|
| 16 |
+
[Chatterbox-Flash](https://github.com/resemble-ai/chatterbox-flash) is a prior-calibrated block-diffusion zero-shot text-to-speech model by Resemble AI. It extends Chatterbox-TTS with a parallel masked decoder that enables streaming generation with significantly lower latency.
|
| 17 |
+
|
| 18 |
+
## How it works
|
| 19 |
+
|
| 20 |
+
1. Enter the text you want to synthesize.
|
| 21 |
+
2. Optionally upload a short reference audio clip to clone a specific voice.
|
| 22 |
+
3. Click **Generate** to produce speech.
|
| 23 |
+
|
| 24 |
+
The model uses a block-diffusion decoder (based on Llama-520M) with prior-calibrated PMI scoring and early decoding via a time-shifted quantile schedule, paired with the original S3Gen flow-matching vocoder and GE2E voice encoder.
|
| 25 |
+
|
| 26 |
+
## Reference
|
| 27 |
+
|
| 28 |
+
- **Paper**: [Chatterbox-Flash: Prior-Calibrated Block Diffusion for Streaming Zero-Shot TTS](https://huggingface.co/papers/2605.30748)
|
| 29 |
+
- **Model**: [ResembleAI/chatterbox-flash](https://huggingface.co/ResembleAI/chatterbox-flash)
|
| 30 |
+
- **Code**: [github.com/resemble-ai/chatterbox-flash](https://github.com/resemble-ai/chatterbox-flash)
|
| 31 |
+
- **License**: MIT
|
app.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.environ.setdefault("CHATTERBOX_FLASH_ENGINE", "torch")
|
| 3 |
+
|
| 4 |
+
import spaces
|
| 5 |
+
import torch
|
| 6 |
+
import numpy as np
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
# Install chatterbox-tts and chatterbox-flash with --no-deps to avoid
|
| 10 |
+
# the torch==2.6.0 pin (incompatible with ZeroGPU's torch 2.11).
|
| 11 |
+
# Then their real deps are listed in requirements.txt.
|
| 12 |
+
import subprocess
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
subprocess.run(
|
| 16 |
+
[sys.executable, "-m", "pip", "install", "--no-deps",
|
| 17 |
+
"chatterbox-tts==0.1.7", "chatterbox-flash==0.1.0"],
|
| 18 |
+
check=True,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
from chatterbox_flash import ChatterboxFlashTTS
|
| 22 |
+
|
| 23 |
+
MODEL_ID = "ResembleAI/chatterbox-flash"
|
| 24 |
+
DEVICE = "cuda"
|
| 25 |
+
|
| 26 |
+
print(f"Loading Chatterbox-Flash from {MODEL_ID}...")
|
| 27 |
+
tts = ChatterboxFlashTTS.from_pretrained(
|
| 28 |
+
MODEL_ID, device=DEVICE, dtype=torch.bfloat16,
|
| 29 |
+
)
|
| 30 |
+
tts.to(DEVICE)
|
| 31 |
+
print("Model loaded successfully.")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@spaces.GPU(duration=120)
|
| 35 |
+
def generate_tts(
|
| 36 |
+
text_input: str,
|
| 37 |
+
audio_prompt_path: str | None = None,
|
| 38 |
+
exaggeration: float = 0.5,
|
| 39 |
+
temperature: float = 0.6,
|
| 40 |
+
cfg_scale: float = 1.0,
|
| 41 |
+
num_steps: int = 10,
|
| 42 |
+
seed_num: int = 0,
|
| 43 |
+
):
|
| 44 |
+
"""Generate speech from text using Chatterbox-Flash block-diffusion TTS.
|
| 45 |
+
|
| 46 |
+
Zero-shot voice cloning: provide a short reference audio clip to clone
|
| 47 |
+
the speaker's voice, or leave it empty to use the default voice.
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
text_input: Text to synthesize (max 300 characters).
|
| 51 |
+
audio_prompt_path: Reference audio file for voice cloning (optional).
|
| 52 |
+
exaggeration: Controls speech expressiveness (0.25-2.0, 0.5=neutral).
|
| 53 |
+
temperature: Controls randomness in generation (0.05-5.0, higher=more varied).
|
| 54 |
+
cfg_scale: Classifier-free guidance scale (0.2-1.0).
|
| 55 |
+
num_steps: Number of block-diffusion denoising steps (default 10).
|
| 56 |
+
seed_num: Random seed for reproducibility (0=random).
|
| 57 |
+
"""
|
| 58 |
+
if seed_num != 0:
|
| 59 |
+
torch.manual_seed(int(seed_num))
|
| 60 |
+
torch.cuda.manual_seed(int(seed_num))
|
| 61 |
+
np.random.seed(int(seed_num))
|
| 62 |
+
|
| 63 |
+
generate_kwargs = {
|
| 64 |
+
"exaggeration": exaggeration,
|
| 65 |
+
"temperature": temperature,
|
| 66 |
+
"cfg_scale": cfg_scale,
|
| 67 |
+
"num_steps": num_steps,
|
| 68 |
+
"backend": "torch",
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
if audio_prompt_path:
|
| 72 |
+
generate_kwargs["audio_prompt_path"] = audio_prompt_path
|
| 73 |
+
|
| 74 |
+
wav = tts.generate(text_input[:300], **generate_kwargs)
|
| 75 |
+
return (tts.sr, wav.squeeze(0).numpy())
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
CSS = """
|
| 79 |
+
#col-container { max-width: 1100px; margin: 0 auto; }
|
| 80 |
+
.dark .gradio-container { color: var(--body-text-color); }
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
|
| 84 |
+
gr.Markdown(
|
| 85 |
+
"""
|
| 86 |
+
# Chatterbox-Flash TTS
|
| 87 |
+
Prior-calibrated block-diffusion zero-shot TTS by Resemble AI.
|
| 88 |
+
Provide a reference audio clip to clone a voice, or generate with the default voice.
|
| 89 |
+
|
| 90 |
+
[Paper](https://huggingface.co/papers/2605.30748) · [Model](https://huggingface.co/ResembleAI/chatterbox-flash) · [GitHub](https://github.com/resemble-ai/chatterbox-flash)
|
| 91 |
+
"""
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
with gr.Row(id="col-container"):
|
| 95 |
+
with gr.Column(scale=3):
|
| 96 |
+
text = gr.Textbox(
|
| 97 |
+
value="Sometimes it's better to just let things slide, you know?",
|
| 98 |
+
label="Text to synthesize (max 300 chars)",
|
| 99 |
+
max_lines=5,
|
| 100 |
+
)
|
| 101 |
+
ref_wav = gr.Audio(
|
| 102 |
+
sources=["upload", "microphone"],
|
| 103 |
+
type="filepath",
|
| 104 |
+
label="Reference Audio (optional — for voice cloning)",
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
with gr.Accordion("Advanced settings", open=False):
|
| 108 |
+
exaggeration = gr.Slider(
|
| 109 |
+
0.25, 2.0, step=0.05,
|
| 110 |
+
label="Exaggeration (0.5=neutral, higher=more expressive)",
|
| 111 |
+
value=0.5,
|
| 112 |
+
)
|
| 113 |
+
temperature = gr.Slider(
|
| 114 |
+
0.05, 2.0, step=0.05,
|
| 115 |
+
label="Temperature",
|
| 116 |
+
value=0.6,
|
| 117 |
+
)
|
| 118 |
+
cfg_scale = gr.Slider(
|
| 119 |
+
0.2, 1.0, step=0.05,
|
| 120 |
+
label="CFG Scale",
|
| 121 |
+
value=1.0,
|
| 122 |
+
)
|
| 123 |
+
num_steps = gr.Slider(
|
| 124 |
+
1, 30, step=1,
|
| 125 |
+
label="Denoising Steps",
|
| 126 |
+
value=10,
|
| 127 |
+
)
|
| 128 |
+
seed_num = gr.Number(
|
| 129 |
+
value=0, label="Seed (0=random)", precision=0,
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
run_btn = gr.Button("Generate", variant="primary")
|
| 133 |
+
|
| 134 |
+
with gr.Column(scale=2):
|
| 135 |
+
audio_output = gr.Audio(label="Output Audio")
|
| 136 |
+
|
| 137 |
+
gr.Examples(
|
| 138 |
+
examples=[
|
| 139 |
+
["Sometimes it's better to just let things slide, you know?"],
|
| 140 |
+
["The quick brown fox jumps over the lazy dog. Pack my box with five dozen liquor jugs."],
|
| 141 |
+
["In the depths of winter, I finally learned that within me lay an invincible summer."],
|
| 142 |
+
],
|
| 143 |
+
inputs=[text],
|
| 144 |
+
outputs=[audio_output],
|
| 145 |
+
fn=generate_tts,
|
| 146 |
+
cache_examples=True,
|
| 147 |
+
cache_mode="lazy",
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
run_btn.click(
|
| 151 |
+
fn=generate_tts,
|
| 152 |
+
inputs=[
|
| 153 |
+
text, ref_wav, exaggeration,
|
| 154 |
+
temperature, cfg_scale, num_steps, seed_num,
|
| 155 |
+
],
|
| 156 |
+
outputs=[audio_output],
|
| 157 |
+
api_name="generate",
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
demo.launch(mcp_server=True)
|
female_shadowheart4.flac
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:19c9562517aca84931af549a7a3578ebb033024f9dbcda7f99881338cba6124c
|
| 3 |
+
size 573883
|
requirements.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chatterbox-tts==0.1.7
|
| 2 |
+
chatterbox-flash==0.1.0
|
| 3 |
+
transformers==5.2.0
|
| 4 |
+
diffusers==0.29.0
|
| 5 |
+
torchaudio
|
| 6 |
+
librosa==0.11.0
|
| 7 |
+
s3tokenizer
|
| 8 |
+
resemble-perth>=1.0.0
|
| 9 |
+
conformer==0.3.2
|
| 10 |
+
safetensors==0.5.3
|
| 11 |
+
omegaconf
|
| 12 |
+
numpy<2.0.0
|
| 13 |
+
soundfile
|
| 14 |
+
scipy
|
| 15 |
+
inflect>=7.0
|
| 16 |
+
Unidecode>=1.3
|
| 17 |
+
pyloudnorm
|
| 18 |
+
peft
|