crackuser commited on
Commit
e6e0279
ยท
verified ยท
1 Parent(s): 187313d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +269 -258
app.py CHANGED
@@ -1,62 +1,90 @@
1
  import gradio as gr
2
  import torch
3
- import numpy as np
4
- import soundfile as sf
5
  import tempfile
6
  import os
7
- from scipy.io import wavfile
8
- import librosa
9
 
10
- def extract_audio_features(audio_path):
11
- """Extract features from audio for voice cloning"""
12
- try:
13
- # Load audio file
14
- audio, sr = librosa.load(audio_path, sr=16000)
15
- return audio, sr
16
- except Exception as e:
17
- print(f"Error processing audio: {e}")
18
- return None, None
 
 
 
 
 
 
 
 
 
 
19
 
20
- def voice_clone_with_audio(reference_audio, input_audio, enhance_quality=True):
21
  """
22
- Voice-to-Voice cloning: Clone reference voice using input audio
23
  """
24
  try:
25
- if not reference_audio:
26
- return None, "โŒ Please upload reference audio!"
27
 
28
- if not input_audio:
29
- return None, "โŒ Please upload input audio to transform!"
30
 
31
- # Process reference audio
32
- ref_audio, ref_sr = extract_audio_features(reference_audio)
33
- if ref_audio is None:
34
- return None, "โŒ Error processing reference audio!"
 
 
 
 
 
 
35
 
