Update templates/index.html
Browse files- templates/index.html +529 -312
templates/index.html
CHANGED
@@ -5,173 +5,269 @@
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>PyxiLabs._.Vocify - Text to Speech API</title>
|
7 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
|
8 |
-
<!-- Favicon -->
|
9 |
-
<link rel="icon" href="/static/icon.png" type="image/png">
|
10 |
-
<link rel="icon" href="/static/icon.png" sizes="32x32" type="image/png">
|
11 |
-
<link rel="icon" href="/static/icon.png" sizes="16x16" type="image/png">
|
12 |
-
<link rel="apple-touch-icon" href="/static/icon.png">
|
13 |
-
<link rel="icon" href="/static/icon.png" sizes="192x192">
|
14 |
<style>
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
44 |
-
}
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
color: #fff;
|
64 |
-
backdrop-filter: blur(4px);
|
65 |
-
}
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
transition: all 0.3s ease;
|
81 |
-
}
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
margin-top: 1rem;
|
126 |
-
position: relative;
|
127 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
128 |
-
}
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
width: 100%;
|
146 |
-
height: 100%;
|
147 |
-
background: linear-gradient(90deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.2));
|
148 |
-
animation: shimmer 2s infinite;
|
149 |
-
}
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
</style>
|
|
|
175 |
</head>
|
176 |
<body class="text-white text-shadow">
|
177 |
<div class="container mx-auto px-4 py-8 md:py-12 max-w-6xl relative">
|
@@ -240,28 +336,51 @@
|
|
240 |
Generate Speech
|
241 |
</button>
|
242 |
|
243 |
-
<!-- Loading
|
244 |
-
<div id="loading
|
245 |
-
<div class="
|
246 |
-
<div id="loading-bar" class="loading-bar"></div>
|
247 |
-
</div>
|
248 |
-
<div id="loading-bar-text" class="loading-bar-text">0%</div>
|
249 |
</div>
|
250 |
|
251 |
<!-- Audio Player -->
|
252 |
-
<div id="audio-container" class="mt-6
|
253 |
-
<div class="
|
254 |
-
<
|
255 |
-
|
256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
</div>
|
258 |
</div>
|
259 |
|
260 |
-
<!-- Loading Spinner -->
|
261 |
-
<div id="loading" class="hidden mt-6 md:mt-8 text-center">
|
262 |
-
<div class="inline-block animate-spin rounded-full h-10 w-10 md:h-12 md:w-12 border-4 border-red-500 border-t-transparent"></div>
|
263 |
-
</div>
|
264 |
-
|
265 |
<!-- Error Message -->
|
266 |
<div id="error" class="hidden mt-6 md:mt-8 text-red-400 text-center font-medium glass-effect p-4 md:p-6 rounded-xl">
|
267 |
</div>
|
@@ -292,175 +411,273 @@ Rate Limits (Free Tier):
|
|
292 |
</p>
|
293 |
</footer>
|
294 |
</div>
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
}
|
|
|
|
|
336 |
}
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
}
|
351 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
textInput.addEventListener('input', () => {
|
358 |
-
const length = textInput.value.length;
|
359 |
-
charCount.textContent = `${length}/5000 characters`;
|
360 |
-
|
361 |
-
if (length > 4900) {
|
362 |
-
charCount.classList.add('text-red-400');
|
363 |
-
charCount.classList.remove('white-text');
|
364 |
-
} else {
|
365 |
-
charCount.classList.remove('text-red-400');
|
366 |
-
charCount.classList.add('white-text');
|
367 |
-
}
|
368 |
-
});
|
369 |
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
|
375 |
-
|
376 |
-
|
377 |
-
return;
|
378 |
-
}
|
379 |
|
380 |
-
|
381 |
-
|
|
|
382 |
|
383 |
-
|
|
|
|
|
384 |
loadingBar.style.width = `${progress}%`;
|
385 |
loadingBarText.textContent = `${progress}%`;
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
})
|
405 |
-
});
|
406 |
-
|
407 |
-
clearInterval(intervalId);
|
408 |
-
|
409 |
-
if (!response.ok) {
|
410 |
-
loadingBar.style.width = `100%`;
|
411 |
-
loadingBarText.textContent = `Failed`;
|
412 |
-
throw new Error('Failed to generate speech. Please try again.');
|
413 |
-
}
|
414 |
-
|
415 |
-
const audioBlob = await response.blob();
|
416 |
-
const audioUrl = URL.createObjectURL(audioBlob);
|
417 |
-
|
418 |
loadingBar.style.width = `100%`;
|
419 |
-
loadingBarText.textContent = `
|
420 |
-
|
421 |
-
showAudioPlayer();
|
422 |
-
audioPlayer.play();
|
423 |
-
} catch (err) {
|
424 |
-
showError(err.message);
|
425 |
-
} finally {
|
426 |
-
if (error.classList.contains('hidden')) {
|
427 |
-
setTimeout(hideLoading, 500); // Keep the 100% for a bit if successful
|
428 |
-
} else {
|
429 |
-
hideLoading(); // Hide immediately if there's an error
|
430 |
-
}
|
431 |
}
|
432 |
-
});
|
433 |
-
|
434 |
-
function showLoading() {
|
435 |
-
loadingBarContainer.classList.remove('hidden');
|
436 |
-
loading.classList.remove('hidden');
|
437 |
-
generateBtn.disabled = true;
|
438 |
-
generateBtn.classList.add('opacity-50');
|
439 |
-
}
|
440 |
-
|
441 |
-
function hideLoading() {
|
442 |
-
loadingBarContainer.classList.add('hidden');
|
443 |
-
loading.classList.add('hidden');
|
444 |
-
generateBtn.disabled = false;
|
445 |
-
generateBtn.classList.remove('opacity-50');
|
446 |
-
}
|
447 |
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
}
|
453 |
-
|
454 |
-
|
455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
}
|
457 |
-
|
458 |
-
|
459 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
460 |
}
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
</body>
|
466 |
</html>
|
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>PyxiLabs._.Vocify - Text to Speech API</title>
|
7 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
<style>
|
9 |
+
/* Root Variables */
|
10 |
+
:root {
|
11 |
+
--gradient-start: #ff0066;
|
12 |
+
--gradient-end: #3366ff;
|
13 |
+
}
|
14 |
|
15 |
+
/* Base Styles */
|
16 |
+
body {
|
17 |
+
background-image: url('static/bg3.png');
|
18 |
+
background-size: cover;
|
19 |
+
background-position: center;
|
20 |
+
background-attachment: fixed;
|
21 |
+
min-height: 100vh;
|
22 |
+
}
|
23 |
|
24 |
+
/* Text Effects */
|
25 |
+
.gradient-text {
|
26 |
+
background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
|
27 |
+
-webkit-background-clip: text;
|
28 |
+
background-clip: text;
|
29 |
+
color: transparent;
|
30 |
+
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
31 |
+
}
|
32 |
|
33 |
+
.text-shadow {
|
34 |
+
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
35 |
+
}
|
36 |
|
37 |
+
.white-text {
|
38 |
+
color: rgba(255, 255, 255, 0.9);
|
39 |
+
}
|
|
|
|
|
40 |
|
41 |
+
/* Container Effects */
|
42 |
+
.custom-shadow {
|
43 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
|
44 |
+
}
|
45 |
|
46 |
+
.content-box {
|
47 |
+
background: rgba(0, 0, 0, 0.15);
|
48 |
+
backdrop-filter: blur(8px);
|
49 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
50 |
+
}
|
51 |
|
52 |
+
.glass-effect {
|
53 |
+
background: rgba(0, 0, 0, 0.1);
|
54 |
+
backdrop-filter: blur(8px);
|
55 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
56 |
+
}
|
57 |
|
58 |
+
.hover-scale {
|
59 |
+
transition: transform 0.2s;
|
60 |
+
}
|
|
|
|
|
|
|
61 |
|
62 |
+
.hover-scale:hover {
|
63 |
+
transform: scale(1.02);
|
64 |
+
}
|
65 |
|
66 |
+
/* Form Elements */
|
67 |
+
.input-dark {
|
68 |
+
background: rgba(0, 0, 0, 0.1);
|
69 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
70 |
+
color: #fff;
|
71 |
+
backdrop-filter: blur(4px);
|
72 |
+
}
|
73 |
|
74 |
+
.input-dark::placeholder {
|
75 |
+
color: rgba(255, 255, 255, 0.6);
|
76 |
+
}
|
|
|
|
|
77 |
|
78 |
+
.input-dark:focus {
|
79 |
+
border-color: var(--gradient-start);
|
80 |
+
box-shadow: 0 0 0 2px rgba(255, 0, 102, 0.2);
|
81 |
+
background: rgba(0, 0, 0, 0.15);
|
82 |
+
}
|
83 |
|
84 |
+
select option {
|
85 |
+
background-color: rgba(0, 0, 0, 0.8);
|
86 |
+
color: white;
|
87 |
+
}
|
88 |
|
89 |
+
.gradient-btn {
|
90 |
+
background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
|
91 |
+
backdrop-filter: blur(4px);
|
92 |
+
transition: all 0.3s ease;
|
93 |
+
}
|
94 |
|
95 |
+
.gradient-btn:hover {
|
96 |
+
filter: brightness(1.1);
|
97 |
+
transform: translateY(-2px);
|
98 |
+
background: linear-gradient(45deg, var(--gradient-end), var(--gradient-start));
|
99 |
+
}
|
100 |
|
101 |
+
/* Code Block Styles */
|
102 |
+
pre {
|
103 |
+
background: rgba(0, 0, 0, 0.1) !important;
|
104 |
+
backdrop-filter: blur(4px);
|
105 |
+
white-space: pre-wrap;
|
106 |
+
word-wrap: break-word;
|
107 |
+
}
|
108 |
|
109 |
+
/* Audio Player Styles */
|
110 |
+
.audio-player {
|
111 |
+
background: rgba(0, 0, 0, 0.2);
|
112 |
+
backdrop-filter: blur(10px);
|
113 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
114 |
+
border-radius: 16px;
|
115 |
+
padding: 20px;
|
116 |
+
color: white;
|
117 |
+
}
|
118 |
|
119 |
+
.progress-bar {
|
120 |
+
width: 100%;
|
121 |
+
height: 5px;
|
122 |
+
background: rgba(255, 255, 255, 0.1);
|
123 |
+
border-radius: 10px;
|
124 |
+
cursor: pointer;
|
125 |
+
position: relative;
|
126 |
+
}
|
127 |
|
128 |
+
.progress {
|
129 |
+
height: 100%;
|
130 |
+
background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
|
131 |
+
border-radius: 10px;
|
132 |
+
transition: width 0.1s linear;
|
133 |
+
}
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
.progress-handle {
|
136 |
+
width: 12px;
|
137 |
+
height: 12px;
|
138 |
+
background: white;
|
139 |
+
border-radius: 50%;
|
140 |
+
position: absolute;
|
141 |
+
top: 50%;
|
142 |
+
transform: translate(-50%, -50%);
|
143 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
144 |
+
pointer-events: none;
|
145 |
+
}
|
146 |
|
147 |
+
.time-display {
|
148 |
+
font-family: monospace;
|
149 |
+
font-size: 14px;
|
150 |
+
color: rgba(255, 255, 255, 0.8);
|
151 |
+
}
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
+
.control-button {
|
154 |
+
width: 40px;
|
155 |
+
height: 40px;
|
156 |
+
border-radius: 50%;
|
157 |
+
background: rgba(255, 255, 255, 0.1);
|
158 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
159 |
+
color: white;
|
160 |
+
display: flex;
|
161 |
+
align-items: center;
|
162 |
+
justify-content: center;
|
163 |
+
cursor: pointer;
|
164 |
+
transition: all 0.2s ease;
|
165 |
+
}
|
166 |
|
167 |
+
.control-button:hover {
|
168 |
+
background: rgba(255, 255, 255, 0.2);
|
169 |
+
transform: scale(1.05);
|
170 |
+
}
|
171 |
+
|
172 |
+
.volume-slider {
|
173 |
+
width: 100px;
|
174 |
+
height: 4px;
|
175 |
+
background: rgba(255, 255, 255, 0.1);
|
176 |
+
border-radius: 2px;
|
177 |
+
cursor: pointer;
|
178 |
+
}
|
179 |
+
|
180 |
+
.volume-slider::-webkit-slider-thumb {
|
181 |
+
-webkit-appearance: none;
|
182 |
+
width: 12px;
|
183 |
+
height: 12px;
|
184 |
+
background: white;
|
185 |
+
border-radius: 50%;
|
186 |
+
cursor: pointer;
|
187 |
+
}
|
188 |
+
|
189 |
+
.download-button {
|
190 |
+
background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
|
191 |
+
color: white;
|
192 |
+
padding: 8px 16px;
|
193 |
+
border-radius: 8px;
|
194 |
+
display: flex;
|
195 |
+
align-items: center;
|
196 |
+
gap: 8px;
|
197 |
+
transition: all 0.2s ease;
|
198 |
+
}
|
199 |
+
|
200 |
+
.download-button:hover {
|
201 |
+
transform: translateY(-2px);
|
202 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
203 |
+
}
|
204 |
+
|
205 |
+
/* Loading Spinner */
|
206 |
+
.spinner {
|
207 |
+
width: 40px;
|
208 |
+
height: 40px;
|
209 |
+
border: 3px solid rgba(255, 255, 255, 0.1);
|
210 |
+
border-radius: 50%;
|
211 |
+
border-top-color: #ff0066;
|
212 |
+
animation: spin 1s linear infinite;
|
213 |
+
}
|
214 |
+
|
215 |
+
@keyframes spin {
|
216 |
+
100% {
|
217 |
+
transform: rotate(360deg);
|
218 |
+
}
|
219 |
+
}
|
220 |
+
|
221 |
+
/* Responsive Adjustments */
|
222 |
+
@media (max-width: 768px) {
|
223 |
+
.audio-player {
|
224 |
+
padding: 15px;
|
225 |
+
}
|
226 |
+
|
227 |
+
.control-button {
|
228 |
+
width: 36px;
|
229 |
+
height: 36px;
|
230 |
+
}
|
231 |
+
|
232 |
+
.volume-slider {
|
233 |
+
width: 80px;
|
234 |
+
}
|
235 |
+
|
236 |
+
.download-button {
|
237 |
+
padding: 6px 12px;
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
/* Accessibility Improvements */
|
242 |
+
@media (prefers-reduced-motion: reduce) {
|
243 |
+
.hover-scale,
|
244 |
+
.gradient-btn,
|
245 |
+
.control-button,
|
246 |
+
.download-button {
|
247 |
+
transition: none;
|
248 |
+
}
|
249 |
+
|
250 |
+
.spinner {
|
251 |
+
animation: none;
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
+
/* High Contrast Mode */
|
256 |
+
@media (prefers-contrast: high) {
|
257 |
+
.glass-effect,
|
258 |
+
.content-box,
|
259 |
+
.input-dark {
|
260 |
+
background: rgba(0, 0, 0, 0.8);
|
261 |
+
backdrop-filter: none;
|
262 |
+
}
|
263 |
+
|
264 |
+
.gradient-text {
|
265 |
+
background: none;
|
266 |
+
color: white;
|
267 |
+
}
|
268 |
+
}
|
269 |
</style>
|
270 |
+
|
271 |
</head>
|
272 |
<body class="text-white text-shadow">
|
273 |
<div class="container mx-auto px-4 py-8 md:py-12 max-w-6xl relative">
|
|
|
336 |
Generate Speech
|
337 |
</button>
|
338 |
|
339 |
+
<!-- Loading Spinner -->
|
340 |
+
<div id="loading" class="hidden flex justify-center items-center p-8">
|
341 |
+
<div class="spinner"></div>
|
|
|
|
|
|
|
342 |
</div>
|
343 |
|
344 |
<!-- Audio Player -->
|
345 |
+
<div id="audio-container" class="hidden mt-6">
|
346 |
+
<div class="audio-player">
|
347 |
+
<div class="flex items-center gap-4 mb-4">
|
348 |
+
<button id="playPauseBtn" class="control-button">
|
349 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
|
350 |
+
<path d="M8 5v14l11-7z"/>
|
351 |
+
</svg>
|
352 |
+
</button>
|
353 |
+
<div class="flex-grow">
|
354 |
+
<div class="progress-bar" id="progressBar">
|
355 |
+
<div class="progress" id="progress"></div>
|
356 |
+
<div class="progress-handle" id="progressHandle"></div>
|
357 |
+
</div>
|
358 |
+
<div class="flex justify-between mt-1">
|
359 |
+
<span class="time-display" id="currentTime">0:00</span>
|
360 |
+
<span class="time-display" id="duration">0:00</span>
|
361 |
+
</div>
|
362 |
+
</div>
|
363 |
+
<div class="flex items-center gap-2">
|
364 |
+
<button id="muteBtn" class="control-button">
|
365 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
|
366 |
+
<path d="M8 4l6-4v20l-6-4H2V8h6z"/>
|
367 |
+
<path d="M16 8c1 1 1.5 2.5 1.5 4s-.5 3-1.5 4"/>
|
368 |
+
<path d="M19 5c2 2 3 4.5 3 7s-1 5-3 7"/>
|
369 |
+
</svg>
|
370 |
+
</button>
|
371 |
+
<input type="range" class="volume-slider" id="volumeSlider" min="0" max="100" value="100">
|
372 |
+
</div>
|
373 |
+
<button id="downloadBtn" class="download-button">
|
374 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
|
375 |
+
<path d="M3 17h18M10 4v10m0 0l4-4m-4 4l-4-4"/>
|
376 |
+
</svg>
|
377 |
+
Download
|
378 |
+
</button>
|
379 |
+
</div>
|
380 |
+
<audio id="audio-player" class="hidden"></audio>
|
381 |
</div>
|
382 |
</div>
|
383 |
|
|
|
|
|
|
|
|
|
|
|
384 |
<!-- Error Message -->
|
385 |
<div id="error" class="hidden mt-6 md:mt-8 text-red-400 text-center font-medium glass-effect p-4 md:p-6 rounded-xl">
|
386 |
</div>
|
|
|
411 |
</p>
|
412 |
</footer>
|
413 |
</div>
|
414 |
+
<script>
|
415 |
+
const modelSelect = document.getElementById('model');
|
416 |
+
const voiceSelect = document.getElementById('voice');
|
417 |
+
const textInput = document.getElementById('text');
|
418 |
+
const charCount = document.getElementById('char-count');
|
419 |
+
const generateBtn = document.getElementById('generate');
|
420 |
+
const audioContainer = document.getElementById('audio-container');
|
421 |
+
const audioPlayer = document.getElementById('audio-player');
|
422 |
+
const loading = document.getElementById('loading');
|
423 |
+
const error = document.getElementById('error');
|
424 |
+
const loadingBarContainer = document.getElementById('loading-bar-container');
|
425 |
+
const loadingBar = document.getElementById('loading-bar');
|
426 |
+
const loadingBarText = document.getElementById('loading-bar-text');
|
427 |
+
|
428 |
+
// Audio Player Controls
|
429 |
+
const playPauseBtn = document.getElementById('playPauseBtn');
|
430 |
+
const muteBtn = document.getElementById('muteBtn');
|
431 |
+
const volumeSlider = document.getElementById('volumeSlider');
|
432 |
+
const progressBar = document.getElementById('progressBar');
|
433 |
+
const progress = document.getElementById('progress');
|
434 |
+
const progressHandle = document.getElementById('progressHandle');
|
435 |
+
const currentTimeDisplay = document.getElementById('currentTime');
|
436 |
+
const durationDisplay = document.getElementById('duration');
|
437 |
+
const downloadBtn = document.getElementById('downloadBtn');
|
438 |
+
|
439 |
+
let modelsData = {};
|
440 |
+
|
441 |
+
// Initialize the application
|
442 |
+
fetchModels();
|
443 |
+
|
444 |
+
async function fetchModels() {
|
445 |
+
try {
|
446 |
+
const response = await fetch('/v1/models');
|
447 |
+
const data = await response.json();
|
448 |
+
modelsData = data.models.reduce((acc, model) => {
|
449 |
+
acc[model.id] = model;
|
450 |
+
return acc;
|
451 |
+
}, {});
|
452 |
+
|
453 |
+
// Populate model select
|
454 |
+
data.models.forEach(model => {
|
455 |
+
const option = document.createElement('option');
|
456 |
+
option.value = model.id;
|
457 |
+
option.textContent = `${model.name} (${model.owner})`;
|
458 |
+
modelSelect.appendChild(option);
|
459 |
+
});
|
460 |
+
|
461 |
+
// Initialize voices for first model
|
462 |
+
if (data.models.length > 0) {
|
463 |
+
updateVoices(data.models[0].id);
|
464 |
}
|
465 |
+
} catch (err) {
|
466 |
+
showError('Failed to load models. Please refresh the page.');
|
467 |
}
|
468 |
+
}
|
469 |
+
|
470 |
+
function updateVoices(modelId) {
|
471 |
+
// Clear existing voices
|
472 |
+
voiceSelect.innerHTML = '';
|
473 |
+
|
474 |
+
const model = modelsData[modelId];
|
475 |
+
if (model && model.vocals) {
|
476 |
+
model.vocals.forEach(voice => {
|
477 |
+
const option = document.createElement('option');
|
478 |
+
option.value = voice.id;
|
479 |
+
option.textContent = voice.id.charAt(0).toUpperCase() + voice.id.slice(1);
|
480 |
+
voiceSelect.appendChild(option);
|
481 |
+
});
|
482 |
}
|
483 |
+
}
|
484 |
+
|
485 |
+
modelSelect.addEventListener('change', (e) => {
|
486 |
+
updateVoices(e.target.value);
|
487 |
+
});
|
488 |
+
|
489 |
+
textInput.addEventListener('input', () => {
|
490 |
+
const length = textInput.value.length;
|
491 |
+
charCount.textContent = `${length}/5000 characters`;
|
492 |
+
|
493 |
+
if (length > 4900) {
|
494 |
+
charCount.classList.add('text-red-400');
|
495 |
+
charCount.classList.remove('white-text');
|
496 |
+
} else {
|
497 |
+
charCount.classList.remove('text-red-400');
|
498 |
+
charCount.classList.add('white-text');
|
499 |
+
}
|
500 |
+
});
|
501 |
|
502 |
+
generateBtn.addEventListener('click', async () => {
|
503 |
+
const text = textInput.value.trim();
|
504 |
+
const model = modelSelect.value;
|
505 |
+
const voice = voiceSelect.value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
+
if (!text) {
|
508 |
+
showError('Please enter some text to convert to speech');
|
509 |
+
return;
|
510 |
+
}
|
511 |
|
512 |
+
showLoading();
|
513 |
+
hideError();
|
|
|
|
|
514 |
|
515 |
+
let progress = 0;
|
516 |
+
loadingBar.style.width = `${progress}%`;
|
517 |
+
loadingBarText.textContent = `${progress}%`;
|
518 |
|
519 |
+
const intervalId = setInterval(() => {
|
520 |
+
progress += 10;
|
521 |
+
if (progress > 95) progress = 95; // Keep it below 100 until success
|
522 |
loadingBar.style.width = `${progress}%`;
|
523 |
loadingBarText.textContent = `${progress}%`;
|
524 |
+
}, 300);
|
525 |
+
|
526 |
+
try {
|
527 |
+
const response = await fetch('/v1/audio/speech', {
|
528 |
+
method: 'POST',
|
529 |
+
headers: {
|
530 |
+
'Content-Type': 'application/json',
|
531 |
+
},
|
532 |
+
body: JSON.stringify({
|
533 |
+
model: model,
|
534 |
+
input: text,
|
535 |
+
voice: voice
|
536 |
+
})
|
537 |
+
});
|
538 |
+
|
539 |
+
clearInterval(intervalId);
|
540 |
+
|
541 |
+
if (!response.ok) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
loadingBar.style.width = `100%`;
|
543 |
+
loadingBarText.textContent = `Failed`;
|
544 |
+
throw new Error('Failed to generate speech. Please try again.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
546 |
|
547 |
+
const audioBlob = await response.blob();
|
548 |
+
const audioUrl = URL.createObjectURL(audioBlob);
|
549 |
+
|
550 |
+
loadingBar.style.width = `100%`;
|
551 |
+
loadingBarText.textContent = `100%`;
|
552 |
+
audioPlayer.src = audioUrl;
|
553 |
+
showAudioPlayer();
|
554 |
+
audioPlayer.play();
|
555 |
+
} catch (err) {
|
556 |
+
showError(err.message);
|
557 |
+
} finally {
|
558 |
+
if (error.classList.contains('hidden')) {
|
559 |
+
setTimeout(hideLoading, 500); // Keep the 100% for a bit if successful
|
560 |
+
} else {
|
561 |
+
hideLoading(); // Hide immediately if there's an error
|
562 |
+
}
|
563 |
}
|
564 |
+
});
|
565 |
+
|
566 |
+
// Audio Player Controls
|
567 |
+
playPauseBtn.addEventListener('click', () => {
|
568 |
+
if (audioPlayer.paused) {
|
569 |
+
audioPlayer.play();
|
570 |
+
playPauseBtn.innerHTML = `
|
571 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
|
572 |
+
<path d="M8 5h3v14H8zm5 0h3v14h-3z"/>
|
573 |
+
</svg>
|
574 |
+
`;
|
575 |
+
} else {
|
576 |
+
audioPlayer.pause();
|
577 |
+
playPauseBtn.innerHTML = `
|
578 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
|
579 |
+
<path d="M8 5v14l11-7z"/>
|
580 |
+
</svg>
|
581 |
+
`;
|
582 |
}
|
583 |
+
});
|
584 |
+
|
585 |
+
// Update progress bar
|
586 |
+
audioPlayer.addEventListener('timeupdate', () => {
|
587 |
+
const percentage = (audioPlayer.currentTime / audioPlayer.duration) * 100;
|
588 |
+
progress.style.width = `${percentage}%`;
|
589 |
+
progressHandle.style.left = `${percentage}%`;
|
590 |
+
currentTimeDisplay.textContent = formatTime(audioPlayer.currentTime);
|
591 |
+
});
|
592 |
+
|
593 |
+
// Click on progress bar
|
594 |
+
progressBar.addEventListener('click', (e) => {
|
595 |
+
const rect = progressBar.getBoundingClientRect();
|
596 |
+
const percentage = (e.clientX - rect.left) / rect.width;
|
597 |
+
audioPlayer.currentTime = percentage * audioPlayer.duration;
|
598 |
+
});
|
599 |
+
|
600 |
+
// Volume control
|
601 |
+
volumeSlider.addEventListener('input', (e) => {
|
602 |
+
audioPlayer.volume = e.target.value / 100;
|
603 |
+
updateMuteButton();
|
604 |
+
});
|
605 |
+
|
606 |
+
// Mute toggle
|
607 |
+
muteBtn.addEventListener('click', () => {
|
608 |
+
audioPlayer.muted = !audioPlayer.muted;
|
609 |
+
updateMuteButton();
|
610 |
+
});
|
611 |
+
|
612 |
+
// Duration display
|
613 |
+
audioPlayer.addEventListener('loadedmetadata', () => {
|
614 |
+
durationDisplay.textContent = formatTime(audioPlayer.duration);
|
615 |
+
});
|
616 |
+
|
617 |
+
// Download functionality
|
618 |
+
downloadBtn.addEventListener('click', () => {
|
619 |
+
const audioUrl = audioPlayer.src;
|
620 |
+
const a = document.createElement('a');
|
621 |
+
a.href = audioUrl;
|
622 |
+
a.download = 'generated-speech.mp3';
|
623 |
+
document.body.appendChild(a);
|
624 |
+
a.click();
|
625 |
+
document.body.removeChild(a);
|
626 |
+
});
|
627 |
+
|
628 |
+
// Helper functions
|
629 |
+
function formatTime(seconds) {
|
630 |
+
const minutes = Math.floor(seconds / 60);
|
631 |
+
const remainingSeconds = Math.floor(seconds % 60);
|
632 |
+
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
|
633 |
+
}
|
634 |
+
|
635 |
+
function updateMuteButton() {
|
636 |
+
if (audioPlayer.muted || audioPlayer.volume === 0) {
|
637 |
+
muteBtn.innerHTML = `
|
638 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
|
639 |
+
<path d="M8 4l6-4v20l-6-4H2V8h6z"/>
|
640 |
+
<path d="M18 7l-4 4m0-4l4 4"/>
|
641 |
+
</svg>
|
642 |
+
`;
|
643 |
+
} else {
|
644 |
+
muteBtn.innerHTML = `
|
645 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
|
646 |
+
<path d="M8 4l6-4v20l-6-4H2V8h6z"/>
|
647 |
+
<path d="M16 8c1 1 1.5 2.5 1.5 4s-.5 3-1.5 4"/>
|
648 |
+
<path d="M19 5c2 2 3 4.5 3 7s-1 5-3 7"/>
|
649 |
+
</svg>
|
650 |
+
`;
|
651 |
}
|
652 |
+
}
|
653 |
+
|
654 |
+
function showLoading() {
|
655 |
+
loadingBarContainer.classList.remove('hidden');
|
656 |
+
loading.classList.remove('hidden');
|
657 |
+
generateBtn.disabled = true;
|
658 |
+
generateBtn.classList.add('opacity-50');
|
659 |
+
}
|
660 |
+
|
661 |
+
function hideLoading() {
|
662 |
+
loadingBarContainer.classList.add('hidden');
|
663 |
+
loading.classList.add('hidden');
|
664 |
+
generateBtn.disabled = false;
|
665 |
+
generateBtn.classList.remove('opacity-50');
|
666 |
+
}
|
667 |
+
|
668 |
+
function showError(message) {
|
669 |
+
error.textContent = message;
|
670 |
+
error.classList.remove('hidden');
|
671 |
+
error.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
672 |
+
}
|
673 |
+
|
674 |
+
function hideError() {
|
675 |
+
error.classList.add('hidden');
|
676 |
+
}
|
677 |
+
|
678 |
+
function showAudioPlayer() {
|
679 |
+
audioContainer.classList.remove('hidden');
|
680 |
+
}
|
681 |
+
</script>
|
682 |
</body>
|
683 |
</html>
|