Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,90 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
import
|
| 4 |
-
import soundfile as sf
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
-
from
|
| 8 |
-
import
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
def
|
| 21 |
"""
|
| 22 |
-
Voice-to-Voice cloning
|
| 23 |
"""
|
| 24 |
try:
|
| 25 |
-
if not reference_audio:
|
| 26 |
-
return None, "โ Please upload reference audio!"
|
| 27 |
|
| 28 |
-
if not
|
| 29 |
-
return None, "โ
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
return None, "โ Error processing input audio!"
|
| 40 |
-
|
| 41 |
-
# For demo: Apply simple voice transformation
|
| 42 |
-
# In production, this would use actual voice cloning models
|
| 43 |
-
transformed_audio = apply_voice_transformation(
|
| 44 |
-
reference_audio=ref_audio,
|
| 45 |
-
input_audio=input_audio_data,
|
| 46 |
-
enhance_quality=enhance_quality
|
| 47 |
-
)
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
except Exception as e:
|
| 55 |
-
return None, f"โ Error
|
| 56 |
|
| 57 |
-
def
|
| 58 |
"""
|
| 59 |
-
Text-to-
|
| 60 |
"""
|
| 61 |
try:
|
| 62 |
if not reference_audio:
|
|
@@ -65,272 +93,255 @@ def voice_clone_with_text(reference_audio, input_text, language="en", speed=1.0)
|
|
| 65 |
if not input_text or not input_text.strip():
|
| 66 |
return None, "โ Please enter text to convert!"
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
if ref_audio is None:
|
| 71 |
-
return None, "โ Error processing reference audio!"
|
| 72 |
-
|
| 73 |
-
# Generate speech from text (demo implementation)
|
| 74 |
-
generated_audio = text_to_speech_with_voice(
|
| 75 |
-
text=input_text,
|
| 76 |
-
reference_voice=ref_audio,
|
| 77 |
-
language=language,
|
| 78 |
-
speed=speed
|
| 79 |
-
)
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
# Resize to same length
|
| 105 |
-
ref_segment = reference_audio[:min_length]
|
| 106 |
-
input_segment = input_audio[:min_length]
|
| 107 |
-
|
| 108 |
-
# Simple transformation (placeholder)
|
| 109 |
-
transformed = alpha * input_segment + beta * ref_segment
|
| 110 |
|
| 111 |
-
#
|
| 112 |
-
if
|
| 113 |
-
transformed = enhance_audio_quality(transformed)
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
In production, this would use TTS models with voice cloning
|
| 123 |
-
"""
|
| 124 |
-
# Demo: Generate simple synthetic speech
|
| 125 |
-
# This is a placeholder - replace with actual TTS model
|
| 126 |
-
|
| 127 |
-
duration = len(text) * 0.1 * speed # Rough duration estimate
|
| 128 |
-
sr = 16000
|
| 129 |
-
samples = int(duration * sr)
|
| 130 |
-
|
| 131 |
-
# Generate simple sine wave pattern (placeholder)
|
| 132 |
-
t = np.linspace(0, duration, samples)
|
| 133 |
-
frequency = 200 + np.mean(np.abs(reference_voice)) * 100 # Use ref voice characteristics
|
| 134 |
-
|
| 135 |
-
synthetic_speech = 0.3 * np.sin(2 * np.pi * frequency * t)
|
| 136 |
-
|
| 137 |
-
# Add some variation based on text length
|
| 138 |
-
for i, char in enumerate(text[:10]):
|
| 139 |
-
freq_mod = 200 + ord(char) % 100
|
| 140 |
-
synthetic_speech += 0.1 * np.sin(2 * np.pi * freq_mod * t)
|
| 141 |
-
|
| 142 |
-
return synthetic_speech[:samples]
|
| 143 |
-
|
| 144 |
-
def enhance_audio_quality(audio):
|
| 145 |
-
"""Apply audio enhancement"""
|
| 146 |
-
# Simple noise reduction and normalization
|
| 147 |
-
audio = audio / np.max(np.abs(audio)) # Normalize
|
| 148 |
-
audio = audio * 0.8 # Reduce volume slightly
|
| 149 |
-
return audio
|
| 150 |
-
|
| 151 |
-
def save_audio_output(audio_data, sample_rate):
|
| 152 |
-
"""Save audio data to temporary file"""
|
| 153 |
-
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
|
| 154 |
-
output_path = tmp_file.name
|
| 155 |
-
|
| 156 |
-
# Ensure audio is in correct format
|
| 157 |
-
audio_data = np.array(audio_data, dtype=np.float32)
|
| 158 |
-
|
| 159 |
-
# Save using soundfile
|
| 160 |
-
sf.write(output_path, audio_data, sample_rate)
|
| 161 |
-
|
| 162 |
-
return output_path
|
| 163 |
|
| 164 |
-
# Create Gradio interface
|
| 165 |
-
def
|
| 166 |
with gr.Blocks(
|
| 167 |
-
title="๐ญ Voice Cloning Studio",
|
| 168 |
-
theme=gr.themes.Soft(primary_hue="
|
| 169 |
) as demo:
|
| 170 |
|
| 171 |
# Header
|
| 172 |
gr.HTML("""
|
| 173 |
<div style="text-align: center; padding: 20px;">
|
| 174 |
-
<h1 style="color: #
|
| 175 |
-
<p style="color: #666; font-size: 18px;">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
</div>
|
| 177 |
""")
|
| 178 |
|
| 179 |
with gr.Row():
|
| 180 |
with gr.Column(scale=1):
|
| 181 |
# Reference Voice Section
|
| 182 |
-
gr.HTML("<h3 style='color: #
|
| 183 |
reference_audio = gr.Audio(
|
| 184 |
-
label="Reference Audio
|
| 185 |
type="filepath",
|
| 186 |
sources=["upload", "microphone"]
|
| 187 |
)
|
|
|
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
with gr.Column(scale=1):
|
| 192 |
-
#
|
| 193 |
-
gr.HTML("<h3 style='color: #
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
"
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
],
|
| 236 |
-
value="en",
|
| 237 |
-
label="Language"
|
| 238 |
-
)
|
| 239 |
-
|
| 240 |
-
speed_control = gr.Slider(
|
| 241 |
-
minimum=0.5,
|
| 242 |
-
maximum=2.0,
|
| 243 |
-
step=0.1,
|
| 244 |
-
value=1.0,
|
| 245 |
-
label="Speech Speed"
|
| 246 |
-
)
|
| 247 |
-
|
| 248 |
-
text_clone_btn = gr.Button(
|
| 249 |
-
"๐ Generate Speech from Text",
|
| 250 |
-
variant="secondary",
|
| 251 |
-
size="lg"
|
| 252 |
-
)
|
| 253 |
-
|
| 254 |
-
# Output Section
|
| 255 |
-
with gr.Row():
|
| 256 |
-
with gr.Column():
|
| 257 |
-
gr.HTML("<h3 style='color: #2E86AB;'>๐ต Cloned Voice Output</h3>")
|
| 258 |
-
audio_output = gr.Audio(
|
| 259 |
-
label="Generated Audio",
|
| 260 |
-
type="filepath"
|
| 261 |
)
|
| 262 |
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
)
|
| 268 |
|
| 269 |
-
#
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
"
|
| 274 |
-
"
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
inputs=text_input,
|
| 281 |
-
label="Click to try these examples:"
|
| 282 |
)
|
| 283 |
|
| 284 |
-
#
|
| 285 |
-
with gr.Accordion("
|
| 286 |
gr.Markdown("""
|
| 287 |
-
###
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
|
|
|
| 298 |
|
| 299 |
-
|
| 300 |
-
- **
|
| 301 |
-
- **
|
| 302 |
-
- **Language**: Match reference voice language when possible
|
| 303 |
-
- **Length**: Shorter inputs (under 30 seconds) work better
|
| 304 |
""")
|
| 305 |
|
| 306 |
-
# Event
|
| 307 |
-
|
| 308 |
-
fn=
|
| 309 |
-
inputs=[reference_audio, input_audio,
|
| 310 |
outputs=[audio_output, status_output],
|
| 311 |
show_progress=True
|
| 312 |
)
|
| 313 |
|
| 314 |
text_clone_btn.click(
|
| 315 |
-
fn=
|
| 316 |
-
inputs=[reference_audio, text_input,
|
| 317 |
-
outputs=[audio_output, status_output],
|
| 318 |
-
show_progress=True
|
| 319 |
-
)
|
| 320 |
-
|
| 321 |
-
# Auto-generate on Enter for text
|
| 322 |
-
text_input.submit(
|
| 323 |
-
fn=voice_clone_with_text,
|
| 324 |
-
inputs=[reference_audio, text_input, language_select, speed_control],
|
| 325 |
outputs=[audio_output, status_output],
|
| 326 |
show_progress=True
|
| 327 |
)
|
| 328 |
|
| 329 |
return demo
|
| 330 |
|
| 331 |
-
# Launch the app
|
| 332 |
if __name__ == "__main__":
|
| 333 |
-
demo =
|
| 334 |
demo.launch(
|
| 335 |
server_name="0.0.0.0",
|
| 336 |
server_port=7860,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
import torchaudio as ta
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
+
from chatterbox.tts import ChatterboxTTS
|
| 7 |
+
from chatterbox.mtl_tts import ChatterboxMultilingualTTS
|
| 8 |
|
| 9 |
+
# Initialize Chatterbox models (the ones we actually discussed!)
|
| 10 |
+
print("๐ Loading Chatterbox TTS models...")
|
| 11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
# Load Chatterbox English model
|
| 15 |
+
english_model = ChatterboxTTS.from_pretrained(device=device)
|
| 16 |
+
print("โ
Chatterbox English model loaded!")
|
| 17 |
+
|
| 18 |
+
# Load Chatterbox Multilingual model
|
| 19 |
+
multilingual_model = ChatterboxMultilingualTTS.from_pretrained(device=device)
|
| 20 |
+
print("โ
Chatterbox Multilingual model loaded!")
|
| 21 |
+
|
| 22 |
+
models_loaded = True
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"โ Error loading Chatterbox models: {e}")
|
| 25 |
+
english_model = None
|
| 26 |
+
multilingual_model = None
|
| 27 |
+
models_loaded = False
|
| 28 |
|
| 29 |
+
def chatterbox_voice_clone(reference_audio, input_audio, language="en", exaggeration=0.5, cfg=0.5):
|
| 30 |
"""
|
| 31 |
+
Real Voice-to-Voice cloning using Chatterbox (the model we discussed!)
|
| 32 |
"""
|
| 33 |
try:
|
| 34 |
+
if not reference_audio or not input_audio:
|
| 35 |
+
return None, "โ Please upload both reference and input audio files!"
|
| 36 |
|
| 37 |
+
if not models_loaded:
|
| 38 |
+
return None, "โ Chatterbox models not loaded!"
|
| 39 |
|
| 40 |
+
# Extract text from input audio using Whisper
|
| 41 |
+
import whisper
|
| 42 |
+
try:
|
| 43 |
+
whisper_model = whisper.load_model("base")
|
| 44 |
+
result = whisper_model.transcribe(input_audio)
|
| 45 |
+
input_text = result["text"]
|
| 46 |
+
print(f"๐ Extracted text: {input_text}")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
input_text = "Voice cloning demonstration using Chatterbox AI technology."
|
| 49 |
+
print(f"โ ๏ธ Whisper failed, using default text: {e}")
|
| 50 |
|
| 51 |
+
# Create output file
|
| 52 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
|
| 53 |
+
output_path = tmp_file.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
# Use appropriate Chatterbox model based on language
|
| 56 |
+
if language == "en":
|
| 57 |
+
# Use English Chatterbox model
|
| 58 |
+
wav = english_model.generate(
|
| 59 |
+
input_text,
|
| 60 |
+
audio_prompt_path=reference_audio,
|
| 61 |
+
exaggeration=exaggeration,
|
| 62 |
+
cfg=cfg
|
| 63 |
+
)
|
| 64 |
+
else:
|
| 65 |
+
# Use Multilingual Chatterbox model
|
| 66 |
+
wav = multilingual_model.generate(
|
| 67 |
+
input_text,
|
| 68 |
+
audio_prompt_path=reference_audio,
|
| 69 |
+
language_id=language,
|
| 70 |
+
exaggeration=exaggeration,
|
| 71 |
+
cfg=cfg
|
| 72 |
+
)
|
| 73 |
|
| 74 |
+
# Save generated audio
|
| 75 |
+
ta.save(output_path, wav, english_model.sr if language == "en" else multilingual_model.sr)
|
| 76 |
|
| 77 |
+
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
|
| 78 |
+
return output_path, f"โ
Chatterbox Voice Cloning Complete!\n๐ต Generated: '{input_text[:100]}...'\n๐๏ธ Settings: Exaggeration={exaggeration}, CFG={cfg}"
|
| 79 |
+
else:
|
| 80 |
+
return None, "โ Failed to generate cloned audio!"
|
| 81 |
+
|
| 82 |
except Exception as e:
|
| 83 |
+
return None, f"โ Chatterbox Error: {str(e)}"
|
| 84 |
|
| 85 |
+
def chatterbox_text_to_speech(reference_audio, input_text, language="en", exaggeration=0.5, cfg=0.5, speed=1.0):
|
| 86 |
"""
|
| 87 |
+
Real Text-to-Speech with voice cloning using Chatterbox
|
| 88 |
"""
|
| 89 |
try:
|
| 90 |
if not reference_audio:
|
|
|
|
| 93 |
if not input_text or not input_text.strip():
|
| 94 |
return None, "โ Please enter text to convert!"
|
| 95 |
|
| 96 |
+
if not models_loaded:
|
| 97 |
+
return None, "โ Chatterbox models not loaded!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
+
print(f"๐ค Generating speech with Chatterbox...")
|
| 100 |
+
print(f"๐ Text: {input_text}")
|
| 101 |
+
print(f"๐ฃ๏ธ Language: {language}")
|
| 102 |
+
print(f"๐๏ธ Exaggeration: {exaggeration}, CFG: {cfg}")
|
| 103 |
|
| 104 |
+
# Create output file
|
| 105 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
|
| 106 |
+
output_path = tmp_file.name
|
| 107 |
|
| 108 |
+
# Use appropriate Chatterbox model
|
| 109 |
+
if language == "en":
|
| 110 |
+
# English Chatterbox model
|
| 111 |
+
wav = english_model.generate(
|
| 112 |
+
input_text,
|
| 113 |
+
audio_prompt_path=reference_audio,
|
| 114 |
+
exaggeration=exaggeration,
|
| 115 |
+
cfg=cfg
|
| 116 |
+
)
|
| 117 |
+
else:
|
| 118 |
+
# Multilingual Chatterbox model
|
| 119 |
+
wav = multilingual_model.generate(
|
| 120 |
+
input_text,
|
| 121 |
+
audio_prompt_path=reference_audio,
|
| 122 |
+
language_id=language,
|
| 123 |
+
exaggeration=exaggeration,
|
| 124 |
+
cfg=cfg
|
| 125 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
# Save generated audio
|
| 128 |
+
ta.save(output_path, wav, english_model.sr if language == "en" else multilingual_model.sr)
|
|
|
|
| 129 |
|
| 130 |
+
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
|
| 131 |
+
return output_path, f"โ
Chatterbox TTS Complete!\n๐ Generated: '{input_text[:100]}...'\n๐๏ธ Settings: Exaggeration={exaggeration}, CFG={cfg}"
|
| 132 |
+
else:
|
| 133 |
+
return None, "โ Failed to generate speech!"
|
| 134 |
+
|
| 135 |
+
except Exception as e:
|
| 136 |
+
return None, f"โ Chatterbox Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
+
# Create Gradio interface
|
| 139 |
+
def create_chatterbox_interface():
|
| 140 |
with gr.Blocks(
|
| 141 |
+
title="๐ญ Chatterbox Voice Cloning Studio",
|
| 142 |
+
theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink")
|
| 143 |
) as demo:
|
| 144 |
|
| 145 |
# Header
|
| 146 |
gr.HTML("""
|
| 147 |
<div style="text-align: center; padding: 20px;">
|
| 148 |
+
<h1 style="color: #8B5CF6; margin-bottom: 10px;">๐ญ Chatterbox Voice Cloning Studio</h1>
|
| 149 |
+
<p style="color: #666; font-size: 18px;">Powered by Resemble AI's Chatterbox - The Model We Discussed!</p>
|
| 150 |
+
<p style="color: #888; font-size: 14px;">โจ Emotion control โข 23+ languages โข Zero-shot cloning โข MIT licensed</p>
|
| 151 |
+
</div>
|
| 152 |
+
""")
|
| 153 |
+
|
| 154 |
+
# Model Status
|
| 155 |
+
gr.HTML(f"""
|
| 156 |
+
<div style="text-align: center; padding: 10px; background: {'#d4edda' if models_loaded else '#f8d7da'}; border-radius: 10px; margin-bottom: 20px;">
|
| 157 |
+
<strong>๐ค Chatterbox Status:</strong> {'โ
Models Loaded Successfully!' if models_loaded else 'โ Models Not Loaded'}
|
| 158 |
</div>
|
| 159 |
""")
|
| 160 |
|
| 161 |
with gr.Row():
|
| 162 |
with gr.Column(scale=1):
|
| 163 |
# Reference Voice Section
|
| 164 |
+
gr.HTML("<h3 style='color: #8B5CF6;'>๐ค Reference Voice (5+ seconds)</h3>")
|
| 165 |
reference_audio = gr.Audio(
|
| 166 |
+
label="Upload Reference Audio",
|
| 167 |
type="filepath",
|
| 168 |
sources=["upload", "microphone"]
|
| 169 |
)
|
| 170 |
+
gr.HTML("<p style='color: #666; font-size: 14px;'>๐ Upload clear speech from the voice you want to clone</p>")
|
| 171 |
|
| 172 |
+
with gr.Row():
|
|
|
|
| 173 |
with gr.Column(scale=1):
|
| 174 |
+
# Voice-to-Voice Cloning
|
| 175 |
+
gr.HTML("<h3 style='color: #8B5CF6;'>๐ต Voice-to-Voice Cloning</h3>")
|
| 176 |
|
| 177 |
+
input_audio = gr.Audio(
|
| 178 |
+
label="Input Audio to Transform",
|
| 179 |
+
type="filepath",
|
| 180 |
+
sources=["upload", "microphone"]
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
with gr.Row():
|
| 184 |
+
voice_language = gr.Dropdown(
|
| 185 |
+
choices=[
|
| 186 |
+
("๐บ๐ธ English", "en"),
|
| 187 |
+
("๐ช๐ธ Spanish", "es"),
|
| 188 |
+
("๐ซ๐ท French", "fr"),
|
| 189 |
+
("๐ฉ๐ช German", "de"),
|
| 190 |
+
("๐ฎ๐น Italian", "it"),
|
| 191 |
+
("๐ง๐ท Portuguese", "pt"),
|
| 192 |
+
("๐จ๐ณ Chinese", "zh"),
|
| 193 |
+
("๐ฏ๐ต Japanese", "ja"),
|
| 194 |
+
("๐ฐ๐ท Korean", "ko"),
|
| 195 |
+
("๐ท๐บ Russian", "ru"),
|
| 196 |
+
("๐ธ๐ฆ Arabic", "ar"),
|
| 197 |
+
("๐ฎ๐ณ Hindi", "hi"),
|
| 198 |
+
("๐ณ๐ฑ Dutch", "nl"),
|
| 199 |
+
("๐ต๐ฑ Polish", "pl"),
|
| 200 |
+
("๐น๐ท Turkish", "tr"),
|
| 201 |
+
("๐ธ๐ช Swedish", "sv"),
|
| 202 |
+
("๐ซ๐ฎ Finnish", "fi"),
|
| 203 |
+
("๐ฉ๐ฐ Danish", "da"),
|
| 204 |
+
("๐ณ๐ด Norwegian", "no"),
|
| 205 |
+
("๐ฌ๐ท Greek", "el"),
|
| 206 |
+
("๐ฎ๐ฑ Hebrew", "he"),
|
| 207 |
+
("๐ฒ๐พ Malay", "ms"),
|
| 208 |
+
("๐ฐ๐ช Swahili", "sw")
|
| 209 |
+
],
|
| 210 |
+
value="en",
|
| 211 |
+
label="Language"
|
| 212 |
+
)
|
| 213 |
|
| 214 |
+
voice_exaggeration = gr.Slider(
|
| 215 |
+
minimum=0.0,
|
| 216 |
+
maximum=1.0,
|
| 217 |
+
step=0.1,
|
| 218 |
+
value=0.5,
|
| 219 |
+
label="๐ญ Emotion Exaggeration"
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
voice_cfg = gr.Slider(
|
| 223 |
+
minimum=0.0,
|
| 224 |
+
maximum=1.0,
|
| 225 |
+
step=0.1,
|
| 226 |
+
value=0.5,
|
| 227 |
+
label="๐๏ธ CFG Scale"
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
voice_clone_btn = gr.Button(
|
| 231 |
+
"๐ค Clone Voice with Chatterbox",
|
| 232 |
+
variant="primary",
|
| 233 |
+
size="lg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
)
|
| 235 |
|
| 236 |
+
with gr.Column(scale=1):
|
| 237 |
+
# Text-to-Speech
|
| 238 |
+
gr.HTML("<h3 style='color: #8B5CF6;'>๐ Text-to-Speech Cloning</h3>")
|
| 239 |
+
|
| 240 |
+
text_input = gr.Textbox(
|
| 241 |
+
label="Text to Convert to Speech",
|
| 242 |
+
placeholder="Enter text to speak in the cloned voice...",
|
| 243 |
+
lines=4,
|
| 244 |
+
max_lines=8
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
with gr.Row():
|
| 248 |
+
text_language = gr.Dropdown(
|
| 249 |
+
choices=[
|
| 250 |
+
("๐บ๐ธ English", "en"),
|
| 251 |
+
("๐ช๐ธ Spanish", "es"),
|
| 252 |
+
("๐ซ๐ท French", "fr"),
|
| 253 |
+
("๐ฉ๐ช German", "de"),
|
| 254 |
+
("๐ฎ๐น Italian", "it"),
|
| 255 |
+
("๐ง๏ฟฝ๏ฟฝ Portuguese", "pt"),
|
| 256 |
+
("๐จ๐ณ Chinese", "zh"),
|
| 257 |
+
("๐ฏ๐ต Japanese", "ja")
|
| 258 |
+
],
|
| 259 |
+
value="en",
|
| 260 |
+
label="Language"
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
text_exaggeration = gr.Slider(
|
| 264 |
+
minimum=0.0,
|
| 265 |
+
maximum=1.0,
|
| 266 |
+
step=0.1,
|
| 267 |
+
value=0.5,
|
| 268 |
+
label="๐ญ Emotion Exaggeration"
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
text_cfg = gr.Slider(
|
| 272 |
+
minimum=0.0,
|
| 273 |
+
maximum=1.0,
|
| 274 |
+
step=0.1,
|
| 275 |
+
value=0.5,
|
| 276 |
+
label="๐๏ธ CFG Scale"
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
text_clone_btn = gr.Button(
|
| 280 |
+
"๐ Generate Speech with Chatterbox",
|
| 281 |
+
variant="secondary",
|
| 282 |
+
size="lg"
|
| 283 |
)
|
| 284 |
|
| 285 |
+
# Output Section
|
| 286 |
+
gr.HTML("<h3 style='color: #8B5CF6;'>๐ต Chatterbox Generated Audio</h3>")
|
| 287 |
+
with gr.Row():
|
| 288 |
+
audio_output = gr.Audio(
|
| 289 |
+
label="Cloned Voice Result",
|
| 290 |
+
type="filepath"
|
| 291 |
+
)
|
| 292 |
+
status_output = gr.Textbox(
|
| 293 |
+
label="Processing Status",
|
| 294 |
+
lines=5,
|
| 295 |
+
interactive=False
|
|
|
|
|
|
|
| 296 |
)
|
| 297 |
|
| 298 |
+
# Chatterbox Features
|
| 299 |
+
with gr.Accordion("๐ Chatterbox Features", open=False):
|
| 300 |
gr.Markdown("""
|
| 301 |
+
### Why Chatterbox is Special
|
| 302 |
+
|
| 303 |
+
**๐ญ Emotion Exaggeration Control**
|
| 304 |
+
- First open source model with emotion control
|
| 305 |
+
- Adjust from monotone (0.0) to highly expressive (1.0)
|
| 306 |
+
- Perfect for creative content, games, and dramatic speech
|
| 307 |
+
|
| 308 |
+
**๐ Multilingual Support (23 Languages)**
|
| 309 |
+
- Arabic, Chinese, Danish, Dutch, English, Finnish, French
|
| 310 |
+
- German, Greek, Hebrew, Hindi, Italian, Japanese, Korean
|
| 311 |
+
- Malay, Norwegian, Polish, Portuguese, Russian, Spanish
|
| 312 |
+
- Swedish, Swahili, Turkish
|
| 313 |
|
| 314 |
+
**โก Technical Advantages**
|
| 315 |
+
- 0.5B parameter Llama backbone
|
| 316 |
+
- Zero-shot voice cloning with 5+ seconds of audio
|
| 317 |
+
- Built-in neural watermarking for responsible AI
|
| 318 |
+
- MIT licensed - free for commercial use
|
| 319 |
+
- Consistently outperforms ElevenLabs in evaluations
|
| 320 |
|
| 321 |
+
**๐๏ธ Control Parameters**
|
| 322 |
+
- **Exaggeration**: Controls emotional intensity (0.0 = monotone, 1.0 = very expressive)
|
| 323 |
+
- **CFG Scale**: Controls adherence to reference voice (lower = more creative, higher = more accurate)
|
|
|
|
|
|
|
| 324 |
""")
|
| 325 |
|
| 326 |
+
# Event Handlers
|
| 327 |
+
voice_clone_btn.click(
|
| 328 |
+
fn=chatterbox_voice_clone,
|
| 329 |
+
inputs=[reference_audio, input_audio, voice_language, voice_exaggeration, voice_cfg],
|
| 330 |
outputs=[audio_output, status_output],
|
| 331 |
show_progress=True
|
| 332 |
)
|
| 333 |
|
| 334 |
text_clone_btn.click(
|
| 335 |
+
fn=chatterbox_text_to_speech,
|
| 336 |
+
inputs=[reference_audio, text_input, text_language, text_exaggeration, text_cfg],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
outputs=[audio_output, status_output],
|
| 338 |
show_progress=True
|
| 339 |
)
|
| 340 |
|
| 341 |
return demo
|
| 342 |
|
|
|
|
| 343 |
if __name__ == "__main__":
|
| 344 |
+
demo = create_chatterbox_interface()
|
| 345 |
demo.launch(
|
| 346 |
server_name="0.0.0.0",
|
| 347 |
server_port=7860,
|