36
- # Process input audio
37
- input_audio_data, input_sr = extract_audio_features(input_audio)
38
- if input_audio_data is None:
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
- # Save output audio
50
- output_path = save_audio_output(transformed_audio, ref_sr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- return output_path, f"โœ… Voice cloning complete!\n๐ŸŽต Transformed {len(input_audio_data)/input_sr:.1f}s of audio using reference voice"
 
53
 
 
 
 
 
 
54
  except Exception as e:
55
- return None, f"โŒ Error in voice cloning: {str(e)}"
56
 
57
- def voice_clone_with_text(reference_audio, input_text, language="en", speed=1.0):
58
  """
59
- Text-to-Voice cloning: Generate speech from text using reference voice
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
- # Process reference audio
69
- ref_audio, ref_sr = extract_audio_features(reference_audio)
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
- # Save output audio
82
- output_path = save_audio_output(generated_audio, ref_sr)
 
 
83
 
84
- return output_path, f"โœ… Text-to-speech complete!\n๐Ÿ“ Generated speech for: '{input_text[:100]}{'...' if len(input_text) > 100 else ''}'"
 
 
85
 
86
- except Exception as e:
87
- return None, f"โŒ Error in text-to-speech: {str(e)}"
88
-
89
- def apply_voice_transformation(reference_audio, input_audio, enhance_quality=True):
90
- """
91
- Apply voice transformation (demo implementation)
92
- In production, this would use models like XTTS, OpenVoice, etc.
93
- """
94
- # Demo: Simple pitch and tone adjustment
95
- # This is a placeholder - replace with actual voice cloning model
96
-
97
- # Normalize audio lengths
98
- min_length = min(len(reference_audio), len(input_audio))
99
- if min_length > 0:
100
- # Simple blending for demo (not real voice cloning)
101
- alpha = 0.7 # Weight for input audio
102
- beta = 0.3 # Weight for reference characteristics
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
- # Apply enhancement if requested
112
- if enhance_quality:
113
- transformed = enhance_audio_quality(transformed)
114
 
115
- return transformed
116
- else:
117
- return input_audio
118
-
119
- def text_to_speech_with_voice(text, reference_voice, language="en", speed=1.0):
120
- """
121
- Generate speech from text using reference voice characteristics
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 with tabs
165
- def create_interface():
166
  with gr.Blocks(
167
- title="๐ŸŽญ Voice Cloning Studio",
168
- theme=gr.themes.Soft(primary_hue="blue", secondary_hue="green")
169
  ) as demo:
170
 
171
  # Header
172
  gr.HTML("""
173
  <div style="text-align: center; padding: 20px;">
174
- <h1 style="color: #2E86AB; margin-bottom: 10px;">๐ŸŽญ AI Voice Cloning Studio</h1>
175
- <p style="color: #666; font-size: 18px;">Clone any voice with AI technology - Support for both Audio and Text input</p>
 
 
 
 
 
 
 
 
176
  </div>
177
  """)
178
 
179
  with gr.Row():
180
  with gr.Column(scale=1):
181
  # Reference Voice Section
182
- gr.HTML("<h3 style='color: #2E86AB;'>๐ŸŽค Upload Reference Voice</h3>")
183
  reference_audio = gr.Audio(
184
- label="Reference Audio (10+ seconds recommended)",
185
  type="filepath",
186
  sources=["upload", "microphone"]
187
  )
 
188
 
189
- gr.HTML("<p style='color: #666; font-size: 14px;'>This is the voice you want to clone. Upload clear, high-quality audio.</p>")
190
-
191
  with gr.Column(scale=1):
192
- # Input Method Selection
193
- gr.HTML("<h3 style='color: #2E86AB;'>๐Ÿ“ฅ Choose Input Method</h3>")
194
 
195
- with gr.Tabs():
196
- with gr.TabItem("๐ŸŽต Audio Input"):
197
- gr.HTML("<p>Upload audio to transform into the reference voice</p>")
198
- input_audio = gr.Audio(
199
- label="Input Audio to Transform",
200
- type="filepath",
201
- sources=["upload", "microphone"]
202
- )
203
-
204
- enhance_audio = gr.Checkbox(
205
- label="๐ŸŽš๏ธ Enhance Audio Quality",
206
- value=True
207
- )
208
-
209
- audio_clone_btn = gr.Button(
210
- "๐ŸŽค Clone Voice from Audio",
211
- variant="primary",
212
- size="lg"
213
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
- with gr.TabItem("๐Ÿ“ Text Input"):
216
- gr.HTML("<p>Enter text to speak in the reference voice</p>")
217
- text_input = gr.Textbox(
218
- label="Text to Convert",
219
- placeholder="Enter the text you want to speak in the cloned voice...",
220
- lines=4,
221
- max_lines=6
222
- )
223
-
224
- with gr.Row():
225
- language_select = gr.Dropdown(
226
- choices=[
227
- ("๐Ÿ‡บ๐Ÿ‡ธ English", "en"),
228
- ("๐Ÿ‡ช๐Ÿ‡ธ Spanish", "es"),
229
- ("๐Ÿ‡ซ๐Ÿ‡ท French", "fr"),
230
- ("๐Ÿ‡ฉ๐Ÿ‡ช German", "de"),
231
- ("๐Ÿ‡ฎ๐Ÿ‡น Italian", "it"),
232
- ("๐Ÿ‡ง๐Ÿ‡ท Portuguese", "pt"),
233
- ("๐Ÿ‡จ๐Ÿ‡ณ Chinese", "zh"),
234
- ("๐Ÿ‡ฏ๐Ÿ‡ต Japanese", "ja")
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
- status_output = gr.Textbox(
264
- label="Status",
265
- lines=3,
266
- interactive=False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  )
268
 
269
- # Examples Section
270
- with gr.Accordion("๐Ÿ’ก Example Texts", open=False):
271
- examples = [
272
- "Hello, this is a demonstration of AI voice cloning technology.",
273
- "Welcome to the future of artificial intelligence and speech synthesis.",
274
- "This voice was generated using advanced machine learning models.",
275
- "Experience the power of AI-driven voice generation with natural speech patterns."
276
- ]
277
-
278
- gr.Examples(
279
- examples=examples,
280
- inputs=text_input,
281
- label="Click to try these examples:"
282
  )
283
 
284
- # How it works section
285
- with gr.Accordion("๐Ÿ” How Voice Cloning Works", open=False):
286
  gr.Markdown("""
287
- ### Voice-to-Voice Cloning Process
288
- 1. **๐ŸŽค Reference Voice**: Upload 10+ seconds of clear speech
289
- 2. **๐Ÿ“ฅ Input Audio**: Upload audio you want to transform
290
- 3. **๐Ÿง  AI Analysis**: Extract voice characteristics and features
291
- 4. **๐ŸŽต Voice Synthesis**: Apply reference voice to input content
 
 
 
 
 
 
 
292
 
293
- ### Text-to-Speech Process
294
- 1. **๐ŸŽค Reference Voice**: Upload voice sample to clone
295
- 2. **๐Ÿ“ Text Input**: Enter text to convert to speech
296
- 3. **๐Ÿ—ฃ๏ธ Speech Generation**: Generate speech in the cloned voice
297
- 4. **๐ŸŽต Audio Output**: Download your cloned speech
 
298
 
299
- ### Tips for Best Results
300
- - **Reference Audio**: Use 10+ seconds of clear, single-speaker audio
301
- - **Input Audio**: Ensure good quality with minimal background noise
302
- - **Language**: Match reference voice language when possible
303
- - **Length**: Shorter inputs (under 30 seconds) work better
304
  """)
305
 
306
- # Event handlers
307
- audio_clone_btn.click(
308
- fn=voice_clone_with_audio,
309
- inputs=[reference_audio, input_audio, enhance_audio],
310
  outputs=[audio_output, status_output],
311
  show_progress=True
312
  )
313
 
314
  text_clone_btn.click(
315
- fn=voice_clone_with_text,
316
- inputs=[reference_audio, text_input, language_select, speed_control],
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 = create_interface()
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,