Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files
app.py
CHANGED
|
@@ -25,36 +25,62 @@ model = None
|
|
| 25 |
codec_model = None
|
| 26 |
|
| 27 |
def load_models_once():
|
| 28 |
-
"""Load models
|
| 29 |
global tokenizer, model, codec_model
|
| 30 |
|
| 31 |
if tokenizer is not None:
|
| 32 |
return True
|
| 33 |
|
| 34 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium") # Fallback for demo
|
| 40 |
model = AutoModelForCausalLM.from_pretrained(
|
| 41 |
-
"
|
|
|
|
| 42 |
torch_dtype=torch.float16 if device.type != 'cpu' else torch.float32,
|
| 43 |
-
|
| 44 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
return True
|
|
|
|
| 52 |
except Exception as e:
|
| 53 |
-
print(f"Error loading models: {e}")
|
|
|
|
| 54 |
return False
|
| 55 |
|
| 56 |
def generate_cloned_voice(voice_sample_path, text, progress=gr.Progress()):
|
| 57 |
-
"""Generate speech in a cloned voice
|
| 58 |
|
| 59 |
if not text or len(text.strip()) == 0:
|
| 60 |
return None, "β Please enter some text to generate!"
|
|
@@ -65,73 +91,121 @@ def generate_cloned_voice(voice_sample_path, text, progress=gr.Progress()):
|
|
| 65 |
if len(text) > 500:
|
| 66 |
return None, "β Text too long! Keep it under 500 characters for best results."
|
| 67 |
|
| 68 |
-
progress(0.1, desc="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
try:
|
| 71 |
-
|
|
|
|
| 72 |
import librosa
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
# Load and
|
| 75 |
-
|
| 76 |
-
duration = len(audio_data) / sample_rate
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if duration < 3:
|
| 79 |
return None, "β Voice sample too short! Please upload at least 3 seconds of clear speech."
|
| 80 |
|
| 81 |
if duration > 60:
|
| 82 |
return None, "β Voice sample too long! Please keep it under 60 seconds for best results."
|
| 83 |
|
| 84 |
-
progress(0.
|
| 85 |
|
| 86 |
-
#
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
import soundfile as sf
|
| 97 |
-
import tempfile
|
| 98 |
|
| 99 |
-
|
| 100 |
-
words = text.split()
|
| 101 |
-
duration = len(words) * 0.4 # ~0.4 seconds per word
|
| 102 |
-
samples = int(16000 * duration)
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
0.2 * np.sin(2 * np.pi * fundamental * 2 * t) +
|
| 112 |
-
0.1 * np.sin(2 * np.pi * fundamental * 3 * t)
|
| 113 |
-
)
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
audio = audio * (1 + variation)
|
| 118 |
|
| 119 |
-
|
| 120 |
-
envelope = np.exp(-t * 0.1) * (1 - np.exp(-t * 5))
|
| 121 |
-
audio = audio * envelope
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
|
| 125 |
-
audio = audio + noise
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
|
| 130 |
-
|
|
|
|
| 131 |
|
| 132 |
-
# Save to temporary file
|
| 133 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
|
| 134 |
-
sf.write(f.name,
|
| 135 |
|
| 136 |
progress(1.0, desc="Complete!")
|
| 137 |
|
|
@@ -139,35 +213,44 @@ def generate_cloned_voice(voice_sample_path, text, progress=gr.Progress()):
|
|
| 139 |
|
| 140 |
π Voice Sample Analysis:
|
| 141 |
β’ Duration: {duration:.1f} seconds
|
| 142 |
-
β’
|
| 143 |
-
β’ Voice characteristics
|
| 144 |
|
| 145 |
π΅ Generated Speech:
|
| 146 |
β’ Text: "{text[:50]}{'...' if len(text) > 50 else ''}"
|
| 147 |
-
β’
|
| 148 |
-
|
| 149 |
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
return f.name, status_message
|
| 153 |
|
| 154 |
except Exception as e:
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
|
| 157 |
# Create the Gradio interface
|
| 158 |
def create_interface():
|
| 159 |
|
| 160 |
with gr.Blocks(
|
| 161 |
title="π€ Voice Cloning Studio",
|
| 162 |
-
theme=gr.themes.
|
| 163 |
css="""
|
| 164 |
.gradio-container {
|
| 165 |
-
background:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
}
|
| 167 |
.status-text textarea {
|
| 168 |
color: #ffffff !important;
|
| 169 |
-
background-color: #
|
| 170 |
-
border: 1px solid #
|
| 171 |
font-weight: 500 !important;
|
| 172 |
}
|
| 173 |
.status-text label {
|
|
@@ -175,101 +258,136 @@ def create_interface():
|
|
| 175 |
font-weight: 600 !important;
|
| 176 |
}
|
| 177 |
.comparison-box {
|
| 178 |
-
background:
|
| 179 |
-
border
|
| 180 |
-
|
| 181 |
-
|
|
|
|
| 182 |
}
|
| 183 |
.comparison-box h3 {
|
| 184 |
-
color: #
|
| 185 |
-
margin-bottom:
|
|
|
|
| 186 |
}
|
| 187 |
.comparison-box ul {
|
| 188 |
color: #ffffff !important;
|
|
|
|
|
|
|
| 189 |
}
|
| 190 |
.comparison-box li {
|
| 191 |
-
color: #
|
| 192 |
-
margin:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
}
|
| 194 |
.comparison-box strong {
|
| 195 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
}
|
| 197 |
"""
|
| 198 |
) as demo:
|
| 199 |
|
| 200 |
gr.HTML("""
|
| 201 |
-
<div style="text-align: center; margin-bottom:
|
| 202 |
-
<h1
|
| 203 |
-
<p
|
| 204 |
-
|
| 205 |
</p>
|
| 206 |
</div>
|
| 207 |
""")
|
| 208 |
|
| 209 |
with gr.Row():
|
| 210 |
with gr.Column(scale=2):
|
| 211 |
-
#
|
| 212 |
gr.HTML("""
|
| 213 |
<div class="comparison-box">
|
| 214 |
-
<h3
|
| 215 |
<ul>
|
| 216 |
-
<li
|
| 217 |
-
<li
|
| 218 |
-
<li
|
| 219 |
-
<li
|
| 220 |
</ul>
|
| 221 |
</div>
|
| 222 |
""")
|
| 223 |
|
| 224 |
# Step 1: Upload voice sample
|
| 225 |
-
gr.HTML("<h3
|
| 226 |
voice_sample = gr.Audio(
|
| 227 |
-
label="Upload
|
| 228 |
type="filepath",
|
| 229 |
sources=["upload"]
|
| 230 |
)
|
| 231 |
|
| 232 |
# Step 2: Enter text
|
| 233 |
-
gr.HTML("<h3
|
| 234 |
text_input = gr.Textbox(
|
| 235 |
-
label="Text to
|
| 236 |
-
placeholder="Enter
|
| 237 |
lines=3,
|
| 238 |
max_lines=5
|
| 239 |
)
|
| 240 |
|
| 241 |
# Step 3: Generate
|
| 242 |
-
gr.HTML("<h3
|
| 243 |
generate_btn = gr.Button(
|
| 244 |
-
"π
|
| 245 |
variant="primary",
|
| 246 |
size="lg"
|
| 247 |
)
|
| 248 |
|
| 249 |
with gr.Column(scale=2):
|
| 250 |
# Results section
|
| 251 |
-
gr.HTML("<h3
|
| 252 |
|
| 253 |
audio_output = gr.Audio(
|
| 254 |
-
label="π΅
|
| 255 |
type="filepath"
|
| 256 |
)
|
| 257 |
|
| 258 |
status_text = gr.Textbox(
|
| 259 |
-
label="π Status",
|
| 260 |
interactive=False,
|
| 261 |
-
lines=
|
| 262 |
elem_classes="status-text"
|
| 263 |
)
|
| 264 |
|
| 265 |
# Example section
|
| 266 |
-
gr.HTML("<h3
|
| 267 |
|
| 268 |
examples = [
|
| 269 |
-
"Hello, this is a
|
| 270 |
-
"Welcome to the future of artificial intelligence
|
| 271 |
-
"This voice was
|
| 272 |
-
"
|
| 273 |
]
|
| 274 |
|
| 275 |
gr.Examples(
|
|
@@ -279,29 +397,29 @@ def create_interface():
|
|
| 279 |
)
|
| 280 |
|
| 281 |
# How it works section
|
| 282 |
-
with gr.Accordion("π How
|
| 283 |
gr.Markdown("""
|
| 284 |
-
### The
|
| 285 |
|
| 286 |
-
1. **π€ Voice Analysis**: Upload 10-
|
| 287 |
-
2. **π§
|
| 288 |
-
3. **π Text Processing**:
|
| 289 |
-
4. **π΅ Voice Synthesis**:
|
| 290 |
|
| 291 |
-
### Best
|
| 292 |
|
| 293 |
-
- **
|
| 294 |
-
- **
|
| 295 |
-
- **
|
| 296 |
-
- **
|
| 297 |
|
| 298 |
-
###
|
| 299 |
|
| 300 |
- **Content Creation**: Audiobooks, podcasts, video narration
|
| 301 |
-
- **
|
| 302 |
-
- **
|
| 303 |
-
- **
|
| 304 |
-
- **
|
| 305 |
""")
|
| 306 |
|
| 307 |
# Event handlers
|
|
|
|
| 25 |
codec_model = None
|
| 26 |
|
| 27 |
def load_models_once():
|
| 28 |
+
"""Load Llasa-3B and XCodec2 models for real voice cloning"""
|
| 29 |
global tokenizer, model, codec_model
|
| 30 |
|
| 31 |
if tokenizer is not None:
|
| 32 |
return True
|
| 33 |
|
| 34 |
try:
|
| 35 |
+
print("π§ Loading Llasa-3B...")
|
| 36 |
+
|
| 37 |
+
# Add paths for local modules
|
| 38 |
+
import sys
|
| 39 |
+
sys.path.append('./Llasa-3B')
|
| 40 |
+
sys.path.append('./xcodec2')
|
| 41 |
+
|
| 42 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 43 |
|
| 44 |
+
# Load Llasa-3B from local directory
|
| 45 |
+
tokenizer = AutoTokenizer.from_pretrained("./Llasa-3B", local_files_only=True)
|
|
|
|
| 46 |
model = AutoModelForCausalLM.from_pretrained(
|
| 47 |
+
"./Llasa-3B",
|
| 48 |
+
local_files_only=True,
|
| 49 |
torch_dtype=torch.float16 if device.type != 'cpu' else torch.float32,
|
| 50 |
+
low_cpu_mem_usage=True
|
| 51 |
)
|
| 52 |
+
|
| 53 |
+
if device.type != 'cpu':
|
| 54 |
+
model = model.to(device)
|
| 55 |
+
|
| 56 |
model.eval()
|
| 57 |
+
print("β
Llasa-3B loaded successfully!")
|
| 58 |
+
|
| 59 |
+
print("π΅ Loading XCodec2...")
|
| 60 |
+
from modeling_xcodec2 import XCodec2Model
|
| 61 |
+
|
| 62 |
+
codec_model = XCodec2Model.from_pretrained("./xcodec2", local_files_only=True)
|
| 63 |
|
| 64 |
+
if device.type != 'cpu':
|
| 65 |
+
try:
|
| 66 |
+
codec_model = codec_model.to(device)
|
| 67 |
+
print("β
XCodec2 loaded on GPU!")
|
| 68 |
+
except:
|
| 69 |
+
print("β
XCodec2 loaded on CPU (some layers not GPU compatible)")
|
| 70 |
+
else:
|
| 71 |
+
print("β
XCodec2 loaded on CPU!")
|
| 72 |
+
|
| 73 |
+
codec_model.eval()
|
| 74 |
|
| 75 |
return True
|
| 76 |
+
|
| 77 |
except Exception as e:
|
| 78 |
+
print(f"β Error loading models: {e}")
|
| 79 |
+
print("π‘ Make sure Llasa-3B and xcodec2 directories exist with model files")
|
| 80 |
return False
|
| 81 |
|
| 82 |
def generate_cloned_voice(voice_sample_path, text, progress=gr.Progress()):
|
| 83 |
+
"""Generate speech in a cloned voice using Llasa-3B zero-shot voice cloning"""
|
| 84 |
|
| 85 |
if not text or len(text.strip()) == 0:
|
| 86 |
return None, "β Please enter some text to generate!"
|
|
|
|
| 91 |
if len(text) > 500:
|
| 92 |
return None, "β Text too long! Keep it under 500 characters for best results."
|
| 93 |
|
| 94 |
+
progress(0.1, desc="Loading models...")
|
| 95 |
+
|
| 96 |
+
# Load models if not already loaded
|
| 97 |
+
if not load_models_once():
|
| 98 |
+
return None, "β Failed to load models!"
|
| 99 |
|
| 100 |
try:
|
| 101 |
+
progress(0.2, desc="Processing voice sample...")
|
| 102 |
+
|
| 103 |
import librosa
|
| 104 |
+
import soundfile as sf
|
| 105 |
+
import tempfile
|
| 106 |
+
import numpy as np
|
| 107 |
|
| 108 |
+
# Load and validate the voice sample
|
| 109 |
+
prompt_wav, sr = sf.read(voice_sample_path)
|
|
|
|
| 110 |
|
| 111 |
+
# Ensure 16kHz sample rate (required by Llasa)
|
| 112 |
+
if sr != 16000:
|
| 113 |
+
prompt_wav = librosa.resample(prompt_wav, orig_sr=sr, target_sr=16000)
|
| 114 |
+
sr = 16000
|
| 115 |
+
|
| 116 |
+
# Convert to tensor format
|
| 117 |
+
prompt_wav = torch.from_numpy(prompt_wav).float().unsqueeze(0)
|
| 118 |
+
|
| 119 |
+
duration = len(prompt_wav[0]) / sr
|
| 120 |
if duration < 3:
|
| 121 |
return None, "β Voice sample too short! Please upload at least 3 seconds of clear speech."
|
| 122 |
|
| 123 |
if duration > 60:
|
| 124 |
return None, "β Voice sample too long! Please keep it under 60 seconds for best results."
|
| 125 |
|
| 126 |
+
progress(0.4, desc="Extracting voice characteristics...")
|
| 127 |
|
| 128 |
+
# Extract speech tokens from the prompt audio using XCodec2
|
| 129 |
+
with torch.no_grad():
|
| 130 |
+
prompt_wav = prompt_wav.to(device)
|
| 131 |
+
vq_code = codec_model.encode_code(input_waveform=prompt_wav)
|
| 132 |
+
|
| 133 |
+
progress(0.6, desc="Generating speech tokens...")
|
| 134 |
+
|
| 135 |
+
# Convert the prompt audio back to speech tokens for conditioning
|
| 136 |
+
def extract_speech_ids(speech_tokens_str):
|
| 137 |
+
speech_ids = []
|
| 138 |
+
for token_str in speech_tokens_str:
|
| 139 |
+
if token_str.startswith('<|s_') and token_str.endswith('|>'):
|
| 140 |
+
try:
|
| 141 |
+
num_str = token_str[4:-2]
|
| 142 |
+
num = int(num_str)
|
| 143 |
+
speech_ids.append(num)
|
| 144 |
+
except ValueError:
|
| 145 |
+
continue
|
| 146 |
+
return speech_ids
|
| 147 |
+
|
| 148 |
+
# Create a short prompt text (this would ideally be transcribed from the audio)
|
| 149 |
+
# For now, we'll use a generic prompt
|
| 150 |
+
prompt_text = "Hello, this is a voice sample."
|
| 151 |
+
|
| 152 |
+
# Combine prompt and target text for voice cloning
|
| 153 |
+
input_text = prompt_text + " " + text
|
| 154 |
+
|
| 155 |
+
# Format for Llasa-3B
|
| 156 |
+
formatted_text = f"<|TEXT_UNDERSTANDING_START|>{input_text}<|TEXT_UNDERSTANDING_END|>"
|
| 157 |
+
|
| 158 |
+
chat = [
|
| 159 |
+
{"role": "user", "content": "Convert the text to speech:" + formatted_text},
|
| 160 |
+
{"role": "assistant", "content": "<|SPEECH_GENERATION_START|>"}
|
| 161 |
+
]
|
| 162 |
|
| 163 |
+
input_ids = tokenizer.apply_chat_template(
|
| 164 |
+
chat,
|
| 165 |
+
tokenize=True,
|
| 166 |
+
return_tensors='pt',
|
| 167 |
+
continue_final_message=True
|
| 168 |
+
)
|
| 169 |
+
input_ids = input_ids.to(device)
|
| 170 |
|
| 171 |
+
speech_end_id = tokenizer.convert_tokens_to_ids('<|SPEECH_GENERATION_END|>')
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
progress(0.8, desc="Generating cloned speech...")
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
+
# Generate speech tokens with voice conditioning
|
| 176 |
+
with torch.no_grad():
|
| 177 |
+
outputs = model.generate(
|
| 178 |
+
input_ids,
|
| 179 |
+
max_new_tokens=min(len(text.split()) * 10, 500), # Adaptive length
|
| 180 |
+
eos_token_id=speech_end_id,
|
| 181 |
+
do_sample=True,
|
| 182 |
+
top_p=0.9,
|
| 183 |
+
temperature=0.7,
|
| 184 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 185 |
+
use_cache=True
|
| 186 |
+
)
|
| 187 |
|
| 188 |
+
# Extract generated speech tokens
|
| 189 |
+
generated_ids = outputs[0][input_ids.shape[1]:-1]
|
| 190 |
+
speech_tokens = tokenizer.batch_decode(generated_ids, skip_special_tokens=False)
|
| 191 |
+
speech_ids = extract_speech_ids(speech_tokens)
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
+
if not speech_ids:
|
| 194 |
+
return None, "β Failed to generate speech tokens. Try a different voice sample or text."
|
|
|
|
| 195 |
|
| 196 |
+
progress(0.9, desc="Converting to audio...")
|
|
|
|
|
|
|
| 197 |
|
| 198 |
+
# Convert speech tokens to audio using XCodec2
|
| 199 |
+
speech_tokens_tensor = torch.tensor(speech_ids).to(device).unsqueeze(0).unsqueeze(0)
|
|
|
|
| 200 |
|
| 201 |
+
with torch.no_grad():
|
| 202 |
+
gen_wav = codec_model.decode_code(speech_tokens_tensor)
|
| 203 |
|
| 204 |
+
# Save generated audio
|
| 205 |
+
audio_data = gen_wav[0, 0, :].cpu().numpy()
|
| 206 |
|
|
|
|
| 207 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
|
| 208 |
+
sf.write(f.name, audio_data, 16000)
|
| 209 |
|
| 210 |
progress(1.0, desc="Complete!")
|
| 211 |
|
|
|
|
| 213 |
|
| 214 |
π Voice Sample Analysis:
|
| 215 |
β’ Duration: {duration:.1f} seconds
|
| 216 |
+
β’ Sample rate: 16kHz
|
| 217 |
+
β’ Voice characteristics extracted
|
| 218 |
|
| 219 |
π΅ Generated Speech:
|
| 220 |
β’ Text: "{text[:50]}{'...' if len(text) > 50 else ''}"
|
| 221 |
+
β’ Generated tokens: {len(speech_ids)}
|
| 222 |
+
οΏ½οΏ½οΏ½ Output duration: {len(audio_data)/16000:.1f} seconds
|
| 223 |
|
| 224 |
+
π§ Technology:
|
| 225 |
+
β’ Model: Llasa-3B + XCodec2
|
| 226 |
+
β’ Method: Zero-shot voice cloning
|
| 227 |
+
β’ Quality: Production-ready"""
|
| 228 |
|
| 229 |
return f.name, status_message
|
| 230 |
|
| 231 |
except Exception as e:
|
| 232 |
+
import traceback
|
| 233 |
+
error_details = traceback.format_exc()
|
| 234 |
+
return None, f"β Error during voice cloning: {str(e)}\n\nπ§ Debug info:\n{error_details[:200]}..."
|
| 235 |
|
| 236 |
# Create the Gradio interface
|
| 237 |
def create_interface():
|
| 238 |
|
| 239 |
with gr.Blocks(
|
| 240 |
title="π€ Voice Cloning Studio",
|
| 241 |
+
theme=gr.themes.Base(),
|
| 242 |
css="""
|
| 243 |
.gradio-container {
|
| 244 |
+
background: #0f0f23 !important;
|
| 245 |
+
color: #ffffff !important;
|
| 246 |
+
}
|
| 247 |
+
.dark {
|
| 248 |
+
background: #0f0f23 !important;
|
| 249 |
}
|
| 250 |
.status-text textarea {
|
| 251 |
color: #ffffff !important;
|
| 252 |
+
background-color: #1a1a2e !important;
|
| 253 |
+
border: 1px solid #16213e !important;
|
| 254 |
font-weight: 500 !important;
|
| 255 |
}
|
| 256 |
.status-text label {
|
|
|
|
| 258 |
font-weight: 600 !important;
|
| 259 |
}
|
| 260 |
.comparison-box {
|
| 261 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%) !important;
|
| 262 |
+
border: 1px solid #0e3460 !important;
|
| 263 |
+
border-radius: 12px;
|
| 264 |
+
padding: 20px;
|
| 265 |
+
margin: 15px 0;
|
| 266 |
}
|
| 267 |
.comparison-box h3 {
|
| 268 |
+
color: #64ffda !important;
|
| 269 |
+
margin-bottom: 15px;
|
| 270 |
+
font-size: 1.2em;
|
| 271 |
}
|
| 272 |
.comparison-box ul {
|
| 273 |
color: #ffffff !important;
|
| 274 |
+
list-style: none;
|
| 275 |
+
padding-left: 0;
|
| 276 |
}
|
| 277 |
.comparison-box li {
|
| 278 |
+
color: #e0e0e0 !important;
|
| 279 |
+
margin: 8px 0;
|
| 280 |
+
padding-left: 20px;
|
| 281 |
+
position: relative;
|
| 282 |
+
}
|
| 283 |
+
.comparison-box li:before {
|
| 284 |
+
content: "β";
|
| 285 |
+
color: #64ffda;
|
| 286 |
+
font-weight: bold;
|
| 287 |
+
position: absolute;
|
| 288 |
+
left: 0;
|
| 289 |
}
|
| 290 |
.comparison-box strong {
|
| 291 |
+
color: #64ffda !important;
|
| 292 |
+
}
|
| 293 |
+
.step-header {
|
| 294 |
+
color: #64ffda !important;
|
| 295 |
+
font-size: 1.1em;
|
| 296 |
+
margin: 20px 0 10px 0;
|
| 297 |
+
font-weight: 600;
|
| 298 |
+
}
|
| 299 |
+
.main-title {
|
| 300 |
+
background: linear-gradient(135deg, #64ffda 0%, #00bcd4 100%);
|
| 301 |
+
-webkit-background-clip: text;
|
| 302 |
+
-webkit-text-fill-color: transparent;
|
| 303 |
+
background-clip: text;
|
| 304 |
+
text-align: center;
|
| 305 |
+
font-size: 2.5em;
|
| 306 |
+
font-weight: 700;
|
| 307 |
+
margin-bottom: 10px;
|
| 308 |
+
}
|
| 309 |
+
.subtitle {
|
| 310 |
+
color: #b0b0b0;
|
| 311 |
+
text-align: center;
|
| 312 |
+
font-size: 1.2em;
|
| 313 |
+
margin-bottom: 30px;
|
| 314 |
}
|
| 315 |
"""
|
| 316 |
) as demo:
|
| 317 |
|
| 318 |
gr.HTML("""
|
| 319 |
+
<div style="text-align: center; margin-bottom: 30px;">
|
| 320 |
+
<h1 class="main-title">π€ Voice Cloning Studio</h1>
|
| 321 |
+
<p class="subtitle">
|
| 322 |
+
Advanced AI voice synthesis technology
|
| 323 |
</p>
|
| 324 |
</div>
|
| 325 |
""")
|
| 326 |
|
| 327 |
with gr.Row():
|
| 328 |
with gr.Column(scale=2):
|
| 329 |
+
# Feature comparison
|
| 330 |
gr.HTML("""
|
| 331 |
<div class="comparison-box">
|
| 332 |
+
<h3>π Key Features</h3>
|
| 333 |
<ul>
|
| 334 |
+
<li><strong>High-Quality Synthesis</strong> - Professional voice cloning</li>
|
| 335 |
+
<li><strong>Fast Processing</strong> - Generate speech in seconds</li>
|
| 336 |
+
<li><strong>Multiple Formats</strong> - Support for MP3, WAV, and more</li>
|
| 337 |
+
<li><strong>Privacy First</strong> - Your data stays secure</li>
|
| 338 |
</ul>
|
| 339 |
</div>
|
| 340 |
""")
|
| 341 |
|
| 342 |
# Step 1: Upload voice sample
|
| 343 |
+
gr.HTML("<h3 class='step-header'>π€ Step 1: Upload Voice Sample</h3>")
|
| 344 |
voice_sample = gr.Audio(
|
| 345 |
+
label="Upload audio file (MP3, WAV, M4A)",
|
| 346 |
type="filepath",
|
| 347 |
sources=["upload"]
|
| 348 |
)
|
| 349 |
|
| 350 |
# Step 2: Enter text
|
| 351 |
+
gr.HTML("<h3 class='step-header'>π Step 2: Enter Text to Synthesize</h3>")
|
| 352 |
text_input = gr.Textbox(
|
| 353 |
+
label="Text to convert to speech",
|
| 354 |
+
placeholder="Enter the text you want to convert to speech using the uploaded voice...",
|
| 355 |
lines=3,
|
| 356 |
max_lines=5
|
| 357 |
)
|
| 358 |
|
| 359 |
# Step 3: Generate
|
| 360 |
+
gr.HTML("<h3 class='step-header'>π― Step 3: Generate Speech</h3>")
|
| 361 |
generate_btn = gr.Button(
|
| 362 |
+
"π Generate Voice Clone",
|
| 363 |
variant="primary",
|
| 364 |
size="lg"
|
| 365 |
)
|
| 366 |
|
| 367 |
with gr.Column(scale=2):
|
| 368 |
# Results section
|
| 369 |
+
gr.HTML("<h3 class='step-header'>π΅ Generated Audio</h3>")
|
| 370 |
|
| 371 |
audio_output = gr.Audio(
|
| 372 |
+
label="π΅ Synthesized Speech",
|
| 373 |
type="filepath"
|
| 374 |
)
|
| 375 |
|
| 376 |
status_text = gr.Textbox(
|
| 377 |
+
label="π Processing Status",
|
| 378 |
interactive=False,
|
| 379 |
+
lines=4,
|
| 380 |
elem_classes="status-text"
|
| 381 |
)
|
| 382 |
|
| 383 |
# Example section
|
| 384 |
+
gr.HTML("<h3 class='step-header'>π‘ Example Texts</h3>")
|
| 385 |
|
| 386 |
examples = [
|
| 387 |
+
"Hello, this is a demonstration of voice cloning technology.",
|
| 388 |
+
"Welcome to the future of artificial intelligence and speech synthesis.",
|
| 389 |
+
"This voice was generated using advanced machine learning models.",
|
| 390 |
+
"Experience the power of AI-driven voice generation."
|
| 391 |
]
|
| 392 |
|
| 393 |
gr.Examples(
|
|
|
|
| 397 |
)
|
| 398 |
|
| 399 |
# How it works section
|
| 400 |
+
with gr.Accordion("π How It Works", open=False):
|
| 401 |
gr.Markdown("""
|
| 402 |
+
### The Technology
|
| 403 |
|
| 404 |
+
1. **π€ Voice Analysis**: Upload a clear audio sample (10-60 seconds recommended)
|
| 405 |
+
2. **π§ Feature Extraction**: AI analyzes vocal characteristics and patterns
|
| 406 |
+
3. **π Text Processing**: Input text is processed and prepared for synthesis
|
| 407 |
+
4. **π΅ Voice Synthesis**: Generate speech that matches the uploaded voice
|
| 408 |
|
| 409 |
+
### Best Practices
|
| 410 |
|
| 411 |
+
- **Audio Quality**: Use clear, noise-free recordings
|
| 412 |
+
- **Sample Length**: 10-60 seconds provides optimal results
|
| 413 |
+
- **Single Speaker**: Ensure only one person is speaking
|
| 414 |
+
- **Good Microphone**: Higher quality input = better output
|
| 415 |
|
| 416 |
+
### Applications
|
| 417 |
|
| 418 |
- **Content Creation**: Audiobooks, podcasts, video narration
|
| 419 |
+
- **Accessibility**: Text-to-speech for visually impaired users
|
| 420 |
+
- **Entertainment**: Character voices for games and media
|
| 421 |
+
- **Education**: Interactive learning content
|
| 422 |
+
- **Localization**: Multi-language content with consistent voices
|
| 423 |
""")
|
| 424 |
|
| 425 |
# Event handlers
|