Delete templates/index.html
Browse files- templates/index.html +0 -681
templates/index.html
DELETED
@@ -1,681 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
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">
|
274 |
-
<!-- Header -->
|
275 |
-
<header class="text-center mb-8 md:mb-12">
|
276 |
-
<div class="glass-effect inline-block px-6 md:px-10 py-4 md:py-6 rounded-3xl mb-6 md:mb-8">
|
277 |
-
<h1 class="text-3xl md:text-5xl lg:text-7xl font-bold gradient-text mb-3 md:mb-4 tracking-tight">PyxiLabs._.Vocify</h1>
|
278 |
-
<p class="white-text text-lg md:text-xl lg:text-2xl max-w-2xl mx-auto">Transform your text into natural speech with our powerful API</p>
|
279 |
-
</div>
|
280 |
-
</header>
|
281 |
-
|
282 |
-
<!-- Main Content -->
|
283 |
-
<div class="max-w-3xl mx-auto content-box rounded-3xl custom-shadow p-4 md:p-8 lg:p-10 hover-scale">
|
284 |
-
<!-- Model Selection -->
|
285 |
-
<div class="mb-6 md:mb-8">
|
286 |
-
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="model">
|
287 |
-
Select Model
|
288 |
-
</label>
|
289 |
-
<div class="relative">
|
290 |
-
<select id="model" class="w-full px-4 md:px-5 py-3 md:py-4 rounded-xl input-dark focus:outline-none focus:ring-2 focus:ring-red-400 appearance-none text-base md:text-lg">
|
291 |
-
</select>
|
292 |
-
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-3 md:px-4 text-white">
|
293 |
-
<svg class="fill-current h-4 w-4 md:h-5 md:w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
|
294 |
-
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/>
|
295 |
-
</svg>
|
296 |
-
</div>
|
297 |
-
</div>
|
298 |
-
</div>
|
299 |
-
|
300 |
-
<!-- Voice Selection -->
|
301 |
-
<div class="mb-6 md:mb-8">
|
302 |
-
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="voice">
|
303 |
-
Select Voice
|
304 |
-
</label>
|
305 |
-
<div class="relative">
|
306 |
-
<select id="voice" class="w-full px-4 md:px-5 py-3 md:py-4 rounded-xl input-dark focus:outline-none focus:ring-2 focus:ring-red-400 appearance-none text-base md:text-lg">
|
307 |
-
</select>
|
308 |
-
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-3 md:px-4 text-white">
|
309 |
-
<svg class="fill-current h-4 w-4 md:h-5 md:w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
|
310 |
-
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/>
|
311 |
-
</svg>
|
312 |
-
</div>
|
313 |
-
</div>
|
314 |
-
</div>
|
315 |
-
|
316 |
-
<!-- Text Input -->
|
317 |
-
<div class="mb-6 md:mb-8">
|
318 |
-
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="text">
|
319 |
-
Enter Text
|
320 |
-
</label>
|
321 |
-
<textarea
|
322 |
-
id="text"
|
323 |
-
rows="4"
|
324 |
-
maxlength="5000"
|
325 |
-
class="w-full px-4 md:px-5 py-3 md:py-4 rounded-xl input-dark focus:outline-none focus:ring-2 focus:ring-red-400 resize-none text-base md:text-lg"
|
326 |
-
placeholder="Enter your text here (max 5000 characters)..."
|
327 |
-
></textarea>
|
328 |
-
<p id="char-count" class="text-sm md:text-base white-text mt-2 text-right">0/5000 characters</p>
|
329 |
-
</div>
|
330 |
-
|
331 |
-
<!-- Generate Button -->
|
332 |
-
<button
|
333 |
-
id="generate"
|
334 |
-
class="w-full gradient-btn text-white font-bold py-4 md:py-5 px-6 md:px-8 rounded-xl text-base md:text-lg shadow-lg"
|
335 |
-
>
|
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>
|
387 |
-
</div>
|
388 |
-
|
389 |
-
<!-- API Documentation -->
|
390 |
-
<div class="mt-12 md:mt-16 text-center">
|
391 |
-
<h2 class="text-2xl md:text-3xl font-bold mb-6 md:mb-8 white-text glass-effect inline-block px-6 md:px-8 py-2 md:py-3 rounded-xl">API Documentation</h2>
|
392 |
-
<div class="content-box rounded-xl p-6 md:p-8 custom-shadow inline-block text-left hover-scale max-w-full overflow-x-auto">
|
393 |
-
<pre class="p-4 md:p-6 rounded-xl overflow-x-auto text-white"><code class="text-sm md:text-base">POST /v1/audio/speech
|
394 |
-
{
|
395 |
-
"model": "Pyx r1-voice",
|
396 |
-
"input": "Your text here",
|
397 |
-
"voice": "selected_voice"
|
398 |
-
}
|
399 |
-
|
400 |
-
Rate Limits (Free Tier):
|
401 |
-
- Requests Per Minute (RPM): 10
|
402 |
-
- Requests Per Hour (RPH): 100
|
403 |
-
- Requests Per Day (RPD): 1,000</code></pre>
|
404 |
-
</div>
|
405 |
-
</div>
|
406 |
-
|
407 |
-
<!-- Footer -->
|
408 |
-
<footer class="mt-12 md:mt-16 text-center">
|
409 |
-
<p class="white-text text-sm md:text-base glass-effect inline-block px-4 md:px-6 py-2 md:py-3 rounded-xl">
|
410 |
-
© 2024 PyxiLabs._.Vocify. All rights reserved.
|
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 |
-
loading.classList.remove('hidden');
|
656 |
-
generateBtn.disabled = true;
|
657 |
-
generateBtn.classList.add('opacity-50');
|
658 |
-
}
|
659 |
-
|
660 |
-
function hideLoading() {
|
661 |
-
loading.classList.add('hidden');
|
662 |
-
generateBtn.disabled = false;
|
663 |
-
generateBtn.classList.remove('opacity-50');
|
664 |
-
}
|
665 |
-
|
666 |
-
function showError(message) {
|
667 |
-
error.textContent = message;
|
668 |
-
error.classList.remove('hidden');
|
669 |
-
error.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
670 |
-
}
|
671 |
-
|
672 |
-
function hideError() {
|
673 |
-
error.classList.add('hidden');
|
674 |
-
}
|
675 |
-
|
676 |
-
function showAudioPlayer() {
|
677 |
-
audioContainer.classList.remove('hidden');
|
678 |
-
}
|
679 |
-
</script>
|
680 |
-
</body>
|
681 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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