Update index.html
Browse files- index.html +104 -4
index.html
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="hi">
|
| 4 |
<head>
|
|
@@ -46,6 +45,14 @@
|
|
| 46 |
<div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
|
| 47 |
<!-- Left Column: Settings -->
|
| 48 |
<div class="lg:col-span-4 space-y-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
<div class="cartesia-card p-6 rounded-3xl">
|
| 50 |
<h2 class="text-lg font-bold mb-4 flex items-center gap-2">
|
| 51 |
<span>π</span> API Settings
|
|
@@ -55,10 +62,15 @@
|
|
| 55 |
<label class="block text-xs font-bold text-gray-500 mb-1">API KEY</label>
|
| 56 |
<input type="password" id="apiKey" placeholder="sk_car_..."
|
| 57 |
class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm focus:border-blue-500 outline-none transition-all">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
</div>
|
| 59 |
<button id="connectBtn" class="w-full bg-white text-black font-bold py-3 rounded-xl hover:bg-gray-200 transition-colors">
|
| 60 |
Connect Account
|
| 61 |
</button>
|
|
|
|
| 62 |
</div>
|
| 63 |
</div>
|
| 64 |
|
|
@@ -101,7 +113,11 @@
|
|
| 101 |
|
| 102 |
<div id="audioArea" class="w-full hidden text-center animate-fade-in">
|
| 103 |
<audio id="audioPlayer" controls class="w-full mx-auto"></audio>
|
| 104 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
</div>
|
| 106 |
</div>
|
| 107 |
</div>
|
|
@@ -122,9 +138,55 @@
|
|
| 122 |
const statusText = document.getElementById('statusText');
|
| 123 |
const audioArea = document.getElementById('audioArea');
|
| 124 |
const audioPlayer = document.getElementById('audioPlayer');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
// Cartesia API Base URL
|
| 127 |
const CARTESIA_API_URL = "https://api.cartesia.ai";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
function updateLog(msg, type = 'info') {
|
| 130 |
logBox.classList.remove('hidden');
|
|
@@ -157,6 +219,9 @@
|
|
| 157 |
|
| 158 |
const voices = await response.json();
|
| 159 |
|
|
|
|
|
|
|
|
|
|
| 160 |
voiceSelect.innerHTML = '<option value="">Select a voice...</option>';
|
| 161 |
voices.forEach(voice => {
|
| 162 |
const option = document.createElement('option');
|
|
@@ -168,6 +233,7 @@
|
|
| 168 |
statusDot.className = "h-3 w-3 rounded-full bg-green-500 shadow-lg shadow-green-900";
|
| 169 |
statusText.textContent = "CONNECTED";
|
| 170 |
updateLog("Account successfully connected! Voices load ho chuki hain.", "success");
|
|
|
|
| 171 |
|
| 172 |
} catch (err) {
|
| 173 |
updateLog(err.message, "error");
|
|
@@ -204,7 +270,7 @@
|
|
| 204 |
"Content-Type": "application/json"
|
| 205 |
},
|
| 206 |
body: JSON.stringify({
|
| 207 |
-
model_id: "sonic-english",
|
| 208 |
transcript: text,
|
| 209 |
voice: {
|
| 210 |
mode: "id",
|
|
@@ -230,6 +296,12 @@
|
|
| 230 |
updateLog("Audio generate ho gaya!", "success");
|
| 231 |
audioPlayer.play();
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
} catch (err) {
|
| 234 |
updateLog(err.message, "error");
|
| 235 |
} finally {
|
|
@@ -238,6 +310,34 @@
|
|
| 238 |
document.getElementById('btnIcon').textContent = "β‘";
|
| 239 |
}
|
| 240 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
</script>
|
| 242 |
</body>
|
| 243 |
-
</html>
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="hi">
|
| 3 |
<head>
|
|
|
|
| 45 |
<div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
|
| 46 |
<!-- Left Column: Settings -->
|
| 47 |
<div class="lg:col-span-4 space-y-6">
|
| 48 |
+
<!-- HF Spaces Info -->
|
| 49 |
+
<div class="cartesia-card p-4 rounded-2xl border-l-4 border-amber-500">
|
| 50 |
+
<p class="text-xs text-amber-400 font-bold mb-2">π HUGGING FACE SETUP</p>
|
| 51 |
+
<p class="text-xs text-gray-300 leading-relaxed">
|
| 52 |
+
HF Spaces mein "Secrets" section se API Key add karo variable name: <code class="bg-black px-2 py-1 rounded text-amber-400">CARTESIA_API_KEY</code>
|
| 53 |
+
</p>
|
| 54 |
+
</div>
|
| 55 |
+
|
| 56 |
<div class="cartesia-card p-6 rounded-3xl">
|
| 57 |
<h2 class="text-lg font-bold mb-4 flex items-center gap-2">
|
| 58 |
<span>π</span> API Settings
|
|
|
|
| 62 |
<label class="block text-xs font-bold text-gray-500 mb-1">API KEY</label>
|
| 63 |
<input type="password" id="apiKey" placeholder="sk_car_..."
|
| 64 |
class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm focus:border-blue-500 outline-none transition-all">
|
| 65 |
+
<div class="flex gap-2 mt-2">
|
| 66 |
+
<button id="toggleShowKey" class="text-xs text-gray-500 hover:text-gray-300 flex-1">ποΈ Show</button>
|
| 67 |
+
<button id="clearKeyBtn" class="text-xs text-gray-500 hover:text-red-400 flex-1">β Clear</button>
|
| 68 |
+
</div>
|
| 69 |
</div>
|
| 70 |
<button id="connectBtn" class="w-full bg-white text-black font-bold py-3 rounded-xl hover:bg-gray-200 transition-colors">
|
| 71 |
Connect Account
|
| 72 |
</button>
|
| 73 |
+
<p id="savedKeyIndicator" class="text-xs text-green-500 hidden">β API Key saved locally</p>
|
| 74 |
</div>
|
| 75 |
</div>
|
| 76 |
|
|
|
|
| 113 |
|
| 114 |
<div id="audioArea" class="w-full hidden text-center animate-fade-in">
|
| 115 |
<audio id="audioPlayer" controls class="w-full mx-auto"></audio>
|
| 116 |
+
<div class="flex gap-2 justify-center mt-3">
|
| 117 |
+
<button id="downloadBtn" class="text-xs bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded">β¬οΈ Download</button>
|
| 118 |
+
<button id="shareBtn" class="text-xs bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded">π Copy Link</button>
|
| 119 |
+
</div>
|
| 120 |
+
<p class="text-xs text-gray-500 mt-2">Audio ready! Play karo ya download karo</p>
|
| 121 |
</div>
|
| 122 |
</div>
|
| 123 |
</div>
|
|
|
|
| 138 |
const statusText = document.getElementById('statusText');
|
| 139 |
const audioArea = document.getElementById('audioArea');
|
| 140 |
const audioPlayer = document.getElementById('audioPlayer');
|
| 141 |
+
const toggleShowKey = document.getElementById('toggleShowKey');
|
| 142 |
+
const clearKeyBtn = document.getElementById('clearKeyBtn');
|
| 143 |
+
const savedKeyIndicator = document.getElementById('savedKeyIndicator');
|
| 144 |
+
const downloadBtn = document.getElementById('downloadBtn');
|
| 145 |
+
const shareBtn = document.getElementById('shareBtn');
|
| 146 |
|
| 147 |
// Cartesia API Base URL
|
| 148 |
const CARTESIA_API_URL = "https://api.cartesia.ai";
|
| 149 |
+
const STORAGE_KEY = "cartesia_api_key";
|
| 150 |
+
|
| 151 |
+
// Initialize - Load saved API key from localStorage
|
| 152 |
+
function initializeApp() {
|
| 153 |
+
const savedKey = localStorage.getItem(STORAGE_KEY);
|
| 154 |
+
|
| 155 |
+
// Check URL parameters (for Hugging Face integration)
|
| 156 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 157 |
+
const urlKey = urlParams.get('api_key');
|
| 158 |
+
|
| 159 |
+
if (urlKey) {
|
| 160 |
+
apiKeyInput.value = urlKey;
|
| 161 |
+
localStorage.setItem(STORAGE_KEY, urlKey);
|
| 162 |
+
showSavedIndicator();
|
| 163 |
+
} else if (savedKey) {
|
| 164 |
+
apiKeyInput.value = savedKey;
|
| 165 |
+
showSavedIndicator();
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function showSavedIndicator() {
|
| 170 |
+
savedKeyIndicator.classList.remove('hidden');
|
| 171 |
+
setTimeout(() => savedKeyIndicator.classList.add('hidden'), 3000);
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// Toggle password visibility
|
| 175 |
+
toggleShowKey.addEventListener('click', () => {
|
| 176 |
+
const type = apiKeyInput.type === 'password' ? 'text' : 'password';
|
| 177 |
+
apiKeyInput.type = type;
|
| 178 |
+
toggleShowKey.textContent = type === 'password' ? 'ποΈ Show' : 'ποΈ Hide';
|
| 179 |
+
});
|
| 180 |
+
|
| 181 |
+
// Clear stored key
|
| 182 |
+
clearKeyBtn.addEventListener('click', () => {
|
| 183 |
+
apiKeyInput.value = '';
|
| 184 |
+
localStorage.removeItem(STORAGE_KEY);
|
| 185 |
+
updateLog("API Key clear ho gaya", "info");
|
| 186 |
+
statusDot.className = "h-3 w-3 rounded-full bg-red-500 pulse-red";
|
| 187 |
+
statusText.textContent = "DISCONNECTED";
|
| 188 |
+
voiceSelect.innerHTML = '<option value="">Select a voice...</option>';
|
| 189 |
+
});
|
| 190 |
|
| 191 |
function updateLog(msg, type = 'info') {
|
| 192 |
logBox.classList.remove('hidden');
|
|
|
|
| 219 |
|
| 220 |
const voices = await response.json();
|
| 221 |
|
| 222 |
+
// Save API key to localStorage
|
| 223 |
+
localStorage.setItem(STORAGE_KEY, key);
|
| 224 |
+
|
| 225 |
voiceSelect.innerHTML = '<option value="">Select a voice...</option>';
|
| 226 |
voices.forEach(voice => {
|
| 227 |
const option = document.createElement('option');
|
|
|
|
| 233 |
statusDot.className = "h-3 w-3 rounded-full bg-green-500 shadow-lg shadow-green-900";
|
| 234 |
statusText.textContent = "CONNECTED";
|
| 235 |
updateLog("Account successfully connected! Voices load ho chuki hain.", "success");
|
| 236 |
+
showSavedIndicator();
|
| 237 |
|
| 238 |
} catch (err) {
|
| 239 |
updateLog(err.message, "error");
|
|
|
|
| 270 |
"Content-Type": "application/json"
|
| 271 |
},
|
| 272 |
body: JSON.stringify({
|
| 273 |
+
model_id: "sonic-english",
|
| 274 |
transcript: text,
|
| 275 |
voice: {
|
| 276 |
mode: "id",
|
|
|
|
| 296 |
updateLog("Audio generate ho gaya!", "success");
|
| 297 |
audioPlayer.play();
|
| 298 |
|
| 299 |
+
// Store blob for download
|
| 300 |
+
audioPlayer.dataset.blob = JSON.stringify({
|
| 301 |
+
size: blob.size,
|
| 302 |
+
type: blob.type
|
| 303 |
+
});
|
| 304 |
+
|
| 305 |
} catch (err) {
|
| 306 |
updateLog(err.message, "error");
|
| 307 |
} finally {
|
|
|
|
| 310 |
document.getElementById('btnIcon').textContent = "β‘";
|
| 311 |
}
|
| 312 |
});
|
| 313 |
+
|
| 314 |
+
// Download functionality
|
| 315 |
+
downloadBtn.addEventListener('click', () => {
|
| 316 |
+
const src = audioPlayer.src;
|
| 317 |
+
if (!src) return;
|
| 318 |
+
|
| 319 |
+
const a = document.createElement('a');
|
| 320 |
+
a.href = src;
|
| 321 |
+
a.download = `cartesia-audio-${Date.now()}.wav`;
|
| 322 |
+
document.body.appendChild(a);
|
| 323 |
+
a.click();
|
| 324 |
+
document.body.removeChild(a);
|
| 325 |
+
updateLog("Audio download ho raha hai!", "success");
|
| 326 |
+
});
|
| 327 |
+
|
| 328 |
+
// Share functionality
|
| 329 |
+
shareBtn.addEventListener('click', () => {
|
| 330 |
+
const src = audioPlayer.src;
|
| 331 |
+
if (!src) return;
|
| 332 |
+
|
| 333 |
+
navigator.clipboard.writeText(src);
|
| 334 |
+
updateLog("Audio link copy ho gaya clipboard mein!", "success");
|
| 335 |
+
shareBtn.textContent = "β Copied!";
|
| 336 |
+
setTimeout(() => shareBtn.textContent = "π Copy Link", 2000);
|
| 337 |
+
});
|
| 338 |
+
|
| 339 |
+
// Initialize app on load
|
| 340 |
+
window.addEventListener('load', initializeApp);
|
| 341 |
</script>
|
| 342 |
</body>
|
| 343 |
+
</html>
|