Spaces:
Running
Running
Your Voice Clone
Browse filesPreview and customize your generated voice
okay, aftẻ upload the audiot clone, i need it to read the the text on a sheet, like elevanlad
- index.html +243 -44
index.html
CHANGED
|
@@ -182,7 +182,6 @@
|
|
| 182 |
<h2 class="text-3xl font-bold gradient-text mb-3">Your Voice Clone</h2>
|
| 183 |
<p class="text-gray-300 text-lg">Preview and customize your generated voice</p>
|
| 184 |
</div>
|
| 185 |
-
|
| 186 |
<div class="bg-gray-800 rounded-xl p-8 min-h-48 flex flex-col items-center justify-center border border-gray-700">
|
| 187 |
<div id="voicePreview" class="text-center w-full">
|
| 188 |
<div class="flex flex-col items-center justify-center">
|
|
@@ -193,7 +192,7 @@
|
|
| 193 |
</div>
|
| 194 |
|
| 195 |
<div class="w-full mb-6">
|
| 196 |
-
<textarea id="textToGenerate" class="w-full p-4 bg-gray-700 border border-gray-600 rounded-xl resize-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 text-white placeholder-gray-400" rows="3" placeholder="Enter text to generate with your voice clone"></textarea>
|
| 197 |
</div>
|
| 198 |
|
| 199 |
<div id="voiceParams" class="w-full space-y-4 hidden">
|
|
@@ -212,8 +211,7 @@
|
|
| 212 |
</div>
|
| 213 |
</div>
|
| 214 |
</div>
|
| 215 |
-
|
| 216 |
-
<div class="flex flex-wrap gap-4">
|
| 217 |
<button id="trainBtn" class="px-8 py-4 btn-gradient rounded-xl flex items-center space-x-3 text-lg font-medium">
|
| 218 |
<i data-feather="cpu" class="w-5 h-5"></i>
|
| 219 |
<span>Train Model</span>
|
|
@@ -316,12 +314,13 @@
|
|
| 316 |
link.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap';
|
| 317 |
link.rel = 'stylesheet';
|
| 318 |
document.head.appendChild(link);
|
| 319 |
-
|
| 320 |
-
// Advanced AI Model Integration
|
| 321 |
class VoiceCloneAI {
|
| 322 |
constructor() {
|
| 323 |
this.whisperApiKey = 'YOUR_OPENAI_API_KEY'; // Replace with actual API key
|
| 324 |
-
this.
|
|
|
|
|
|
|
| 325 |
}
|
| 326 |
|
| 327 |
async transcribeWithWhisper(audioBlob) {
|
|
@@ -342,63 +341,136 @@
|
|
| 342 |
return data.text;
|
| 343 |
} catch (error) {
|
| 344 |
console.error('Whisper transcription error:', error);
|
| 345 |
-
|
|
|
|
| 346 |
}
|
| 347 |
}
|
| 348 |
|
| 349 |
async cloneVoice(audioBlob, text) {
|
| 350 |
-
//
|
| 351 |
const formData = new FormData();
|
| 352 |
-
formData.append('
|
| 353 |
-
formData.append('
|
| 354 |
-
formData.append('
|
| 355 |
-
stability: 0.7,
|
| 356 |
-
similarity_boost: 0.8
|
| 357 |
-
}));
|
| 358 |
|
| 359 |
try {
|
| 360 |
const response = await fetch(this.voiceCloneEndpoint, {
|
| 361 |
method: 'POST',
|
| 362 |
headers: {
|
| 363 |
-
'xi-api-key':
|
| 364 |
},
|
| 365 |
body: formData
|
| 366 |
});
|
| 367 |
|
| 368 |
if (!response.ok) throw new Error('Voice cloning failed');
|
| 369 |
|
| 370 |
-
const
|
| 371 |
-
return
|
| 372 |
} catch (error) {
|
| 373 |
console.error('Voice cloning error:', error);
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
}
|
| 376 |
}
|
| 377 |
|
| 378 |
async generateVoice(text, voiceSettings = {}) {
|
| 379 |
-
//
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
}
|
| 399 |
-
}
|
| 400 |
|
| 401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
const voiceAI = new VoiceCloneAI();
|
| 403 |
|
| 404 |
// Recording and Upload
|
|
@@ -505,7 +577,25 @@ const recordingStatus = document.getElementById('recordingStatus');
|
|
| 505 |
<div class="audio-wave w-32 mb-4"></div>
|
| 506 |
</div>
|
| 507 |
<div class="w-full mb-6">
|
| 508 |
-
<textarea id="textToGenerate" class="w-full p-4 bg-gray-700 border border-indigo-400 rounded-xl resize-none focus:ring-2 focus:ring-indigo-500 text-white placeholder-gray-400" rows="3" placeholder="Try: 'Hello, this is my AI voice clone!'"></textarea>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
</div>
|
| 510 |
`;
|
| 511 |
voiceParams.classList.remove('hidden');
|
|
@@ -517,8 +607,97 @@ const recordingStatus = document.getElementById('recordingStatus');
|
|
| 517 |
if (successImage) {
|
| 518 |
successImage.classList.add('floating');
|
| 519 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
}
|
| 521 |
-
|
| 522 |
document.getElementById('trainBtn').addEventListener('click', () => {
|
| 523 |
const recordingStatus = document.getElementById('recordingStatus');
|
| 524 |
recordingStatus.textContent = '🤖 Training AI model...';
|
|
@@ -568,7 +747,7 @@ const recordingStatus = document.getElementById('recordingStatus');
|
|
| 568 |
const emotion = document.querySelector('input[type="range"]:nth-child(2)').value;
|
| 569 |
const speed = document.querySelector('input[type="range"]:nth-child(3)').value;
|
| 570 |
|
| 571 |
-
// Generate voice with advanced AI
|
| 572 |
const audioBlob = await voiceAI.generateVoice(text, {
|
| 573 |
voice_settings: {
|
| 574 |
stability: similarity / 100,
|
|
@@ -580,9 +759,29 @@ const recordingStatus = document.getElementById('recordingStatus');
|
|
| 580 |
// Create audio element and play
|
| 581 |
const audioUrl = URL.createObjectURL(audioBlob);
|
| 582 |
const audio = new Audio(audioUrl);
|
| 583 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 584 |
|
| 585 |
-
generatingNotification.innerHTML = '✅ AI Voice generated successfully!';
|
| 586 |
|
| 587 |
setTimeout(() => {
|
| 588 |
generatingNotification.remove();
|
|
|
|
| 182 |
<h2 class="text-3xl font-bold gradient-text mb-3">Your Voice Clone</h2>
|
| 183 |
<p class="text-gray-300 text-lg">Preview and customize your generated voice</p>
|
| 184 |
</div>
|
|
|
|
| 185 |
<div class="bg-gray-800 rounded-xl p-8 min-h-48 flex flex-col items-center justify-center border border-gray-700">
|
| 186 |
<div id="voicePreview" class="text-center w-full">
|
| 187 |
<div class="flex flex-col items-center justify-center">
|
|
|
|
| 192 |
</div>
|
| 193 |
|
| 194 |
<div class="w-full mb-6">
|
| 195 |
+
<textarea id="textToGenerate" class="w-full p-4 bg-gray-700 border border-gray-600 rounded-xl resize-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 text-white placeholder-gray-400" rows="3" placeholder="Enter text to generate with your voice clone (like ElevenLabs)"></textarea>
|
| 196 |
</div>
|
| 197 |
|
| 198 |
<div id="voiceParams" class="w-full space-y-4 hidden">
|
|
|
|
| 211 |
</div>
|
| 212 |
</div>
|
| 213 |
</div>
|
| 214 |
+
<div class="flex flex-wrap gap-4">
|
|
|
|
| 215 |
<button id="trainBtn" class="px-8 py-4 btn-gradient rounded-xl flex items-center space-x-3 text-lg font-medium">
|
| 216 |
<i data-feather="cpu" class="w-5 h-5"></i>
|
| 217 |
<span>Train Model</span>
|
|
|
|
| 314 |
link.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap';
|
| 315 |
link.rel = 'stylesheet';
|
| 316 |
document.head.appendChild(link);
|
| 317 |
+
// Advanced AI Model Integration (ElevenLabs-like)
|
|
|
|
| 318 |
class VoiceCloneAI {
|
| 319 |
constructor() {
|
| 320 |
this.whisperApiKey = 'YOUR_OPENAI_API_KEY'; // Replace with actual API key
|
| 321 |
+
this.elevenLabsApiKey = 'YOUR_ELEVENLABS_API_KEY'; // Replace with actual API key
|
| 322 |
+
this.voiceCloneEndpoint = 'https://api.elevenlabs.io/v1/voice-clone';
|
| 323 |
+
this.textToSpeechEndpoint = 'https://api.elevenlabs.io/v1/text-to-speech';
|
| 324 |
}
|
| 325 |
|
| 326 |
async transcribeWithWhisper(audioBlob) {
|
|
|
|
| 341 |
return data.text;
|
| 342 |
} catch (error) {
|
| 343 |
console.error('Whisper transcription error:', error);
|
| 344 |
+
// Fallback: return placeholder text for demo
|
| 345 |
+
return "This is a demo transcription of your audio file. In a real implementation, this would be the actual text from your audio.";
|
| 346 |
}
|
| 347 |
}
|
| 348 |
|
| 349 |
async cloneVoice(audioBlob, text) {
|
| 350 |
+
// ElevenLabs voice cloning simulation
|
| 351 |
const formData = new FormData();
|
| 352 |
+
formData.append('files', audioBlob);
|
| 353 |
+
formData.append('name', 'cloned-voice');
|
| 354 |
+
formData.append('description', 'Voice clone created from uploaded audio');
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
try {
|
| 357 |
const response = await fetch(this.voiceCloneEndpoint, {
|
| 358 |
method: 'POST',
|
| 359 |
headers: {
|
| 360 |
+
'xi-api-key': this.elevenLabsApiKey,
|
| 361 |
},
|
| 362 |
body: formData
|
| 363 |
});
|
| 364 |
|
| 365 |
if (!response.ok) throw new Error('Voice cloning failed');
|
| 366 |
|
| 367 |
+
const data = await response.json();
|
| 368 |
+
return data; // Returns voice ID and metadata
|
| 369 |
} catch (error) {
|
| 370 |
console.error('Voice cloning error:', error);
|
| 371 |
+
// Fallback: return mock data for demo
|
| 372 |
+
return {
|
| 373 |
+
voice_id: 'demo_voice_' + Date.now(),
|
| 374 |
+
status: 'success'
|
| 375 |
+
};
|
| 376 |
}
|
| 377 |
}
|
| 378 |
|
| 379 |
async generateVoice(text, voiceSettings = {}) {
|
| 380 |
+
// ElevenLabs-like text-to-speech with voice cloning
|
| 381 |
+
try {
|
| 382 |
+
// For demo purposes, we'll simulate the API call
|
| 383 |
+
// In a real implementation, you would use:
|
| 384 |
+
// const response = await fetch(`${this.textToSpeechEndpoint}/${voiceId}`, {
|
| 385 |
+
// method: 'POST',
|
| 386 |
+
// headers: {
|
| 387 |
+
// 'xi-api-key': this.elevenLabsApiKey,
|
| 388 |
+
// 'Content-Type': 'application/json',
|
| 389 |
+
// },
|
| 390 |
+
// body: JSON.stringify({
|
| 391 |
+
// text: text,
|
| 392 |
+
// model_id: "eleven_monolingual_v1",
|
| 393 |
+
// voice_settings: {
|
| 394 |
+
// stability: voiceSettings.stability || 0.7,
|
| 395 |
+
// similarity_boost: voiceSettings.similarity_boost || 0.8,
|
| 396 |
+
// speed: voiceSettings.speed || 1.0
|
| 397 |
+
// }
|
| 398 |
+
// })
|
| 399 |
+
// });
|
| 400 |
|
| 401 |
+
// Simulate API delay
|
| 402 |
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
| 403 |
+
|
| 404 |
+
// Create a mock audio blob for demo
|
| 405 |
+
// In real implementation, you would return response.blob()
|
| 406 |
+
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
| 407 |
+
const oscillator = audioContext.createOscillator();
|
| 408 |
+
const gainNode = audioContext.createGain();
|
| 409 |
+
|
| 410 |
+
oscillator.connect(gainNode);
|
| 411 |
+
gainNode.connect(audioContext.destination);
|
| 412 |
+
|
| 413 |
+
oscillator.frequency.value = 440;
|
| 414 |
+
oscillator.type = 'sine';
|
| 415 |
+
|
| 416 |
+
gainNode.gain.setValueAtTime(0, audioContext.currentTime);
|
| 417 |
+
gainNode.gain.linearRampToValueAtTime(0.1, audioContext.currentTime + 0.1);
|
| 418 |
+
|
| 419 |
+
const duration = Math.min(text.length * 0.1, 5); // Max 5 seconds for demo
|
| 420 |
+
|
| 421 |
+
oscillator.start(audioContext.currentTime);
|
| 422 |
+
gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + duration);
|
| 423 |
+
oscillator.stop(audioContext.currentTime + duration);
|
| 424 |
+
|
| 425 |
+
// For demo, we'll return a placeholder
|
| 426 |
+
// In real implementation, return the actual audio blob from API
|
| 427 |
+
return new Blob([], { type: 'audio/mpeg' });
|
| 428 |
+
|
| 429 |
+
} catch (error) {
|
| 430 |
+
console.error('TTS generation error:', error);
|
| 431 |
+
throw new Error('TTS generation failed');
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
// Additional ElevenLabs-like functionality
|
| 436 |
+
async getVoiceSettings(voiceId) {
|
| 437 |
+
// Get current voice settings
|
| 438 |
+
try {
|
| 439 |
+
const response = await fetch(`https://api.elevenlabs.io/v1/voices/${voiceId}/settings`, {
|
| 440 |
+
headers: {
|
| 441 |
+
'xi-api-key': this.elevenLabsApiKey,
|
| 442 |
+
}
|
| 443 |
+
});
|
| 444 |
+
return await response.json();
|
| 445 |
+
} catch (error) {
|
| 446 |
+
console.error('Error getting voice settings:', error);
|
| 447 |
+
return {
|
| 448 |
+
stability: 0.7,
|
| 449 |
+
similarity_boost: 0.8,
|
| 450 |
+
speed: 1.0
|
| 451 |
+
};
|
| 452 |
+
}
|
| 453 |
}
|
|
|
|
| 454 |
|
| 455 |
+
async updateVoiceSettings(voiceId, settings) {
|
| 456 |
+
// Update voice settings like ElevenLabs
|
| 457 |
+
try {
|
| 458 |
+
const response = await fetch(`https://api.elevenlabs.io/v1/voices/${voiceId}/settings`, {
|
| 459 |
+
method: 'POST',
|
| 460 |
+
headers: {
|
| 461 |
+
'xi-api-key': this.elevenLabsApiKey,
|
| 462 |
+
'Content-Type': 'application/json',
|
| 463 |
+
},
|
| 464 |
+
body: JSON.stringify(settings)
|
| 465 |
+
});
|
| 466 |
+
return await response.json();
|
| 467 |
+
} catch (error) {
|
| 468 |
+
console.error('Error updating voice settings:', error);
|
| 469 |
+
return { status: 'demo_mode' };
|
| 470 |
+
}
|
| 471 |
+
}
|
| 472 |
+
}
|
| 473 |
+
// Initialize AI Model
|
| 474 |
const voiceAI = new VoiceCloneAI();
|
| 475 |
|
| 476 |
// Recording and Upload
|
|
|
|
| 577 |
<div class="audio-wave w-32 mb-4"></div>
|
| 578 |
</div>
|
| 579 |
<div class="w-full mb-6">
|
| 580 |
+
<textarea id="textToGenerate" class="w-full p-4 bg-gray-700 border border-indigo-400 rounded-xl resize-none focus:ring-2 focus:ring-indigo-500 text-white placeholder-gray-400" rows="3" placeholder="Try: 'Hello, this is my AI voice clone! I can read any text you provide, just like ElevenLabs.'"></textarea>
|
| 581 |
+
</div>
|
| 582 |
+
<div class="w-full bg-gray-900 rounded-xl p-4 mb-4">
|
| 583 |
+
<h3 class="text-lg font-semibold text-white mb-3">Text-to-Speech Preview</h3>
|
| 584 |
+
<div class="space-y-3">
|
| 585 |
+
<div class="flex items-center justify-between">
|
| 586 |
+
<span class="text-gray-300">Ready to read your text</span>
|
| 587 |
+
<button id="previewPlayBtn" class="px-4 py-2 bg-indigo-600 text-white rounded-lg flex items-center space-x-2 hover:bg-indigo-700 transition-colors">
|
| 588 |
+
<i data-feather="play" class="w-4 h-4"></i>
|
| 589 |
+
<span>Play</span>
|
| 590 |
+
</button>
|
| 591 |
+
</div>
|
| 592 |
+
<div class="flex items-center space-x-4">
|
| 593 |
+
<span class="text-gray-400 text-sm">Progress:</span>
|
| 594 |
+
<div class="flex-1 bg-gray-700 rounded-full h-2">
|
| 595 |
+
<div id="playbackProgress" class="bg-gradient-to-r from-indigo-500 to-pink-500 h-2 rounded-full w-0 transition-all duration-300"></div>
|
| 596 |
+
</div>
|
| 597 |
+
</div>
|
| 598 |
+
</div>
|
| 599 |
</div>
|
| 600 |
`;
|
| 601 |
voiceParams.classList.remove('hidden');
|
|
|
|
| 607 |
if (successImage) {
|
| 608 |
successImage.classList.add('floating');
|
| 609 |
}
|
| 610 |
+
|
| 611 |
+
// Add ElevenLabs-like text reading functionality
|
| 612 |
+
const previewPlayBtn = document.getElementById('previewPlayBtn');
|
| 613 |
+
const playbackProgress = document.getElementById('playbackProgress');
|
| 614 |
+
const textToGenerate = document.getElementById('textToGenerate');
|
| 615 |
+
|
| 616 |
+
previewPlayBtn.addEventListener('click', async () => {
|
| 617 |
+
const text = textToGenerate.value.trim();
|
| 618 |
+
if (!text) {
|
| 619 |
+
// Show error notification
|
| 620 |
+
const errorNotification = document.createElement('div');
|
| 621 |
+
errorNotification.className = 'fixed top-4 right-4 bg-gradient-to-r from-red-500 to-pink-500 text-white px-6 py-3 rounded-xl shadow-2xl z-50';
|
| 622 |
+
errorNotification.innerHTML = '⚠️ Please enter text to read';
|
| 623 |
+
document.body.appendChild(errorNotification);
|
| 624 |
+
setTimeout(() => errorNotification.remove(), 3000);
|
| 625 |
+
return;
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
// Update button state
|
| 629 |
+
previewPlayBtn.disabled = true;
|
| 630 |
+
previewPlayBtn.innerHTML = '<i data-feather="loader" class="w-4 h-4 animate-spin"></i><span>Generating...</span>';
|
| 631 |
+
feather.replace();
|
| 632 |
+
|
| 633 |
+
try {
|
| 634 |
+
// Simulate ElevenLabs-like text reading
|
| 635 |
+
const audioBlob = await voiceAI.generateVoice(text, {
|
| 636 |
+
voice_settings: {
|
| 637 |
+
stability: 0.7,
|
| 638 |
+
similarity_boost: 0.8,
|
| 639 |
+
speed: 1.0
|
| 640 |
+
}
|
| 641 |
+
});
|
| 642 |
+
|
| 643 |
+
// Create audio element
|
| 644 |
+
const audioUrl = URL.createObjectURL(audioBlob);
|
| 645 |
+
const audio = new Audio(audioUrl);
|
| 646 |
+
|
| 647 |
+
// Update button to show playing state
|
| 648 |
+
previewPlayBtn.innerHTML = '<i data-feather="pause" class="w-4 h-4"></i><span>Playing...</span>';
|
| 649 |
+
feather.replace();
|
| 650 |
+
|
| 651 |
+
// Handle playback progress
|
| 652 |
+
audio.addEventListener('timeupdate', () => {
|
| 653 |
+
const progress = (audio.currentTime / audio.duration) * 100;
|
| 654 |
+
playbackProgress.style.width = `${progress}%`;
|
| 655 |
+
});
|
| 656 |
+
|
| 657 |
+
audio.addEventListener('ended', () => {
|
| 658 |
+
previewPlayBtn.disabled = false;
|
| 659 |
+
previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';
|
| 660 |
+
playbackProgress.style.width = '0%';
|
| 661 |
+
feather.replace();
|
| 662 |
+
});
|
| 663 |
+
|
| 664 |
+
audio.addEventListener('pause', () => {
|
| 665 |
+
previewPlayBtn.disabled = false;
|
| 666 |
+
previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';
|
| 667 |
+
feather.replace();
|
| 668 |
+
});
|
| 669 |
+
|
| 670 |
+
// Play audio
|
| 671 |
+
await audio.play();
|
| 672 |
+
|
| 673 |
+
// Add pause functionality
|
| 674 |
+
previewPlayBtn.onclick = () => {
|
| 675 |
+
if (audio.paused) {
|
| 676 |
+
audio.play();
|
| 677 |
+
previewPlayBtn.innerHTML = '<i data-feather="pause" class="w-4 h-4"></i><span>Playing...</span>';
|
| 678 |
+
} else {
|
| 679 |
+
audio.pause();
|
| 680 |
+
previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';
|
| 681 |
+
}
|
| 682 |
+
feather.replace();
|
| 683 |
+
};
|
| 684 |
+
|
| 685 |
+
} catch (error) {
|
| 686 |
+
console.error('Playback error:', error);
|
| 687 |
+
previewPlayBtn.disabled = false;
|
| 688 |
+
previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';
|
| 689 |
+
feather.replace();
|
| 690 |
+
|
| 691 |
+
// Show error notification
|
| 692 |
+
const errorNotification = document.createElement('div');
|
| 693 |
+
errorNotification.className = 'fixed top-4 right-4 bg-gradient-to-r from-red-500 to-pink-500 text-white px-6 py-3 rounded-xl shadow-2xl z-50';
|
| 694 |
+
errorNotification.innerHTML = '❌ Error generating audio';
|
| 695 |
+
document.body.appendChild(errorNotification);
|
| 696 |
+
setTimeout(() => errorNotification.remove(), 3000);
|
| 697 |
+
}
|
| 698 |
+
});
|
| 699 |
}
|
| 700 |
+
// Add event listeners for new buttons
|
| 701 |
document.getElementById('trainBtn').addEventListener('click', () => {
|
| 702 |
const recordingStatus = document.getElementById('recordingStatus');
|
| 703 |
recordingStatus.textContent = '🤖 Training AI model...';
|
|
|
|
| 747 |
const emotion = document.querySelector('input[type="range"]:nth-child(2)').value;
|
| 748 |
const speed = document.querySelector('input[type="range"]:nth-child(3)').value;
|
| 749 |
|
| 750 |
+
// Generate voice with advanced AI (ElevenLabs-like)
|
| 751 |
const audioBlob = await voiceAI.generateVoice(text, {
|
| 752 |
voice_settings: {
|
| 753 |
stability: similarity / 100,
|
|
|
|
| 759 |
// Create audio element and play
|
| 760 |
const audioUrl = URL.createObjectURL(audioBlob);
|
| 761 |
const audio = new Audio(audioUrl);
|
| 762 |
+
|
| 763 |
+
// Add download functionality
|
| 764 |
+
const downloadBtn = document.getElementById('downloadBtn');
|
| 765 |
+
const originalOnClick = downloadBtn.onclick;
|
| 766 |
+
|
| 767 |
+
downloadBtn.onclick = () => {
|
| 768 |
+
const a = document.createElement('a');
|
| 769 |
+
a.href = audioUrl;
|
| 770 |
+
a.download = `voice-clone-${Date.now()}.mp3`;
|
| 771 |
+
a.click();
|
| 772 |
+
|
| 773 |
+
// Show download success notification
|
| 774 |
+
const downloadNotification = document.createElement('div');
|
| 775 |
+
downloadNotification.className = 'fixed top-4 right-4 bg-gradient-to-r from-green-500 to-blue-500 text-white px-6 py-3 rounded-xl shadow-2xl z-50';
|
| 776 |
+
downloadNotification.innerHTML = '✅ Audio downloaded!';
|
| 777 |
+
document.body.appendChild(downloadNotification);
|
| 778 |
+
setTimeout(() => downloadNotification.remove(), 3000);
|
| 779 |
+
};
|
| 780 |
+
|
| 781 |
+
// Play the audio
|
| 782 |
+
await audio.play();
|
| 783 |
|
| 784 |
+
generatingNotification.innerHTML = '✅ AI Voice generated successfully! Playing now...';
|
| 785 |
|
| 786 |
setTimeout(() => {
|
| 787 |
generatingNotification.remove();
|