Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,82 +4,113 @@ import torchaudio
|
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
import logging
|
| 7 |
-
import traceback
|
| 8 |
|
| 9 |
# Setup logging
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
-
# Device detection
|
| 14 |
DEVICE = "cpu"
|
| 15 |
if torch.cuda.is_available():
|
| 16 |
DEVICE = "cuda"
|
| 17 |
logger.info("๐ Running on CUDA GPU")
|
| 18 |
-
elif torch.backends.mps.is_available():
|
| 19 |
-
DEVICE = "cpu" # Force CPU for MPS compatibility
|
| 20 |
-
logger.info("๐ Apple Silicon detected - using CPU mode for Chatterbox-TTS compatibility")
|
| 21 |
else:
|
| 22 |
logger.info("๐ Running on CPU")
|
| 23 |
|
| 24 |
print(f"๐ Running on device: {DEVICE}")
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
def
|
| 30 |
-
"""
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
return original_torch_load(f, map_location=map_location, **kwargs)
|
| 35 |
-
|
| 36 |
-
# Apply the patch
|
| 37 |
-
torch.load = patched_torch_load
|
| 38 |
-
|
| 39 |
-
# Global model variable
|
| 40 |
-
MODEL = None
|
| 41 |
-
|
| 42 |
-
def get_or_load_model():
|
| 43 |
-
"""Loads the ChatterboxTTS model with proper error handling"""
|
| 44 |
-
global MODEL
|
| 45 |
-
if MODEL is None:
|
| 46 |
-
print("๐ Model not loaded, initializing...")
|
| 47 |
try:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
from chatterbox import ChatterboxTTS
|
| 51 |
-
MODEL = ChatterboxTTS.from_pretrained(device=DEVICE)
|
| 52 |
-
print("โ
Loaded with 'from chatterbox import ChatterboxTTS'")
|
| 53 |
-
except ImportError:
|
| 54 |
-
try:
|
| 55 |
-
from chatterbox.tts import ChatterboxTTS
|
| 56 |
-
MODEL = ChatterboxTTS.from_pretrained(device=DEVICE)
|
| 57 |
-
print("โ
Loaded with 'from chatterbox.tts import ChatterboxTTS'")
|
| 58 |
-
except ImportError:
|
| 59 |
-
try:
|
| 60 |
-
from chatterbox.src.chatterbox.tts import ChatterboxTTS
|
| 61 |
-
MODEL = ChatterboxTTS.from_pretrained(device=DEVICE)
|
| 62 |
-
print("โ
Loaded with 'from chatterbox.src.chatterbox.tts import ChatterboxTTS'")
|
| 63 |
-
except ImportError as e:
|
| 64 |
-
print(f"โ All Chatterbox import paths failed: {e}")
|
| 65 |
-
return None
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
print(
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
except Exception as e:
|
| 75 |
-
print(f"โ Error loading Chatterbox
|
| 76 |
-
|
| 77 |
-
return None
|
| 78 |
|
| 79 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
def
|
| 82 |
-
"""
|
|
|
|
|
|
|
| 83 |
try:
|
| 84 |
if not reference_audio:
|
| 85 |
return None, "โ Please upload reference audio!"
|
|
@@ -87,10 +118,8 @@ def simple_voice_clone(reference_audio, input_text):
|
|
| 87 |
if not input_text or not input_text.strip():
|
| 88 |
return None, "โ Please enter text to convert!"
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
if model is None:
|
| 93 |
-
return None, "โ Chatterbox model failed to load! Check logs for details."
|
| 94 |
|
| 95 |
print(f"๐ค Generating speech with Chatterbox...")
|
| 96 |
print(f"๐ Text: {input_text[:100]}...")
|
|
@@ -99,61 +128,60 @@ def simple_voice_clone(reference_audio, input_text):
|
|
| 99 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
|
| 100 |
output_path = tmp_file.name
|
| 101 |
|
| 102 |
-
#
|
| 103 |
-
|
|
|
|
| 104 |
wav = model.generate(
|
| 105 |
input_text,
|
| 106 |
audio_prompt_path=reference_audio,
|
| 107 |
-
exaggeration=
|
| 108 |
-
cfg=
|
| 109 |
)
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
except Exception as e:
|
| 124 |
-
|
| 125 |
-
return None, f"โ Error: {str(e)}"
|
| 126 |
|
| 127 |
-
#
|
| 128 |
try:
|
| 129 |
-
|
| 130 |
-
if
|
| 131 |
-
|
| 132 |
-
startup_message = "โ
Chatterbox Models Loaded Successfully!"
|
| 133 |
-
else:
|
| 134 |
-
models_loaded = False
|
| 135 |
-
startup_message = "โ Failed to Load Chatterbox Models - Check Dependencies"
|
| 136 |
-
except Exception as startup_error:
|
| 137 |
models_loaded = False
|
| 138 |
-
startup_message = f"โ Startup Error: {str(
|
| 139 |
-
print(f"CRITICAL: {startup_message}")
|
| 140 |
|
| 141 |
# Create Gradio interface
|
| 142 |
with gr.Blocks(
|
| 143 |
-
title="๐ญ Chatterbox Voice Cloning Studio",
|
| 144 |
theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink")
|
| 145 |
) as demo:
|
| 146 |
|
| 147 |
# Header
|
| 148 |
gr.HTML("""
|
| 149 |
<div style="text-align: center; padding: 20px;">
|
| 150 |
-
<h1 style="color: #8B5CF6; margin-bottom: 10px;">๐ญ Chatterbox Voice Cloning Studio</h1>
|
| 151 |
-
<p style="color: #666; font-size: 18px;">
|
| 152 |
-
<p style="color: #888; font-size: 14px;">
|
| 153 |
</div>
|
| 154 |
""")
|
| 155 |
|
| 156 |
-
# Model Status
|
| 157 |
status_color = "#d4edda" if models_loaded else "#f8d7da"
|
| 158 |
gr.HTML(f"""
|
| 159 |
<div style="text-align: center; padding: 15px; background: {status_color}; border-radius: 10px; margin-bottom: 20px;">
|
|
@@ -163,74 +191,181 @@ with gr.Blocks(
|
|
| 163 |
|
| 164 |
with gr.Row():
|
| 165 |
with gr.Column():
|
| 166 |
-
# Reference Voice
|
| 167 |
-
gr.HTML("<h3 style='color: #8B5CF6;'>๐ค Reference Voice</h3>")
|
| 168 |
reference_audio = gr.Audio(
|
| 169 |
label="Upload Reference Audio (5+ seconds)",
|
| 170 |
type="filepath",
|
| 171 |
sources=["upload", "microphone"]
|
| 172 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
gr.HTML("<
|
| 193 |
-
audio_output = gr.Audio(
|
| 194 |
-
label="Cloned Voice Result",
|
| 195 |
-
type="filepath"
|
| 196 |
-
)
|
| 197 |
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
-
#
|
| 205 |
-
with gr.Accordion("
|
| 206 |
gr.Markdown("""
|
| 207 |
-
###
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
-
|
| 222 |
-
-
|
| 223 |
-
|
| 224 |
-
**๐ค Audio Issues:**
|
| 225 |
-
- Use clear, high-quality reference audio (5+ seconds)
|
| 226 |
-
- Supported formats: WAV, MP3, FLAC, M4A
|
| 227 |
-
- Avoid background noise in reference audio
|
| 228 |
""")
|
| 229 |
|
| 230 |
-
# Event
|
| 231 |
-
|
| 232 |
-
fn=
|
| 233 |
-
inputs=[reference_audio,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
outputs=[audio_output, status_output],
|
| 235 |
show_progress=True
|
| 236 |
)
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
import logging
|
|
|
|
| 7 |
|
| 8 |
# Setup logging
|
| 9 |
logging.basicConfig(level=logging.INFO)
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
+
# Device detection
|
| 13 |
DEVICE = "cpu"
|
| 14 |
if torch.cuda.is_available():
|
| 15 |
DEVICE = "cuda"
|
| 16 |
logger.info("๐ Running on CUDA GPU")
|
|
|
|
|
|
|
|
|
|
| 17 |
else:
|
| 18 |
logger.info("๐ Running on CPU")
|
| 19 |
|
| 20 |
print(f"๐ Running on device: {DEVICE}")
|
| 21 |
|
| 22 |
+
# Global models
|
| 23 |
+
ENGLISH_MODEL = None
|
| 24 |
+
MULTILINGUAL_MODEL = None
|
| 25 |
|
| 26 |
+
def load_chatterbox_models():
|
| 27 |
+
"""Load Chatterbox models with proper error handling"""
|
| 28 |
+
global ENGLISH_MODEL, MULTILINGUAL_MODEL
|
| 29 |
+
|
| 30 |
+
if ENGLISH_MODEL is None or MULTILINGUAL_MODEL is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
try:
|
| 32 |
+
from chatterbox.tts import ChatterboxTTS
|
| 33 |
+
from chatterbox.mtl_tts import ChatterboxMultilingualTTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
print("๐ Loading Chatterbox English model...")
|
| 36 |
+
ENGLISH_MODEL = ChatterboxTTS.from_pretrained(device=DEVICE)
|
| 37 |
+
print("โ
English model loaded!")
|
| 38 |
|
| 39 |
+
print("๐ Loading Chatterbox Multilingual model...")
|
| 40 |
+
MULTILINGUAL_MODEL = ChatterboxMultilingualTTS.from_pretrained(device=DEVICE)
|
| 41 |
+
print("โ
Multilingual model loaded!")
|
| 42 |
+
|
| 43 |
+
return True
|
| 44 |
|
| 45 |
except Exception as e:
|
| 46 |
+
print(f"โ Error loading Chatterbox models: {e}")
|
| 47 |
+
return False
|
|
|
|
| 48 |
|
| 49 |
+
return True
|
| 50 |
+
|
| 51 |
+
def voice_to_voice_cloning(reference_audio, input_audio, language="en", exaggeration=0.5, cfg=0.5):
|
| 52 |
+
"""
|
| 53 |
+
Voice-to-Voice Cloning: Transform input audio using reference voice
|
| 54 |
+
"""
|
| 55 |
+
try:
|
| 56 |
+
if not reference_audio:
|
| 57 |
+
return None, "โ Please upload reference audio (voice to clone)!"
|
| 58 |
+
|
| 59 |
+
if not input_audio:
|
| 60 |
+
return None, "โ Please upload input audio (content to transform)!"
|
| 61 |
+
|
| 62 |
+
if not load_chatterbox_models():
|
| 63 |
+
return None, "โ Chatterbox models failed to load!"
|
| 64 |
+
|
| 65 |
+
# Extract text from input audio using Whisper (for content)
|
| 66 |
+
try:
|
| 67 |
+
import whisper
|
| 68 |
+
whisper_model = whisper.load_model("base")
|
| 69 |
+
result = whisper_model.transcribe(input_audio)
|
| 70 |
+
extracted_text = result["text"]
|
| 71 |
+
print(f"๐ Extracted text from input audio: {extracted_text}")
|
| 72 |
+
except Exception as e:
|
| 73 |
+
print(f"โ ๏ธ Whisper transcription failed: {e}")
|
| 74 |
+
extracted_text = "Voice cloning demonstration using the uploaded audio content."
|
| 75 |
+
|
| 76 |
+
# Create output file
|
| 77 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
|
| 78 |
+
output_path = tmp_file.name
|
| 79 |
+
|
| 80 |
+
# Use appropriate model based on language
|
| 81 |
+
if language == "en":
|
| 82 |
+
model = ENGLISH_MODEL
|
| 83 |
+
wav = model.generate(
|
| 84 |
+
extracted_text,
|
| 85 |
+
audio_prompt_path=reference_audio,
|
| 86 |
+
exaggeration=exaggeration,
|
| 87 |
+
cfg=cfg
|
| 88 |
+
)
|
| 89 |
+
else:
|
| 90 |
+
model = MULTILINGUAL_MODEL
|
| 91 |
+
wav = model.generate(
|
| 92 |
+
extracted_text,
|
| 93 |
+
audio_prompt_path=reference_audio,
|
| 94 |
+
language_id=language,
|
| 95 |
+
exaggeration=exaggeration,
|
| 96 |
+
cfg=cfg
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# Save generated audio
|
| 100 |
+
torchaudio.save(output_path, wav.cpu(), model.sr)
|
| 101 |
+
|
| 102 |
+
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
|
| 103 |
+
return output_path, f"โ
Voice-to-Voice Cloning Complete!\n๐ค Reference voice applied to: '{extracted_text[:100]}...'\n๐๏ธ Settings: Exaggeration={exaggeration}, CFG={cfg}"
|
| 104 |
+
else:
|
| 105 |
+
return None, "โ Generated audio file is empty!"
|
| 106 |
+
|
| 107 |
+
except Exception as e:
|
| 108 |
+
return None, f"โ Voice-to-Voice cloning error: {str(e)}"
|
| 109 |
|
| 110 |
+
def text_to_voice_cloning(reference_audio, input_text, language="en", exaggeration=0.5, cfg=0.5, speed=1.0):
|
| 111 |
+
"""
|
| 112 |
+
Text-to-Voice Cloning: Generate speech from text using reference voice
|
| 113 |
+
"""
|
| 114 |
try:
|
| 115 |
if not reference_audio:
|
| 116 |
return None, "โ Please upload reference audio!"
|
|
|
|
| 118 |
if not input_text or not input_text.strip():
|
| 119 |
return None, "โ Please enter text to convert!"
|
| 120 |
|
| 121 |
+
if not load_chatterbox_models():
|
| 122 |
+
return None, "โ Chatterbox models failed to load!"
|
|
|
|
|
|
|
| 123 |
|
| 124 |
print(f"๐ค Generating speech with Chatterbox...")
|
| 125 |
print(f"๐ Text: {input_text[:100]}...")
|
|
|
|
| 128 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
|
| 129 |
output_path = tmp_file.name
|
| 130 |
|
| 131 |
+
# Use appropriate model based on language
|
| 132 |
+
if language == "en":
|
| 133 |
+
model = ENGLISH_MODEL
|
| 134 |
wav = model.generate(
|
| 135 |
input_text,
|
| 136 |
audio_prompt_path=reference_audio,
|
| 137 |
+
exaggeration=exaggeration,
|
| 138 |
+
cfg=cfg
|
| 139 |
)
|
| 140 |
+
else:
|
| 141 |
+
model = MULTILINGUAL_MODEL
|
| 142 |
+
wav = model.generate(
|
| 143 |
+
input_text,
|
| 144 |
+
audio_prompt_path=reference_audio,
|
| 145 |
+
language_id=language,
|
| 146 |
+
exaggeration=exaggeration,
|
| 147 |
+
cfg=cfg
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
# Save generated audio
|
| 151 |
+
torchaudio.save(output_path, wav.cpu(), model.sr)
|
| 152 |
+
|
| 153 |
+
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
|
| 154 |
+
return output_path, f"โ
Text-to-Voice Cloning Complete!\n๐ Generated: '{input_text[:100]}...'\n๐๏ธ Settings: Exaggeration={exaggeration}, CFG={cfg}"
|
| 155 |
+
else:
|
| 156 |
+
return None, "โ Generated audio file is empty!"
|
| 157 |
|
| 158 |
except Exception as e:
|
| 159 |
+
return None, f"โ Text-to-Voice cloning error: {str(e)}"
|
|
|
|
| 160 |
|
| 161 |
+
# Try to load models at startup
|
| 162 |
try:
|
| 163 |
+
models_loaded = load_chatterbox_models()
|
| 164 |
+
startup_message = "โ
Chatterbox Models Loaded Successfully!" if models_loaded else "โ Failed to Load Chatterbox Models"
|
| 165 |
+
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
models_loaded = False
|
| 167 |
+
startup_message = f"โ Startup Error: {str(e)}"
|
|
|
|
| 168 |
|
| 169 |
# Create Gradio interface
|
| 170 |
with gr.Blocks(
|
| 171 |
+
title="๐ญ Complete Chatterbox Voice Cloning Studio",
|
| 172 |
theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink")
|
| 173 |
) as demo:
|
| 174 |
|
| 175 |
# Header
|
| 176 |
gr.HTML("""
|
| 177 |
<div style="text-align: center; padding: 20px;">
|
| 178 |
+
<h1 style="color: #8B5CF6; margin-bottom: 10px;">๐ญ Complete Chatterbox Voice Cloning Studio</h1>
|
| 179 |
+
<p style="color: #666; font-size: 18px;">Voice-to-Voice & Text-to-Speech with Emotion Control</p>
|
| 180 |
+
<p style="color: #888; font-size: 14px;">Powered by Resemble AI's Chatterbox - The Model We Discussed!</p>
|
| 181 |
</div>
|
| 182 |
""")
|
| 183 |
|
| 184 |
+
# Model Status
|
| 185 |
status_color = "#d4edda" if models_loaded else "#f8d7da"
|
| 186 |
gr.HTML(f"""
|
| 187 |
<div style="text-align: center; padding: 15px; background: {status_color}; border-radius: 10px; margin-bottom: 20px;">
|
|
|
|
| 191 |
|
| 192 |
with gr.Row():
|
| 193 |
with gr.Column():
|
| 194 |
+
# Reference Voice Section
|
| 195 |
+
gr.HTML("<h3 style='color: #8B5CF6;'>๐ค Reference Voice (Voice to Clone)</h3>")
|
| 196 |
reference_audio = gr.Audio(
|
| 197 |
label="Upload Reference Audio (5+ seconds)",
|
| 198 |
type="filepath",
|
| 199 |
sources=["upload", "microphone"]
|
| 200 |
)
|
| 201 |
+
gr.HTML("<p style='color: #666; font-size: 14px;'>๐ This is the voice that will be cloned and applied to your content</p>")
|
| 202 |
+
|
| 203 |
+
# Tabs for different input methods
|
| 204 |
+
with gr.Tabs():
|
| 205 |
+
# Tab 1: Voice-to-Voice Cloning
|
| 206 |
+
with gr.TabItem("๐ต Voice-to-Voice Cloning"):
|
| 207 |
+
gr.HTML("<p style='margin-bottom: 15px;'>Upload audio content and transform it using the reference voice</p>")
|
| 208 |
|
| 209 |
+
with gr.Row():
|
| 210 |
+
with gr.Column():
|
| 211 |
+
input_audio = gr.Audio(
|
| 212 |
+
label="Input Audio (Content to Transform)",
|
| 213 |
+
type="filepath",
|
| 214 |
+
sources=["upload", "microphone"]
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
with gr.Row():
|
| 218 |
+
voice_language = gr.Dropdown(
|
| 219 |
+
choices=[
|
| 220 |
+
("๐บ๐ธ English", "en"),
|
| 221 |
+
("๐ช๐ธ Spanish", "es"),
|
| 222 |
+
("๐ซ๐ท French", "fr"),
|
| 223 |
+
("๐ฉ๐ช German", "de"),
|
| 224 |
+
("๐ฎ๐น Italian", "it"),
|
| 225 |
+
("๐ง๐ท Portuguese", "pt"),
|
| 226 |
+
("๐จ๐ณ Chinese", "zh"),
|
| 227 |
+
("๐ฏ๐ต Japanese", "ja"),
|
| 228 |
+
("๐ฐ๐ท Korean", "ko"),
|
| 229 |
+
("๐ท๐บ Russian", "ru")
|
| 230 |
+
],
|
| 231 |
+
value="en",
|
| 232 |
+
label="Language"
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
voice_exaggeration = gr.Slider(
|
| 236 |
+
minimum=0.0,
|
| 237 |
+
maximum=2.0,
|
| 238 |
+
step=0.1,
|
| 239 |
+
value=0.5,
|
| 240 |
+
label="๐ญ Emotion Exaggeration"
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
voice_cfg = gr.Slider(
|
| 244 |
+
minimum=0.2,
|
| 245 |
+
maximum=1.0,
|
| 246 |
+
step=0.1,
|
| 247 |
+
value=0.5,
|
| 248 |
+
label="๐๏ธ CFG Scale"
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
voice_clone_btn = gr.Button(
|
| 252 |
+
"๐ค Transform Voice (Audio โ Cloned Audio)",
|
| 253 |
+
variant="primary",
|
| 254 |
+
size="lg"
|
| 255 |
+
)
|
| 256 |
|
| 257 |
+
# Tab 2: Text-to-Voice Cloning
|
| 258 |
+
with gr.TabItem("๐ Text-to-Speech Cloning"):
|
| 259 |
+
gr.HTML("<p style='margin-bottom: 15px;'>Enter text and generate speech using the reference voice</p>")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
+
with gr.Row():
|
| 262 |
+
with gr.Column():
|
| 263 |
+
text_input = gr.Textbox(
|
| 264 |
+
label="Text to Convert to Speech",
|
| 265 |
+
placeholder="Enter the text you want to speak in the cloned voice...",
|
| 266 |
+
lines=4,
|
| 267 |
+
max_lines=8
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
with gr.Row():
|
| 271 |
+
text_language = gr.Dropdown(
|
| 272 |
+
choices=[
|
| 273 |
+
("๐บ๐ธ English", "en"),
|
| 274 |
+
("๐ช๐ธ Spanish", "es"),
|
| 275 |
+
("๐ซ๐ท French", "fr"),
|
| 276 |
+
("๐ฉ๐ช German", "de"),
|
| 277 |
+
("๐ฎ๐น Italian", "it"),
|
| 278 |
+
("๐ง๐ท Portuguese", "pt"),
|
| 279 |
+
("๐จ๐ณ Chinese", "zh"),
|
| 280 |
+
("๐ฏ๐ต Japanese", "ja")
|
| 281 |
+
],
|
| 282 |
+
value="en",
|
| 283 |
+
label="Language"
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
text_exaggeration = gr.Slider(
|
| 287 |
+
minimum=0.0,
|
| 288 |
+
maximum=2.0,
|
| 289 |
+
step=0.1,
|
| 290 |
+
value=0.5,
|
| 291 |
+
label="๐ญ Emotion Exaggeration"
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
text_cfg = gr.Slider(
|
| 295 |
+
minimum=0.2,
|
| 296 |
+
maximum=1.0,
|
| 297 |
+
step=0.1,
|
| 298 |
+
value=0.5,
|
| 299 |
+
label="๐๏ธ CFG Scale"
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
text_clone_btn = gr.Button(
|
| 303 |
+
"๐ Generate Speech (Text โ Cloned Audio)",
|
| 304 |
+
variant="secondary",
|
| 305 |
+
size="lg"
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
# Output Section
|
| 309 |
+
gr.HTML("<h3 style='color: #8B5CF6;'>๐ต Generated Audio Output</h3>")
|
| 310 |
+
with gr.Row():
|
| 311 |
+
audio_output = gr.Audio(
|
| 312 |
+
label="Cloned Voice Result",
|
| 313 |
+
type="filepath"
|
| 314 |
+
)
|
| 315 |
+
status_output = gr.Textbox(
|
| 316 |
+
label="Processing Status & Details",
|
| 317 |
+
lines=6,
|
| 318 |
+
interactive=False
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
# Examples Section
|
| 322 |
+
with gr.Accordion("๐ก Example Texts for Testing", open=False):
|
| 323 |
+
examples = [
|
| 324 |
+
"Hello, this is a demonstration of real voice cloning technology using Chatterbox.",
|
| 325 |
+
"The weather is beautiful today, perfect for a walk in the park with friends.",
|
| 326 |
+
"Artificial intelligence is revolutionizing how we create and interact with digital content.",
|
| 327 |
+
"This advanced voice cloning system can generate natural speech in multiple languages."
|
| 328 |
+
]
|
| 329 |
+
|
| 330 |
+
gr.Examples(
|
| 331 |
+
examples=examples,
|
| 332 |
+
inputs=text_input,
|
| 333 |
+
label="Click to try these example texts:"
|
| 334 |
+
)
|
| 335 |
|
| 336 |
+
# How It Works Section
|
| 337 |
+
with gr.Accordion("๐ How Voice Cloning Works", open=False):
|
| 338 |
gr.Markdown("""
|
| 339 |
+
### Voice-to-Voice Cloning Process
|
| 340 |
+
1. **๐ค Upload Reference Voice**: The voice you want to clone (5+ seconds)
|
| 341 |
+
2. **๐ฅ Upload Input Audio**: Audio content you want to transform
|
| 342 |
+
3. **๐ง Content Extraction**: AI extracts speech content from input audio
|
| 343 |
+
4. **๐ญ Voice Application**: Reference voice characteristics applied to content
|
| 344 |
+
5. **๐ต Generate Output**: New audio with original content in cloned voice
|
| 345 |
+
|
| 346 |
+
### Text-to-Speech Process
|
| 347 |
+
1. **๐ค Upload Reference Voice**: The voice you want to clone
|
| 348 |
+
2. **๐ Enter Text**: Type the content to convert to speech
|
| 349 |
+
3. **๐๏ธ Adjust Controls**: Set emotion and speech parameters
|
| 350 |
+
4. **๐ต Generate Speech**: Create natural speech in the cloned voice
|
| 351 |
+
|
| 352 |
+
### Chatterbox Controls
|
| 353 |
+
- **Emotion Exaggeration**: 0.0 = monotone, 2.0 = very expressive
|
| 354 |
+
- **CFG Scale**: 0.2 = creative, 1.0 = accurate to reference
|
| 355 |
+
- **Language Support**: 23+ languages with multilingual model
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
""")
|
| 357 |
|
| 358 |
+
# Event Handlers
|
| 359 |
+
voice_clone_btn.click(
|
| 360 |
+
fn=voice_to_voice_cloning,
|
| 361 |
+
inputs=[reference_audio, input_audio, voice_language, voice_exaggeration, voice_cfg],
|
| 362 |
+
outputs=[audio_output, status_output],
|
| 363 |
+
show_progress=True
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
+
text_clone_btn.click(
|
| 367 |
+
fn=text_to_voice_cloning,
|
| 368 |
+
inputs=[reference_audio, text_input, text_language, text_exaggeration, text_cfg],
|
| 369 |
outputs=[audio_output, status_output],
|
| 370 |
show_progress=True
|
| 371 |
)
|