Offex commited on
Commit
1fff061
Β·
verified Β·
1 Parent(s): 61ecce0

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +363 -129
index.html CHANGED
@@ -3,12 +3,12 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Cartesia AI TTS Tool</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <style>
9
  @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;600;700&display=swap');
10
  body {
11
- font-family: 'Plus Jakarta Sans', sans-serif;
12
  background-color: #050505;
13
  color: #ffffff;
14
  }
@@ -17,107 +17,185 @@
17
  border: 1px solid #333;
18
  backdrop-filter: blur(10px);
19
  }
20
- .status-pill {
21
- padding: 2px 8px;
22
- border-radius: 99px;
23
- font-size: 0.7rem;
24
- font-weight: bold;
25
- text-transform: uppercase;
26
- }
27
  .pulse-red { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); animation: pulse-red 2s infinite; }
28
  @keyframes pulse-red { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  </style>
30
  </head>
31
  <body class="p-4 md:p-10 min-h-screen">
32
- <div class="max-w-5xl mx-auto">
33
- <!-- Header Section -->
34
  <div class="flex flex-col md:flex-row justify-between items-center mb-10 gap-4">
35
  <div>
36
  <h1 class="text-4xl font-extrabold tracking-tight text-white">Cartesia <span class="text-blue-500">AI</span></h1>
37
- <p class="text-gray-400">High-performance text-to-speech engine</p>
38
  </div>
39
- <div class="flex items-center gap-3 cartesia-card p-2 px-4 rounded-full">
40
- <span id="statusDot" class="h-3 w-3 rounded-full bg-red-500 pulse-red"></span>
41
- <span id="statusText" class="text-sm font-medium text-gray-300 uppercase tracking-widest">Disconnected</span>
 
 
 
 
 
 
42
  </div>
43
  </div>
44
 
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
59
- </h2>
60
  <div class="space-y-4">
61
  <div>
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
 
 
77
  <div class="cartesia-card p-6 rounded-3xl">
78
- <h2 class="text-lg font-bold mb-4 flex items-center gap-2">
79
- <span>πŸŽ™οΈ</span> Voice Engine
80
- </h2>
81
  <div class="space-y-4">
82
  <div>
83
- <label class="block text-xs font-bold text-gray-500 mb-1">CHOOSE VOICE</label>
84
  <select id="voiceSelect" class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm outline-none focus:border-blue-500">
85
- <option value="">Select a voice...</option>
86
  </select>
87
  </div>
88
  <div>
89
  <label class="block text-xs font-bold text-gray-500 mb-1">CUSTOM VOICE ID</label>
90
- <input type="text" id="customVoiceId" placeholder="Paste Voice ID here..."
91
  class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm outline-none focus:border-blue-500">
92
  </div>
93
  </div>
94
  </div>
95
  </div>
96
 
97
- <!-- Right Column: Workspace -->
98
  <div class="lg:col-span-8 space-y-6">
99
- <!-- Message Output Box -->
100
  <div id="logBox" class="hidden cartesia-card p-4 rounded-2xl text-sm border-l-4">
101
  <p id="logMessage"></p>
102
  </div>
103
 
104
- <div class="cartesia-card p-8 rounded-3xl">
105
- <label class="block text-xs font-bold text-gray-500 mb-2 uppercase tracking-widest text-center">Your Script</label>
106
- <textarea id="textInput" rows="6" placeholder="Yahan apna text likhen..."
107
- class="w-full bg-transparent border-b border-gray-800 text-2xl text-center focus:border-blue-500 outline-none transition-all resize-none mb-8"></textarea>
108
-
109
- <div class="flex flex-col items-center gap-6">
110
- <button id="generateBtn" class="bg-blue-600 hover:bg-blue-500 text-white px-10 py-4 rounded-full font-bold text-lg shadow-lg shadow-blue-900/40 disabled:opacity-50 transition-all flex items-center gap-2">
111
- <span id="btnIcon">⚑</span> <span id="btnText">Convert to Speech</span>
112
- </button>
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>
@@ -126,6 +204,7 @@
126
  </div>
127
 
128
  <script>
 
129
  const apiKeyInput = document.getElementById('apiKey');
130
  const connectBtn = document.getElementById('connectBtn');
131
  const voiceSelect = document.getElementById('voiceSelect');
@@ -143,24 +222,43 @@
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
  }
