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
181 unmodified lines1821831841851861871884 unmodified lines19319419519619719819912 unmodified lines21221321421521621721821996 unmodified lines31631731831932032132232332432532632714 unmodified lines342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404100 unmodified lines5055065075085095105115 unmodified lines51751851952052152252352443 unmodified lines5685695705715725735745 unmodified lines580581582583584585586587588181 unmodified lines<h2 class="text-3xl font-bold gradient-text mb-3">Your Voice Clone</h2><p class="text-gray-300 text-lg">Preview and customize your generated voice</p></div><div class="bg-gray-800 rounded-xl p-8 min-h-48 flex flex-col items-center justify-center border border-gray-700"><div id="voicePreview" class="text-center w-full"><div class="flex flex-col items-center justify-center">4 unmodified lines</div><div class="w-full mb-6"><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></div><div id="voiceParams" class="w-full space-y-4 hidden">12 unmodified lines</div></div></div><div class="flex flex-wrap gap-4"><button id="trainBtn" class="px-8 py-4 btn-gradient rounded-xl flex items-center space-x-3 text-lg font-medium"><i data-feather="cpu" class="w-5 h-5"></i><span>Train Model</span>96 unmodified lineslink.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap';link.rel = 'stylesheet';document.head.appendChild(link);// Advanced AI Model Integrationclass VoiceCloneAI {constructor() {this.whisperApiKey = 'YOUR_OPENAI_API_KEY'; // Replace with actual API keythis.voiceCloneEndpoint = 'https://api.elevenlabs.io/v1/voice-clone'; // Example endpoint}async transcribeWithWhisper(audioBlob) {14 unmodified linesreturn data.text;} catch (error) {console.error('Whisper transcription error:', error);throw new Error('Transcription failed');}}async cloneVoice(audioBlob, text) {// This is a simplified example using ElevenLabs APIconst formData = new FormData();formData.append('audio', audioBlob);formData.append('text', text);formData.append('voice_settings', JSON.stringify({stability: 0.7,similarity_boost: 0.8}));try {const response = await fetch(this.voiceCloneEndpoint, {method: 'POST',headers: {'xi-api-key': 'YOUR_ELEVENLABS_API_KEY', // Replace with actual API key},body: formData});if (!response.ok) throw new Error('Voice cloning failed');const audioData = await response.blob();return audioData;} catch (error) {console.error('Voice cloning error:', error);throw new Error('Voice cloning failed');}}async generateVoice(text, voiceSettings = {}) {// Advanced TTS generation with fine-tuned modelsconst response = await fetch('https://api.openai.com/v1/audio/speech', {method: 'POST',headers: {'Authorization': `Bearer ${this.whisperApiKey}`,'Content-Type': 'application/json',},body: JSON.stringify({model: "tts-1-hd",input: text,voice: "alloy",...voiceSettings})});if (!response.ok) throw new Error('TTS generation failed');const audioBlob = await response.blob();return audioBlob;}}// Initialize AI Modelconst voiceAI = new VoiceCloneAI();// Recording and Upload100 unmodified lines<div class="audio-wave w-32 mb-4"></div></div><div class="w-full mb-6"><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></div>`;voiceParams.classList.remove('hidden');5 unmodified linesif (successImage) {successImage.classList.add('floating');}}// Add event listeners for new buttonsdocument.getElementById('trainBtn').addEventListener('click', () => {const recordingStatus = document.getElementById('recordingStatus');recordingStatus.textContent = '🤖 Training AI model...';43 unmodified linesconst emotion = document.querySelector('input[type="range"]:nth-child(2)').value;const speed = document.querySelector('input[type="range"]:nth-child(3)').value;// Generate voice with advanced AIconst audioBlob = await voiceAI.generateVoice(text, {voice_settings: {stability: similarity / 100,5 unmodified lines// Create audio element and playconst audioUrl = URL.createObjectURL(audioBlob);const audio = new Audio(audioUrl);audio.play();generatingNotification.innerHTML = '✅ AI Voice generated successfully!';setTimeout(() => {generatingNotification.remove();181 unmodified lines1821831841851861874 unmodified lines19219319419519619719812 unmodified lines21121221321421521621796 unmodified lines31431531631731831932032132232332432532614 unmodified lines341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476100 unmodified lines5775785795805815825835845855865875885895905915925935945955965975985996006015 unmodified lines60760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270343 unmodified lines7477487497507517527535 unmodified lines759760761762763764765766767768769770771772773774775776777778779780781782783784785786787181 unmodified lines<h2 class="text-3xl font-bold gradient-text mb-3">Your Voice Clone</h2><p class="text-gray-300 text-lg">Preview and customize your generated voice</p></div><div class="bg-gray-800 rounded-xl p-8 min-h-48 flex flex-col items-center justify-center border border-gray-700"><div id="voicePreview" class="text-center w-full"><div class="flex flex-col items-center justify-center">4 unmodified lines</div><div class="w-full mb-6"><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></div><div id="voiceParams" class="w-full space-y-4 hidden">12 unmodified lines</div></div></div><div class="flex flex-wrap gap-4"><button id="trainBtn" class="px-8 py-4 btn-gradient rounded-xl flex items-center space-x-3 text-lg font-medium"><i data-feather="cpu" class="w-5 h-5"></i><span>Train Model</span>96 unmodified lineslink.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap';link.rel = 'stylesheet';document.head.appendChild(link);// Advanced AI Model Integration (ElevenLabs-like)class VoiceCloneAI {constructor() {this.whisperApiKey = 'YOUR_OPENAI_API_KEY'; // Replace with actual API keythis.elevenLabsApiKey = 'YOUR_ELEVENLABS_API_KEY'; // Replace with actual API keythis.voiceCloneEndpoint = 'https://api.elevenlabs.io/v1/voice-clone';this.textToSpeechEndpoint = 'https://api.elevenlabs.io/v1/text-to-speech';}async transcribeWithWhisper(audioBlob) {14 unmodified linesreturn data.text;} catch (error) {console.error('Whisper transcription error:', error);// Fallback: return placeholder text for demoreturn "This is a demo transcription of your audio file. In a real implementation, this would be the actual text from your audio.";}}async cloneVoice(audioBlob, text) {// ElevenLabs voice cloning simulationconst formData = new FormData();formData.append('files', audioBlob);formData.append('name', 'cloned-voice');formData.append('description', 'Voice clone created from uploaded audio');try {const response = await fetch(this.voiceCloneEndpoint, {method: 'POST',headers: {'xi-api-key': this.elevenLabsApiKey,},body: formData});if (!response.ok) throw new Error('Voice cloning failed');const data = await response.json();return data; // Returns voice ID and metadata} catch (error) {console.error('Voice cloning error:', error);// Fallback: return mock data for demoreturn {voice_id: 'demo_voice_' + Date.now(),status: 'success'};}}async generateVoice(text, voiceSettings = {}) {// ElevenLabs-like text-to-speech with voice cloningtry {// For demo purposes, we'll simulate the API call// In a real implementation, you would use:// const response = await fetch(`${this.textToSpeechEndpoint}/${voiceId}`, {// method: 'POST',// headers: {// 'xi-api-key': this.elevenLabsApiKey,// 'Content-Type': 'application/json',// },// body: JSON.stringify({// text: text,// model_id: "eleven_monolingual_v1",// voice_settings: {// stability: voiceSettings.stability || 0.7,// similarity_boost: voiceSettings.similarity_boost || 0.8,// speed: voiceSettings.speed || 1.0// }// })// });// Simulate API delayawait new Promise(resolve => setTimeout(resolve, 2000));// Create a mock audio blob for demo// In real implementation, you would return response.blob()const audioContext = new (window.AudioContext || window.webkitAudioContext)();const oscillator = audioContext.createOscillator();const gainNode = audioContext.createGain();oscillator.connect(gainNode);gainNode.connect(audioContext.destination);oscillator.frequency.value = 440;oscillator.type = 'sine';gainNode.gain.setValueAtTime(0, audioContext.currentTime);gainNode.gain.linearRampToValueAtTime(0.1, audioContext.currentTime + 0.1);const duration = Math.min(text.length * 0.1, 5); // Max 5 seconds for demooscillator.start(audioContext.currentTime);gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + duration);oscillator.stop(audioContext.currentTime + duration);// For demo, we'll return a placeholder// In real implementation, return the actual audio blob from APIreturn new Blob([], { type: 'audio/mpeg' });} catch (error) {console.error('TTS generation error:', error);throw new Error('TTS generation failed');}}// Additional ElevenLabs-like functionalityasync getVoiceSettings(voiceId) {// Get current voice settingstry {const response = await fetch(`https://api.elevenlabs.io/v1/voices/${voiceId}/settings`, {headers: {'xi-api-key': this.elevenLabsApiKey,}});return await response.json();} catch (error) {console.error('Error getting voice settings:', error);return {stability: 0.7,similarity_boost: 0.8,speed: 1.0};}}async updateVoiceSettings(voiceId, settings) {// Update voice settings like ElevenLabstry {const response = await fetch(`https://api.elevenlabs.io/v1/voices/${voiceId}/settings`, {method: 'POST',headers: {'xi-api-key': this.elevenLabsApiKey,'Content-Type': 'application/json',},body: JSON.stringify(settings)});return await response.json();} catch (error) {console.error('Error updating voice settings:', error);return { status: 'demo_mode' };}}}// Initialize AI Modelconst voiceAI = new VoiceCloneAI();// Recording and Upload100 unmodified lines<div class="audio-wave w-32 mb-4"></div></div><div class="w-full mb-6"><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></div><div class="w-full bg-gray-900 rounded-xl p-4 mb-4"><h3 class="text-lg font-semibold text-white mb-3">Text-to-Speech Preview</h3><div class="space-y-3"><div class="flex items-center justify-between"><span class="text-gray-300">Ready to read your text</span><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"><i data-feather="play" class="w-4 h-4"></i><span>Play</span></button></div><div class="flex items-center space-x-4"><span class="text-gray-400 text-sm">Progress:</span><div class="flex-1 bg-gray-700 rounded-full h-2"><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></div></div></div></div>`;voiceParams.classList.remove('hidden');5 unmodified linesif (successImage) {successImage.classList.add('floating');}// Add ElevenLabs-like text reading functionalityconst previewPlayBtn = document.getElementById('previewPlayBtn');const playbackProgress = document.getElementById('playbackProgress');const textToGenerate = document.getElementById('textToGenerate');previewPlayBtn.addEventListener('click', async () => {const text = textToGenerate.value.trim();if (!text) {// Show error notificationconst errorNotification = document.createElement('div');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';errorNotification.innerHTML = '⚠️ Please enter text to read';document.body.appendChild(errorNotification);setTimeout(() => errorNotification.remove(), 3000);return;}// Update button statepreviewPlayBtn.disabled = true;previewPlayBtn.innerHTML = '<i data-feather="loader" class="w-4 h-4 animate-spin"></i><span>Generating...</span>';feather.replace();try {// Simulate ElevenLabs-like text readingconst audioBlob = await voiceAI.generateVoice(text, {voice_settings: {stability: 0.7,similarity_boost: 0.8,speed: 1.0}});// Create audio elementconst audioUrl = URL.createObjectURL(audioBlob);const audio = new Audio(audioUrl);// Update button to show playing statepreviewPlayBtn.innerHTML = '<i data-feather="pause" class="w-4 h-4"></i><span>Playing...</span>';feather.replace();// Handle playback progressaudio.addEventListener('timeupdate', () => {const progress = (audio.currentTime / audio.duration) * 100;playbackProgress.style.width = `${progress}%`;});audio.addEventListener('ended', () => {previewPlayBtn.disabled = false;previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';playbackProgress.style.width = '0%';feather.replace();});audio.addEventListener('pause', () => {previewPlayBtn.disabled = false;previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';feather.replace();});// Play audioawait audio.play();// Add pause functionalitypreviewPlayBtn.onclick = () => {if (audio.paused) {audio.play();previewPlayBtn.innerHTML = '<i data-feather="pause" class="w-4 h-4"></i><span>Playing...</span>';} else {audio.pause();previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';}feather.replace();};} catch (error) {console.error('Playback error:', error);previewPlayBtn.disabled = false;previewPlayBtn.innerHTML = '<i data-feather="play" class="w-4 h-4"></i><span>Play</span>';feather.replace();// Show error notificationconst errorNotification = document.createElement('div');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';errorNotification.innerHTML = '❌ Error generating audio';document.body.appendChild(errorNotification);setTimeout(() => errorNotification.remove(), 3000);}});}// Add event listeners for new buttonsdocument.getElementById('trainBtn').addEventListener('click', () => {const recordingStatus = document.getElementById('recordingStatus');recordingStatus.textContent = '🤖 Training AI model...';43 unmodified linesconst emotion = document.querySelector('input[type="range"]:nth-child(2)').value;const speed = document.querySelector('input[type="range"]:nth-child(3)').value;// Generate voice with advanced AI (ElevenLabs-like)const audioBlob = await voiceAI.generateVoice(text, {voice_settings: {stability: similarity / 100,5 unmodified lines// Create audio element and playconst audioUrl = URL.createObjectURL(audioBlob);const audio = new Audio(audioUrl);// Add download functionalityconst downloadBtn = document.getElementById('downloadBtn');const originalOnClick = downloadBtn.onclick;downloadBtn.onclick = () => {const a = document.createElement('a');a.href = audioUrl;a.download = `voice-clone-${Date.now()}.mp3`;a.click();// Show download success notificationconst downloadNotification = document.createElement('div');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';downloadNotification.innerHTML = '✅ Audio downloaded!';document.body.appendChild(downloadNotification);setTimeout(() => downloadNotification.remove(), 3000);};// Play the audioawait audio.play();generatingNotification.innerHTML = '✅ AI Voice generated successfully! Playing now...';setTimeout(() => {generatingNotification.remove();
index.html+243-44