@@ -171,58 +269,58 @@
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');
193
- logMessage.textContent = msg;
194
- if (type === 'error') {
195
- logBox.className = "cartesia-card p-4 rounded-2xl text-sm border-l-4 border-red-500 text-red-400";
196
- } else if (type === 'success') {
197
- logBox.className = "cartesia-card p-4 rounded-2xl text-sm border-l-4 border-green-500 text-green-400";
198
- } else {
199
- logBox.className = "cartesia-card p-4 rounded-2xl text-sm border-l-4 border-blue-500 text-blue-400";
200
- }
201
- }
202
-
203
  async function fetchVoices() {
204
  const key = apiKeyInput.value.trim();
205
- if (!key) return updateLog("Pehle API Key daalen", "error");
206
 
207
  connectBtn.disabled = true;
208
  connectBtn.textContent = "Connecting...";
209
 
210
  try {
211
- const response = await fetch(`${CARTESIA_API_URL}/voices`, {
 
212
  headers: {
213
  "X-API-Key": key,
214
  "Cartesia-Version": "2024-06-10"
215
  }
216
  });
217
 
218
- if (!response.ok) throw new Error("API Key galat hai ya expiry ho gayi hai.");
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');
228
  option.value = voice.id;
@@ -230,9 +328,28 @@
230
  voiceSelect.appendChild(option);
231
  });
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) {
@@ -247,18 +364,158 @@
247
 
248
  connectBtn.addEventListener('click', fetchVoices);
249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  generateBtn.addEventListener('click', async () => {
251
  const key = apiKeyInput.value.trim();
252
  const voiceId = customVoiceId.value.trim() || voiceSelect.value;
253
  const text = textInput.value.trim();
254
 
255
  if (!key) return updateLog("API Key missing!", "error");
256
- if (!voiceId) return updateLog("Koi voice select karen ya custom ID daalen", "error");
257
- if (!text) return updateLog("Kuch text to likhen!", "error");
258
 
259
  generateBtn.disabled = true;
260
- document.getElementById('btnText').textContent = "Processing...";
261
- document.getElementById('btnIcon').textContent = "βŒ›";
262
  audioArea.classList.add('hidden');
263
 
264
  try {
@@ -272,71 +529,48 @@
272
  body: JSON.stringify({
273
  model_id: "sonic-english",
274
  transcript: text,
275
- voice: {
276
- mode: "id",
277
- id: voiceId
278
- },
279
- output_format: {
280
- container: "wav",
281
- encoding: "pcm_f32le",
282
- sample_rate: 44100
283
- }
284
  })
285
  });
286
 
287
- if (!response.ok) {
288
- const errorData = await response.json();
289
- throw new Error(errorData.message || "TTS generation failed");
290
- }
291
 
292
  const blob = await response.blob();
293
- const url = URL.createObjectURL(blob);
294
- audioPlayer.src = url;
295
  audioArea.classList.remove('hidden');
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 {
308
  generateBtn.disabled = false;
309
- document.getElementById('btnText').textContent = "Convert to Speech";
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>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Cartesia AI TTS + Voice Clone</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <style>
9
  @import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;600;700&display=swap');
10
  body {
11
+ font-family: 'Plus Jakarta+Sans', sans-serif;
12
  background-color: #050505;
13
  color: #ffffff;
14
  }
 
17
  border: 1px solid #333;
18
  backdrop-filter: blur(10px);
19
  }
 
 
 
 
 
 
 
20
  .pulse-red { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); animation: pulse-red 2s infinite; }
21
  @keyframes pulse-red { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
22
+ .tab-btn { padding: 12px 20px; border: none; background: rgba(50,50,50,0.5); color: #999; cursor: pointer; transition: all 0.3s; border-bottom: 2px solid transparent; }
23
+ .tab-btn.active { background: rgba(70,70,70,0.7); color: #fff; border-bottom-color: #3b82f6; }
24
+ .tab-content { display: none; }
25
+ .tab-content.active { display: block; }
26
+ .credit-badge {
27
+ display: inline-block;
28
+ padding: 6px 14px;
29
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
30
+ border-radius: 20px;
31
+ font-size: 0.75rem;
32
+ font-weight: bold;
33
+ }
34
+ .upload-drag {
35
+ border: 2px dashed #374151;
36
+ border-radius: 1rem;
37
+ padding: 2rem;
38
+ text-align: center;
39
+ cursor: pointer;
40
+ transition: all 0.3s;
41
+ }
42
+ .upload-drag.dragover {
43
+ border-color: #3b82f6;
44
+ background: rgba(59, 130, 246, 0.1);
45
+ }
46
  </style>
47
  </head>
48
  <body class="p-4 md:p-10 min-h-screen">
49
+ <div class="max-w-6xl mx-auto">
50
+ <!-- Header -->
51
  <div class="flex flex-col md:flex-row justify-between items-center mb-10 gap-4">
52
  <div>
53
  <h1 class="text-4xl font-extrabold tracking-tight text-white">Cartesia <span class="text-blue-500">AI</span></h1>
54
+ <p class="text-gray-400">TTS + Voice Cloning 🎀</p>
55
  </div>
56
+ <div class="space-y-2">
57
+ <div class="flex items-center gap-3 cartesia-card p-2 px-4 rounded-full">
58
+ <span id="statusDot" class="h-3 w-3 rounded-full bg-red-500 pulse-red"></span>
59
+ <span id="statusText" class="text-sm font-medium text-gray-300 uppercase">Disconnected</span>
60
+ </div>
61
+ <div id="creditArea" class="hidden text-right">
62
+ <p class="text-xs text-gray-500 mb-1">Credits:</p>
63
+ <div class="credit-badge" id="creditBadge">Loading...</div>
64
+ </div>
65
  </div>
66
  </div>
67
 
68
  <div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
69
+ <!-- Left Column -->
70
  <div class="lg:col-span-4 space-y-6">
71
+ <!-- API Settings -->
 
 
 
 
 
 
 
72
  <div class="cartesia-card p-6 rounded-3xl">
73
+ <h2 class="text-lg font-bold mb-4">πŸ”‘ API Settings</h2>
 
 
74
  <div class="space-y-4">
75
  <div>
76
  <label class="block text-xs font-bold text-gray-500 mb-1">API KEY</label>
77
  <input type="password" id="apiKey" placeholder="sk_car_..."
78
+ class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm focus:border-blue-500 outline-none">
79
  <div class="flex gap-2 mt-2">
80
  <button id="toggleShowKey" class="text-xs text-gray-500 hover:text-gray-300 flex-1">πŸ‘οΈ Show</button>
81
  <button id="clearKeyBtn" class="text-xs text-gray-500 hover:text-red-400 flex-1">❌ Clear</button>
82
  </div>
83
  </div>
84
+ <button id="connectBtn" class="w-full bg-white text-black font-bold py-3 rounded-xl hover:bg-gray-200">
85
  Connect Account
86
  </button>
87
+ <p id="savedKeyIndicator" class="text-xs text-green-500 hidden">βœ“ Connected</p>
88
  </div>
89
  </div>
90
 
91
+ <!-- Voice Selection -->
92
  <div class="cartesia-card p-6 rounded-3xl">
93
+ <h2 class="text-lg font-bold mb-4">πŸŽ™οΈ Voice Engine</h2>
 
 
94
  <div class="space-y-4">
95
  <div>
96
+ <label class="block text-xs font-bold text-gray-500 mb-1">SELECT VOICE</label>
97
  <select id="voiceSelect" class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm outline-none focus:border-blue-500">
98
+ <option value="">Select...</option>
99
  </select>
100
  </div>
101
  <div>
102
  <label class="block text-xs font-bold text-gray-500 mb-1">CUSTOM VOICE ID</label>
103
+ <input type="text" id="customVoiceId" placeholder="Voice ID..."
104
  class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm outline-none focus:border-blue-500">
105
  </div>
106
  </div>
107
  </div>
108
  </div>
109
 
110
+ <!-- Right Column - Tabs -->
111
  <div class="lg:col-span-8 space-y-6">
112
+ <!-- Log -->
113
  <div id="logBox" class="hidden cartesia-card p-4 rounded-2xl text-sm border-l-4">
114
  <p id="logMessage"></p>
115
  </div>
116
 
117
+ <!-- Tabs -->
118
+ <div class="cartesia-card rounded-3xl overflow-hidden">
119
+ <div class="flex border-b border-gray-800">
120
+ <button class="tab-btn active" data-tab="tts">⚑ Text to Speech</button>
121
+ <button class="tab-btn" data-tab="clone">🎀 Voice Clone</button>
122
+ </div>
 
 
 
123
 
124
+ <!-- TTS Tab -->
125
+ <div id="tts-tab" class="tab-content active p-8">
126
+ <label class="block text-xs font-bold text-gray-500 mb-2 text-center">YOUR TEXT</label>
127
+ <textarea id="textInput" rows="6" placeholder="Yahan likhen..."
128
+ class="w-full bg-transparent border-b border-gray-800 text-2xl text-center focus:border-blue-500 outline-none resize-none mb-8"></textarea>
129
+
130
+ <div class="flex flex-col items-center gap-6">
131
+ <button id="generateBtn" class="bg-blue-600 hover:bg-blue-500 text-white px-10 py-4 rounded-full font-bold text-lg shadow-lg shadow-blue-900/40 disabled:opacity-50">
132
+ <span id="btnIcon">⚑</span> Convert to Speech
133
+ </button>
134
+
135
+ <div id="audioArea" class="w-full hidden text-center">
136
+ <audio id="audioPlayer" controls class="w-full"></audio>
137
+ <div class="flex gap-2 justify-center mt-3">
138
+ <button id="downloadBtn" class="text-xs bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded">⬇️ Download</button>
139
+ <button id="shareBtn" class="text-xs bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded">πŸ“‹ Copy</button>
140
+ </div>
141
+ </div>
142
+ </div>
143
+ </div>
144
+
145
+ <!-- Clone Tab -->
146
+ <div id="clone-tab" class="tab-content p-8">
147
+ <div class="space-y-6">
148
+ <!-- Audio Upload -->
149
+ <div>
150
+ <label class="block text-xs font-bold text-gray-500 mb-3">πŸ“ AUDIO SAMPLE (30+ secs)</label>
151
+ <div class="upload-drag" id="uploadArea">
152
+ <input type="file" id="audioFile" accept="audio/*" class="hidden">
153
+ <p class="text-sm text-gray-400 mb-2">Click ya drag karo</p>
154
+ <p class="text-xs text-gray-600">WAV, MP3, 30-60 secs</p>
155
+ <div id="uploadedFileName" class="mt-2 text-xs text-green-400 hidden">βœ“ Selected</div>
156
+ </div>
157
+ </div>
158
+
159
+ <!-- BG Noise -->
160
+ <label class="flex items-center gap-2 cursor-pointer">
161
+ <input type="checkbox" id="removeNoise" class="w-4 h-4">
162
+ <span class="text-sm text-gray-400">πŸ”‡ Remove Background Noise</span>
163
+ </label>
164
+
165
+ <!-- Voice Name -->
166
+ <div>
167
+ <label class="block text-xs font-bold text-gray-500 mb-2">VOICE NAME</label>
168
+ <input type="text" id="voiceName" placeholder="MyVoice, Deepu, etc..."
169
+ class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm outline-none focus:border-blue-500">
170
+ </div>
171
+
172
+ <!-- Create Button -->
173
+ <button id="cloneBtn" class="w-full bg-purple-600 hover:bg-purple-500 text-white px-6 py-3 rounded-xl font-bold text-sm shadow-lg shadow-purple-900/40 disabled:opacity-50">
174
+ 🎀 Create Voice
175
+ </button>
176
+
177
+ <!-- Test Text -->
178
+ <div>
179
+ <label class="block text-xs font-bold text-gray-500 mb-2">TEST TEXT</label>
180
+ <textarea id="testText" rows="3" placeholder="Test karne ke liye..."
181
+ class="w-full bg-black border border-gray-800 rounded-xl p-3 text-sm outline-none focus:border-blue-500 resize-none"></textarea>
182
+ </div>
183
+
184
+ <button id="testVoiceBtn" class="w-full bg-green-600 hover:bg-green-500 text-white px-6 py-3 rounded-xl font-bold text-sm shadow-lg disabled:opacity-50">
185
+ ▢️ Test Voice
186
+ </button>
187
+
188
+ <div id="testAudioArea" class="hidden text-center">
189
+ <audio id="testAudioPlayer" controls class="w-full"></audio>
190
+ <p class="text-xs text-gray-500 mt-2">Apka cloned voice!</p>
191
+ </div>
192
+
193
+ <!-- Voice Details -->
194
+ <div id="voiceDetailsArea" class="hidden bg-gray-900 p-4 rounded-lg border border-gray-800">
195
+ <p class="text-xs text-green-400 mb-2">βœ“ VOICE CREATED!</p>
196
+ <p class="text-sm text-gray-300 mb-2">ID: <code id="clonedVoiceId" class="bg-black px-2 py-1 rounded text-xs">...</code></p>
197
+ <button id="copyVoiceIdBtn" class="text-xs text-gray-400 hover:text-gray-200">πŸ“‹ Copy ID</button>
198
  </div>
 
199
  </div>
200
  </div>
201
  </div>
 
204
  </div>
205
 
206
  <script>
207
+ // Elements
208
  const apiKeyInput = document.getElementById('apiKey');
209
  const connectBtn = document.getElementById('connectBtn');
210
  const voiceSelect = document.getElementById('voiceSelect');
 
222
  const savedKeyIndicator = document.getElementById('savedKeyIndicator');
223
  const downloadBtn = document.getElementById('downloadBtn');
224
  const shareBtn = document.getElementById('shareBtn');
225
+ const creditArea = document.getElementById('creditArea');
226
+ const creditBadge = document.getElementById('creditBadge');
227
+
228
+ // Clone elements
229
+ const uploadArea = document.getElementById('uploadArea');
230
+ const audioFile = document.getElementById('audioFile');
231
+ const uploadedFileName = document.getElementById('uploadedFileName');
232
+ const removeNoise = document.getElementById('removeNoise');
233
+ const voiceName = document.getElementById('voiceName');
234
+ const cloneBtn = document.getElementById('cloneBtn');
235
+ const testText = document.getElementById('testText');
236
+ const testVoiceBtn = document.getElementById('testVoiceBtn');
237
+ const testAudioArea = document.getElementById('testAudioArea');
238
+ const testAudioPlayer = document.getElementById('testAudioPlayer');
239
+ const voiceDetailsArea = document.getElementById('voiceDetailsArea');
240
+ const clonedVoiceId = document.getElementById('clonedVoiceId');
241
+ const copyVoiceIdBtn = document.getElementById('copyVoiceIdBtn');
242
+
243
+ // Constants
244
  const CARTESIA_API_URL = "https://api.cartesia.ai";
245
  const STORAGE_KEY = "cartesia_api_key";
246
+ let currentClonedVoiceId = null;
247
+
248
+ // Tab switching
249
+ document.querySelectorAll('.tab-btn').forEach(btn => {
250
+ btn.addEventListener('click', () => {
251
+ document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
252
+ document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
253
+ btn.classList.add('active');
254
+ document.getElementById(btn.dataset.tab + '-tab').classList.add('active');
255
+ });
256
+ });
257
 
258
+ // Initialize
259
  function initializeApp() {
260
  const savedKey = localStorage.getItem(STORAGE_KEY);
261
+ if (savedKey) {
 
 
 
 
 
 
 
 
 
262
  apiKeyInput.value = savedKey;
263
  showSavedIndicator();
264
  }
 
269
  setTimeout(() => savedKeyIndicator.classList.add('hidden'), 3000);
270
  }
271
 
272
+ function updateLog(msg, type = 'info') {
273
+ logBox.classList.remove('hidden');
274
+ logMessage.textContent = msg;
275
+ if (type === 'error') {
276
+ logBox.className = "cartesia-card p-4 rounded-2xl text-sm border-l-4 border-red-500 text-red-400";
277
+ } else if (type === 'success') {
278
+ logBox.className = "cartesia-card p-4 rounded-2xl text-sm border-l-4 border-green-500 text-green-400";
279
+ } else {
280
+ logBox.className = "cartesia-card p-4 rounded-2xl text-sm border-l-4 border-blue-500 text-blue-400";
281
+ }
282
+ }
283
+
284
+ // Toggle key visibility
285
  toggleShowKey.addEventListener('click', () => {
286
  const type = apiKeyInput.type === 'password' ? 'text' : 'password';
287
  apiKeyInput.type = type;
288
  toggleShowKey.textContent = type === 'password' ? 'πŸ‘οΈ Show' : 'πŸ‘οΈ Hide';
289
  });
290
 
291
+ // Clear key
292
  clearKeyBtn.addEventListener('click', () => {
293
  apiKeyInput.value = '';
294
  localStorage.removeItem(STORAGE_KEY);
295
+ updateLog("API Key clear!", "info");
296
  statusDot.className = "h-3 w-3 rounded-full bg-red-500 pulse-red";
297
  statusText.textContent = "DISCONNECTED";
298
+ creditArea.classList.add('hidden');
299
  });
300
 
301
+ // Connect and fetch voices + credits
 
 
 
 
 
 
 
 
 
 
 
302
  async function fetchVoices() {
303
  const key = apiKeyInput.value.trim();
304
+ if (!key) return updateLog("API Key daalo pehle", "error");
305
 
306
  connectBtn.disabled = true;
307
  connectBtn.textContent = "Connecting...";
308
 
309
  try {
310
+ // Fetch voices
311
+ const voicesResponse = await fetch(`${CARTESIA_API_URL}/voices`, {
312
  headers: {
313
  "X-API-Key": key,
314
  "Cartesia-Version": "2024-06-10"
315
  }
316
  });
317
 
318
+ if (!voicesResponse.ok) throw new Error("API Key invalid!");
319
 
320
+ const voices = await voicesResponse.json();
 
 
321
  localStorage.setItem(STORAGE_KEY, key);
322
 
323
+ voiceSelect.innerHTML = '<option value="">Select voice...</option>';
324
  voices.forEach(voice => {
325
  const option = document.createElement('option');
326
  option.value = voice.id;
 
328
  voiceSelect.appendChild(option);
329
  });
330
 
331
+ // Fetch credits
332
+ try {
333
+ const creditsResponse = await fetch(`${CARTESIA_API_URL}/account/billing/credits`, {
334
+ headers: {
335
+ "X-API-Key": key,
336
+ "Cartesia-Version": "2024-06-10"
337
+ }
338
+ });
339
+
340
+ if (creditsResponse.ok) {
341
+ const creditsData = await creditsResponse.json();
342
+ const credits = creditsData.credits || creditsData.remaining_credits || 0;
343
+ creditBadge.textContent = `β‚Ή ${(credits / 1000).toFixed(2)}K`;
344
+ creditArea.classList.remove('hidden');
345
+ }
346
+ } catch (e) {
347
+ console.log("Credits fetch failed");
348
+ }
349
+
350
  statusDot.className = "h-3 w-3 rounded-full bg-green-500 shadow-lg shadow-green-900";
351
  statusText.textContent = "CONNECTED";
352
+ updateLog("Connected! Voices loaded!", "success");
353
  showSavedIndicator();
354
 
355
  } catch (err) {
 
364
 
365
  connectBtn.addEventListener('click', fetchVoices);
366
 
367
+ // File upload
368
+ uploadArea.addEventListener('click', () => audioFile.click());
369
+ uploadArea.addEventListener('dragover', (e) => {
370
+ e.preventDefault();
371
+ uploadArea.classList.add('dragover');
372
+ });
373
+ uploadArea.addEventListener('dragleave', () => {
374
+ uploadArea.classList.remove('dragover');
375
+ });
376
+ uploadArea.addEventListener('drop', (e) => {
377
+ e.preventDefault();
378
+ uploadArea.classList.remove('dragover');
379
+ audioFile.files = e.dataTransfer.files;
380
+ if (audioFile.files.length) {
381
+ uploadedFileName.classList.remove('hidden');
382
+ uploadedFileName.textContent = `βœ“ ${audioFile.files[0].name}`;
383
+ }
384
+ });
385
+
386
+ audioFile.addEventListener('change', () => {
387
+ if (audioFile.files.length) {
388
+ uploadedFileName.classList.remove('hidden');
389
+ uploadedFileName.textContent = `βœ“ ${audioFile.files[0].name}`;
390
+ }
391
+ });
392
+
393
+ // Clone voice
394
+ cloneBtn.addEventListener('click', async () => {
395
+ const key = apiKeyInput.value.trim();
396
+ const name = voiceName.value.trim();
397
+ const file = audioFile.files[0];
398
+
399
+ if (!key) return updateLog("API Key missing!", "error");
400
+ if (!file) return updateLog("Audio file select karo", "error");
401
+ if (!name) return updateLog("Voice ko name do", "error");
402
+
403
+ cloneBtn.disabled = true;
404
+ cloneBtn.textContent = "⏳ Creating...";
405
+
406
+ try {
407
+ const reader = new FileReader();
408
+ reader.onload = async (e) => {
409
+ const base64Audio = btoa(String.fromCharCode.apply(null, new Uint8Array(e.target.result)));
410
+
411
+ const body = {
412
+ name: name,
413
+ samples: [{
414
+ text: "This is a voice sample",
415
+ audio: base64Audio
416
+ }]
417
+ };
418
+
419
+ if (removeNoise.checked) {
420
+ body.enhance_audio = true;
421
+ }
422
+
423
+ const response = await fetch(`${CARTESIA_API_URL}/voices/clone`, {
424
+ method: 'POST',
425
+ headers: {
426
+ "X-API-Key": key,
427
+ "Cartesia-Version": "2024-06-10",
428
+ "Content-Type": "application/json"
429
+ },
430
+ body: JSON.stringify(body)
431
+ });
432
+
433
+ if (!response.ok) {
434
+ const error = await response.json();
435
+ throw new Error(error.message || "Clone failed");
436
+ }
437
+
438
+ const voiceData = await response.json();
439
+ currentClonedVoiceId = voiceData.id;
440
+ clonedVoiceId.textContent = voiceData.id;
441
+ voiceDetailsArea.classList.remove('hidden');
442
+ customVoiceId.value = voiceData.id;
443
+ updateLog("βœ“ Voice cloned! Test kar sakte ho!", "success");
444
+ };
445
+ reader.readAsArrayBuffer(file);
446
+
447
+ } catch (err) {
448
+ updateLog(err.message, "error");
449
+ } finally {
450
+ cloneBtn.disabled = false;
451
+ cloneBtn.textContent = "🎀 Create Voice";
452
+ }
453
+ });
454
+
455
+ // Copy voice ID
456
+ copyVoiceIdBtn.addEventListener('click', () => {
457
+ navigator.clipboard.writeText(currentClonedVoiceId);
458
+ copyVoiceIdBtn.textContent = "βœ“ Copied!";
459
+ setTimeout(() => copyVoiceIdBtn.textContent = "πŸ“‹ Copy ID", 2000);
460
+ });
461
+
462
+ // Test voice
463
+ testVoiceBtn.addEventListener('click', async () => {
464
+ const key = apiKeyInput.value.trim();
465
+ const voiceId = customVoiceId.value.trim() || voiceSelect.value;
466
+ const text = testText.value.trim();
467
+
468
+ if (!key) return updateLog("API Key missing!", "error");
469
+ if (!voiceId) return updateLog("Voice select karo", "error");
470
+ if (!text) return updateLog("Text likho", "error");
471
+
472
+ testVoiceBtn.disabled = true;
473
+ testVoiceBtn.textContent = "⏳ Processing...";
474
+
475
+ try {
476
+ const response = await fetch(`${CARTESIA_API_URL}/tts/bytes`, {
477
+ method: 'POST',
478
+ headers: {
479
+ "X-API-Key": key,
480
+ "Cartesia-Version": "2024-06-10",
481
+ "Content-Type": "application/json"
482
+ },
483
+ body: JSON.stringify({
484
+ model_id: "sonic-english",
485
+ transcript: text,
486
+ voice: { mode: "id", id: voiceId },
487
+ output_format: { container: "wav", encoding: "pcm_f32le", sample_rate: 44100 }
488
+ })
489
+ });
490
+
491
+ if (!response.ok) throw new Error("TTS failed");
492
+
493
+ const blob = await response.blob();
494
+ testAudioPlayer.src = URL.createObjectURL(blob);
495
+ testAudioArea.classList.remove('hidden');
496
+ updateLog("Test audio ready!", "success");
497
+ testAudioPlayer.play();
498
+
499
+ } catch (err) {
500
+ updateLog(err.message, "error");
501
+ } finally {
502
+ testVoiceBtn.disabled = false;
503
+ testVoiceBtn.textContent = "▢️ Test Voice";
504
+ }
505
+ });
506
+
507
+ // TTS Generation
508
  generateBtn.addEventListener('click', async () => {
509
  const key = apiKeyInput.value.trim();
510
  const voiceId = customVoiceId.value.trim() || voiceSelect.value;
511
  const text = textInput.value.trim();
512
 
513
  if (!key) return updateLog("API Key missing!", "error");
514
+ if (!voiceId) return updateLog("Voice select karo", "error");
515
+ if (!text) return updateLog("Text likho", "error");
516
 
517
  generateBtn.disabled = true;
518
+ generateBtn.textContent = "βŒ› Processing...";
 
519
  audioArea.classList.add('hidden');
520
 
521
  try {
 
529
  body: JSON.stringify({
530
  model_id: "sonic-english",
531
  transcript: text,
532
+ voice: { mode: "id", id: voiceId },
533
+ output_format: { container: "wav", encoding: "pcm_f32le", sample_rate: 44100 }
 
 
 
 
 
 
 
534
  })
535
  });
536
 
537
+ if (!response.ok) throw new Error("TTS failed");
 
 
 
538
 
539
  const blob = await response.blob();
540
+ audioPlayer.src = URL.createObjectURL(blob);
 
541
  audioArea.classList.remove('hidden');
542
+ updateLog("Audio ready!", "success");
543
  audioPlayer.play();
544
 
 
 
 
 
 
 
545
  } catch (err) {
546
  updateLog(err.message, "error");
547
  } finally {
548
  generateBtn.disabled = false;
549
+ generateBtn.textContent = "⚑ Convert to Speech";
 
550
  }
551
  });
552
 
553
+ // Download
554
  downloadBtn.addEventListener('click', () => {
555
  const src = audioPlayer.src;
556
  if (!src) return;
 
557
  const a = document.createElement('a');
558
  a.href = src;
559
+ a.download = `audio-${Date.now()}.wav`;
 
560
  a.click();
561
+ updateLog("Download started!", "success");
 
562
  });
563
 
564
+ // Share
565
  shareBtn.addEventListener('click', () => {
566
  const src = audioPlayer.src;
567
  if (!src) return;
 
568
  navigator.clipboard.writeText(src);
569
+ updateLog("Link copied!", "success");
570
  shareBtn.textContent = "βœ“ Copied!";
571
+ setTimeout(() => shareBtn.textContent = "πŸ“‹ Copy", 2000);
572
  });
573
 
 
574
  window.addEventListener('load', initializeApp);
575
  </script>
576
  </body>