Update templates/index.html
Browse files- templates/index.html +146 -81
templates/index.html
CHANGED
@@ -10,14 +10,15 @@
|
|
10 |
--gradient-start: #ff0066;
|
11 |
--gradient-end: #3366ff;
|
12 |
}
|
13 |
-
|
14 |
body {
|
15 |
-
background-image: url('static/
|
16 |
background-size: cover;
|
17 |
background-position: center;
|
18 |
background-attachment: fixed;
|
19 |
min-height: 100vh;
|
20 |
}
|
|
|
21 |
.gradient-text {
|
22 |
background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
|
23 |
-webkit-background-clip: text;
|
@@ -25,138 +26,118 @@
|
|
25 |
color: transparent;
|
26 |
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
27 |
}
|
|
|
28 |
.custom-shadow {
|
29 |
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
|
30 |
}
|
|
|
31 |
.content-box {
|
32 |
background: rgba(0, 0, 0, 0.15);
|
33 |
backdrop-filter: blur(8px);
|
34 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
35 |
}
|
|
|
36 |
.hover-scale {
|
37 |
transition: transform 0.2s;
|
38 |
}
|
|
|
39 |
.hover-scale:hover {
|
40 |
transform: scale(1.02);
|
41 |
}
|
|
|
42 |
.glass-effect {
|
43 |
background: rgba(0, 0, 0, 0.1);
|
44 |
backdrop-filter: blur(8px);
|
45 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
46 |
}
|
|
|
47 |
.input-dark {
|
48 |
background: rgba(0, 0, 0, 0.1);
|
49 |
border: 1px solid rgba(255, 255, 255, 0.2);
|
50 |
color: #fff;
|
51 |
backdrop-filter: blur(4px);
|
52 |
}
|
|
|
53 |
.input-dark::placeholder {
|
54 |
color: rgba(255, 255, 255, 0.6);
|
55 |
}
|
|
|
56 |
.input-dark:focus {
|
57 |
border-color: var(--gradient-start);
|
58 |
box-shadow: 0 0 0 2px rgba(255, 0, 102, 0.2);
|
59 |
background: rgba(0, 0, 0, 0.15);
|
60 |
}
|
|
|
61 |
.gradient-btn {
|
62 |
background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
|
63 |
backdrop-filter: blur(4px);
|
64 |
transition: all 0.3s ease;
|
65 |
}
|
|
|
66 |
.gradient-btn:hover {
|
67 |
filter: brightness(1.1);
|
68 |
transform: translateY(-2px);
|
69 |
background: linear-gradient(45deg, var(--gradient-end), var(--gradient-start));
|
70 |
}
|
|
|
71 |
select option {
|
72 |
background-color: rgba(0, 0, 0, 0.8);
|
73 |
color: white;
|
74 |
}
|
|
|
75 |
audio::-webkit-media-controls-panel {
|
76 |
background: rgba(0, 0, 0, 0.2);
|
77 |
backdrop-filter: blur(4px);
|
78 |
}
|
|
|
79 |
audio::-webkit-media-controls-current-time-display,
|
80 |
audio::-webkit-media-controls-time-remaining-display {
|
81 |
color: white;
|
82 |
}
|
|
|
83 |
.text-shadow {
|
84 |
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
85 |
}
|
|
|
86 |
pre {
|
87 |
background: rgba(0, 0, 0, 0.1) !important;
|
88 |
backdrop-filter: blur(4px);
|
89 |
white-space: pre-wrap;
|
90 |
word-wrap: break-word;
|
91 |
}
|
|
|
92 |
.white-text {
|
93 |
color: rgba(255, 255, 255, 0.9);
|
94 |
}
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
.
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
header h1 {
|
103 |
-
font-size: 2.5rem !important;
|
104 |
-
}
|
105 |
-
|
106 |
-
header p {
|
107 |
-
font-size: 1.1rem !important;
|
108 |
-
}
|
109 |
-
|
110 |
-
.content-box {
|
111 |
-
padding: 1.5rem !important;
|
112 |
-
}
|
113 |
-
|
114 |
-
.input-dark, .gradient-btn {
|
115 |
-
padding: 0.75rem !important;
|
116 |
-
}
|
117 |
-
|
118 |
-
pre code {
|
119 |
-
font-size: 0.8rem !important;
|
120 |
-
}
|
121 |
}
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
font-size: 1rem !important;
|
130 |
-
}
|
131 |
-
|
132 |
-
.glass-effect {
|
133 |
-
padding: 1rem !important;
|
134 |
-
}
|
135 |
-
|
136 |
-
.content-box {
|
137 |
-
padding: 1rem !important;
|
138 |
-
}
|
139 |
}
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
.container {
|
148 |
-
padding: 2rem;
|
149 |
-
}
|
150 |
-
|
151 |
-
.content-box {
|
152 |
-
padding: 2rem !important;
|
153 |
-
}
|
154 |
}
|
155 |
</style>
|
156 |
</head>
|
157 |
<body class="text-white text-shadow">
|
158 |
<div class="container mx-auto px-4 py-8 md:py-12 max-w-6xl relative">
|
159 |
-
<!-- Header -->
|
160 |
<header class="text-center mb-8 md:mb-12">
|
161 |
<div class="glass-effect inline-block px-6 md:px-10 py-4 md:py-6 rounded-3xl mb-6 md:mb-8">
|
162 |
<h1 class="text-3xl md:text-5xl lg:text-7xl font-bold gradient-text mb-3 md:mb-4 tracking-tight">PyxiLabs._.Vocify</h1>
|
@@ -166,6 +147,22 @@
|
|
166 |
|
167 |
<!-- Main Content -->
|
168 |
<div class="max-w-3xl mx-auto content-box rounded-3xl custom-shadow p-4 md:p-8 lg:p-10 hover-scale">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
<!-- Voice Selection -->
|
170 |
<div class="mb-6 md:mb-8">
|
171 |
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="voice">
|
@@ -182,14 +179,15 @@
|
|
182 |
</div>
|
183 |
</div>
|
184 |
|
|
|
185 |
<!-- Text Input -->
|
186 |
<div class="mb-6 md:mb-8">
|
187 |
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="text">
|
188 |
Enter Text
|
189 |
</label>
|
190 |
-
<textarea
|
191 |
-
id="text"
|
192 |
-
rows="4"
|
193 |
maxlength="500"
|
194 |
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"
|
195 |
placeholder="Enter your text here (max 500 characters)..."
|
@@ -198,13 +196,21 @@
|
|
198 |
</div>
|
199 |
|
200 |
<!-- Generate Button -->
|
201 |
-
<button
|
202 |
-
id="generate"
|
203 |
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"
|
204 |
>
|
205 |
Generate Speech
|
206 |
</button>
|
207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
<!-- Audio Player -->
|
209 |
<div id="audio-container" class="mt-6 md:mt-8 hidden">
|
210 |
<div class="glass-effect p-4 md:p-6 rounded-xl">
|
@@ -214,7 +220,7 @@
|
|
214 |
</div>
|
215 |
</div>
|
216 |
|
217 |
-
<!-- Loading State -->
|
218 |
<div id="loading" class="hidden mt-6 md:mt-8 text-center">
|
219 |
<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>
|
220 |
</div>
|
@@ -230,7 +236,7 @@
|
|
230 |
<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">
|
231 |
<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
|
232 |
{
|
233 |
-
"model": "
|
234 |
"input": "Your text here",
|
235 |
"voice": "selected_voice"
|
236 |
}</code></pre>
|
@@ -246,6 +252,7 @@
|
|
246 |
</div>
|
247 |
|
248 |
<script>
|
|
|
249 |
const voiceSelect = document.getElementById('voice');
|
250 |
const textInput = document.getElementById('text');
|
251 |
const charCount = document.getElementById('char-count');
|
@@ -254,27 +261,61 @@
|
|
254 |
const audioPlayer = document.getElementById('audio-player');
|
255 |
const loading = document.getElementById('loading');
|
256 |
const error = document.getElementById('error');
|
|
|
|
|
|
|
257 |
|
258 |
-
|
|
|
|
|
259 |
try {
|
260 |
-
const response = await fetch('/v1/
|
261 |
const data = await response.json();
|
262 |
-
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
264 |
const option = document.createElement('option');
|
265 |
-
option.value =
|
266 |
-
option.textContent =
|
267 |
-
|
268 |
});
|
|
|
|
|
|
|
|
|
|
|
269 |
} catch (err) {
|
270 |
-
showError('Failed to load
|
271 |
}
|
272 |
}
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
textInput.addEventListener('input', () => {
|
275 |
const length = textInput.value.length;
|
276 |
charCount.textContent = `${length}/500 characters`;
|
277 |
-
|
278 |
if (length > 450) {
|
279 |
charCount.classList.add('text-red-400');
|
280 |
charCount.classList.remove('white-text');
|
@@ -286,6 +327,7 @@
|
|
286 |
|
287 |
generateBtn.addEventListener('click', async () => {
|
288 |
const text = textInput.value.trim();
|
|
|
289 |
const voice = voiceSelect.value;
|
290 |
|
291 |
if (!text) {
|
@@ -295,7 +337,18 @@
|
|
295 |
|
296 |
showLoading();
|
297 |
hideError();
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
try {
|
300 |
const response = await fetch('/v1/audio/speech', {
|
301 |
method: 'POST',
|
@@ -303,36 +356,48 @@
|
|
303 |
'Content-Type': 'application/json',
|
304 |
},
|
305 |
body: JSON.stringify({
|
306 |
-
model:
|
307 |
input: text,
|
308 |
voice: voice
|
309 |
})
|
310 |
});
|
311 |
|
|
|
|
|
312 |
if (!response.ok) {
|
|
|
|
|
313 |
throw new Error('Failed to generate speech. Please try again.');
|
314 |
}
|
315 |
|
316 |
const audioBlob = await response.blob();
|
317 |
const audioUrl = URL.createObjectURL(audioBlob);
|
318 |
-
|
|
|
|
|
319 |
audioPlayer.src = audioUrl;
|
320 |
showAudioPlayer();
|
321 |
audioPlayer.play();
|
322 |
} catch (err) {
|
323 |
showError(err.message);
|
324 |
} finally {
|
325 |
-
|
|
|
|
|
|
|
|
|
326 |
}
|
327 |
});
|
328 |
|
329 |
function showLoading() {
|
|
|
330 |
loading.classList.remove('hidden');
|
331 |
generateBtn.disabled = true;
|
332 |
generateBtn.classList.add('opacity-50');
|
333 |
}
|
334 |
|
335 |
function hideLoading() {
|
|
|
336 |
loading.classList.add('hidden');
|
337 |
generateBtn.disabled = false;
|
338 |
generateBtn.classList.remove('opacity-50');
|
@@ -353,7 +418,7 @@
|
|
353 |
}
|
354 |
|
355 |
// Initialize the application
|
356 |
-
|
357 |
</script>
|
358 |
</body>
|
359 |
</html>
|
|
|
10 |
--gradient-start: #ff0066;
|
11 |
--gradient-end: #3366ff;
|
12 |
}
|
13 |
+
|
14 |
body {
|
15 |
+
background-image: url('static/bg.jpeg');
|
16 |
background-size: cover;
|
17 |
background-position: center;
|
18 |
background-attachment: fixed;
|
19 |
min-height: 100vh;
|
20 |
}
|
21 |
+
|
22 |
.gradient-text {
|
23 |
background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
|
24 |
-webkit-background-clip: text;
|
|
|
26 |
color: transparent;
|
27 |
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
28 |
}
|
29 |
+
|
30 |
.custom-shadow {
|
31 |
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
|
32 |
}
|
33 |
+
|
34 |
.content-box {
|
35 |
background: rgba(0, 0, 0, 0.15);
|
36 |
backdrop-filter: blur(8px);
|
37 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
38 |
}
|
39 |
+
|
40 |
.hover-scale {
|
41 |
transition: transform 0.2s;
|
42 |
}
|
43 |
+
|
44 |
.hover-scale:hover {
|
45 |
transform: scale(1.02);
|
46 |
}
|
47 |
+
|
48 |
.glass-effect {
|
49 |
background: rgba(0, 0, 0, 0.1);
|
50 |
backdrop-filter: blur(8px);
|
51 |
border: 1px solid rgba(255, 255, 255, 0.1);
|
52 |
}
|
53 |
+
|
54 |
.input-dark {
|
55 |
background: rgba(0, 0, 0, 0.1);
|
56 |
border: 1px solid rgba(255, 255, 255, 0.2);
|
57 |
color: #fff;
|
58 |
backdrop-filter: blur(4px);
|
59 |
}
|
60 |
+
|
61 |
.input-dark::placeholder {
|
62 |
color: rgba(255, 255, 255, 0.6);
|
63 |
}
|
64 |
+
|
65 |
.input-dark:focus {
|
66 |
border-color: var(--gradient-start);
|
67 |
box-shadow: 0 0 0 2px rgba(255, 0, 102, 0.2);
|
68 |
background: rgba(0, 0, 0, 0.15);
|
69 |
}
|
70 |
+
|
71 |
.gradient-btn {
|
72 |
background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
|
73 |
backdrop-filter: blur(4px);
|
74 |
transition: all 0.3s ease;
|
75 |
}
|
76 |
+
|
77 |
.gradient-btn:hover {
|
78 |
filter: brightness(1.1);
|
79 |
transform: translateY(-2px);
|
80 |
background: linear-gradient(45deg, var(--gradient-end), var(--gradient-start));
|
81 |
}
|
82 |
+
|
83 |
select option {
|
84 |
background-color: rgba(0, 0, 0, 0.8);
|
85 |
color: white;
|
86 |
}
|
87 |
+
|
88 |
audio::-webkit-media-controls-panel {
|
89 |
background: rgba(0, 0, 0, 0.2);
|
90 |
backdrop-filter: blur(4px);
|
91 |
}
|
92 |
+
|
93 |
audio::-webkit-media-controls-current-time-display,
|
94 |
audio::-webkit-media-controls-time-remaining-display {
|
95 |
color: white;
|
96 |
}
|
97 |
+
|
98 |
.text-shadow {
|
99 |
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
100 |
}
|
101 |
+
|
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 |
.white-text {
|
110 |
color: rgba(255, 255, 255, 0.9);
|
111 |
}
|
112 |
+
|
113 |
+
.loading-bar-container {
|
114 |
+
height: 10px;
|
115 |
+
background-color: rgba(255, 255, 255, 0.1);
|
116 |
+
border-radius: 5px;
|
117 |
+
overflow: hidden;
|
118 |
+
margin-top: 1rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
}
|
120 |
+
|
121 |
+
.loading-bar {
|
122 |
+
height: 100%;
|
123 |
+
background: linear-gradient(to right, #ff0066, #3366ff);
|
124 |
+
width: 0%;
|
125 |
+
border-radius: 5px;
|
126 |
+
transition: width 0.3s ease-in-out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
}
|
128 |
+
.loading-bar-text {
|
129 |
+
position: absolute;
|
130 |
+
top: 50%;
|
131 |
+
left: 50%;
|
132 |
+
transform: translate(-50%, -50%);
|
133 |
+
color: white;
|
134 |
+
font-size: 0.8rem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
}
|
136 |
</style>
|
137 |
</head>
|
138 |
<body class="text-white text-shadow">
|
139 |
<div class="container mx-auto px-4 py-8 md:py-12 max-w-6xl relative">
|
140 |
+
<!-- Header remains unchanged -->
|
141 |
<header class="text-center mb-8 md:mb-12">
|
142 |
<div class="glass-effect inline-block px-6 md:px-10 py-4 md:py-6 rounded-3xl mb-6 md:mb-8">
|
143 |
<h1 class="text-3xl md:text-5xl lg:text-7xl font-bold gradient-text mb-3 md:mb-4 tracking-tight">PyxiLabs._.Vocify</h1>
|
|
|
147 |
|
148 |
<!-- Main Content -->
|
149 |
<div class="max-w-3xl mx-auto content-box rounded-3xl custom-shadow p-4 md:p-8 lg:p-10 hover-scale">
|
150 |
+
<!-- Model Selection (New) -->
|
151 |
+
<div class="mb-6 md:mb-8">
|
152 |
+
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="model">
|
153 |
+
Select Model
|
154 |
+
</label>
|
155 |
+
<div class="relative">
|
156 |
+
<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">
|
157 |
+
</select>
|
158 |
+
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-3 md:px-4 text-white">
|
159 |
+
<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">
|
160 |
+
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/>
|
161 |
+
</svg>
|
162 |
+
</div>
|
163 |
+
</div>
|
164 |
+
</div>
|
165 |
+
|
166 |
<!-- Voice Selection -->
|
167 |
<div class="mb-6 md:mb-8">
|
168 |
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="voice">
|
|
|
179 |
</div>
|
180 |
</div>
|
181 |
|
182 |
+
<!-- Rest of the content structure remains the same -->
|
183 |
<!-- Text Input -->
|
184 |
<div class="mb-6 md:mb-8">
|
185 |
<label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="text">
|
186 |
Enter Text
|
187 |
</label>
|
188 |
+
<textarea
|
189 |
+
id="text"
|
190 |
+
rows="4"
|
191 |
maxlength="500"
|
192 |
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"
|
193 |
placeholder="Enter your text here (max 500 characters)..."
|
|
|
196 |
</div>
|
197 |
|
198 |
<!-- Generate Button -->
|
199 |
+
<button
|
200 |
+
id="generate"
|
201 |
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"
|
202 |
>
|
203 |
Generate Speech
|
204 |
</button>
|
205 |
|
206 |
+
<!-- Loading Bar -->
|
207 |
+
<div id="loading-bar-container" class="hidden relative">
|
208 |
+
<div class="loading-bar-container">
|
209 |
+
<div id="loading-bar" class="loading-bar"></div>
|
210 |
+
</div>
|
211 |
+
<div id="loading-bar-text" class="absolute inset-0 flex justify-center items-center text-white font-semibold">0%</div>
|
212 |
+
</div>
|
213 |
+
|
214 |
<!-- Audio Player -->
|
215 |
<div id="audio-container" class="mt-6 md:mt-8 hidden">
|
216 |
<div class="glass-effect p-4 md:p-6 rounded-xl">
|
|
|
220 |
</div>
|
221 |
</div>
|
222 |
|
223 |
+
<!-- Loading State (the spinning circle) -->
|
224 |
<div id="loading" class="hidden mt-6 md:mt-8 text-center">
|
225 |
<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>
|
226 |
</div>
|
|
|
236 |
<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">
|
237 |
<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
|
238 |
{
|
239 |
+
"model": "Pyx r1-voice",
|
240 |
"input": "Your text here",
|
241 |
"voice": "selected_voice"
|
242 |
}</code></pre>
|
|
|
252 |
</div>
|
253 |
|
254 |
<script>
|
255 |
+
const modelSelect = document.getElementById('model');
|
256 |
const voiceSelect = document.getElementById('voice');
|
257 |
const textInput = document.getElementById('text');
|
258 |
const charCount = document.getElementById('char-count');
|
|
|
261 |
const audioPlayer = document.getElementById('audio-player');
|
262 |
const loading = document.getElementById('loading');
|
263 |
const error = document.getElementById('error');
|
264 |
+
const loadingBarContainer = document.getElementById('loading-bar-container');
|
265 |
+
const loadingBar = document.getElementById('loading-bar');
|
266 |
+
const loadingBarText = document.getElementById('loading-bar-text');
|
267 |
|
268 |
+
let modelsData = {};
|
269 |
+
|
270 |
+
async function fetchModels() {
|
271 |
try {
|
272 |
+
const response = await fetch('/v1/models');
|
273 |
const data = await response.json();
|
274 |
+
modelsData = data.models.reduce((acc, model) => {
|
275 |
+
acc[model.id] = model;
|
276 |
+
return acc;
|
277 |
+
}, {});
|
278 |
+
|
279 |
+
// Populate model select
|
280 |
+
data.models.forEach(model => {
|
281 |
const option = document.createElement('option');
|
282 |
+
option.value = model.id;
|
283 |
+
option.textContent = `${model.name} (${model.owner})`;
|
284 |
+
modelSelect.appendChild(option);
|
285 |
});
|
286 |
+
|
287 |
+
// Initialize voices for first model
|
288 |
+
if (data.models.length > 0) {
|
289 |
+
updateVoices(data.models[0].id);
|
290 |
+
}
|
291 |
} catch (err) {
|
292 |
+
showError('Failed to load models. Please refresh the page.');
|
293 |
}
|
294 |
}
|
295 |
|
296 |
+
function updateVoices(modelId) {
|
297 |
+
// Clear existing voices
|
298 |
+
voiceSelect.innerHTML = '';
|
299 |
+
|
300 |
+
const model = modelsData[modelId];
|
301 |
+
if (model && model.vocals) {
|
302 |
+
model.vocals.forEach(voice => {
|
303 |
+
const option = document.createElement('option');
|
304 |
+
option.value = voice.id;
|
305 |
+
option.textContent = voice.id.charAt(0).toUpperCase() + voice.id.slice(1);
|
306 |
+
voiceSelect.appendChild(option);
|
307 |
+
});
|
308 |
+
}
|
309 |
+
}
|
310 |
+
|
311 |
+
modelSelect.addEventListener('change', (e) => {
|
312 |
+
updateVoices(e.target.value);
|
313 |
+
});
|
314 |
+
|
315 |
textInput.addEventListener('input', () => {
|
316 |
const length = textInput.value.length;
|
317 |
charCount.textContent = `${length}/500 characters`;
|
318 |
+
|
319 |
if (length > 450) {
|
320 |
charCount.classList.add('text-red-400');
|
321 |
charCount.classList.remove('white-text');
|
|
|
327 |
|
328 |
generateBtn.addEventListener('click', async () => {
|
329 |
const text = textInput.value.trim();
|
330 |
+
const model = modelSelect.value;
|
331 |
const voice = voiceSelect.value;
|
332 |
|
333 |
if (!text) {
|
|
|
337 |
|
338 |
showLoading();
|
339 |
hideError();
|
340 |
+
|
341 |
+
let progress = 0;
|
342 |
+
loadingBar.style.width = `${progress}%`;
|
343 |
+
loadingBarText.textContent = `${progress}%`;
|
344 |
+
|
345 |
+
const intervalId = setInterval(() => {
|
346 |
+
progress += 10;
|
347 |
+
if (progress > 95) progress = 95; // Keep it below 100 until success
|
348 |
+
loadingBar.style.width = `${progress}%`;
|
349 |
+
loadingBarText.textContent = `${progress}%`;
|
350 |
+
}, 300);
|
351 |
+
|
352 |
try {
|
353 |
const response = await fetch('/v1/audio/speech', {
|
354 |
method: 'POST',
|
|
|
356 |
'Content-Type': 'application/json',
|
357 |
},
|
358 |
body: JSON.stringify({
|
359 |
+
model: model,
|
360 |
input: text,
|
361 |
voice: voice
|
362 |
})
|
363 |
});
|
364 |
|
365 |
+
clearInterval(intervalId);
|
366 |
+
|
367 |
if (!response.ok) {
|
368 |
+
loadingBar.style.width = `100%`;
|
369 |
+
loadingBarText.textContent = `Failed`;
|
370 |
throw new Error('Failed to generate speech. Please try again.');
|
371 |
}
|
372 |
|
373 |
const audioBlob = await response.blob();
|
374 |
const audioUrl = URL.createObjectURL(audioBlob);
|
375 |
+
|
376 |
+
loadingBar.style.width = `100%`;
|
377 |
+
loadingBarText.textContent = `100%`;
|
378 |
audioPlayer.src = audioUrl;
|
379 |
showAudioPlayer();
|
380 |
audioPlayer.play();
|
381 |
} catch (err) {
|
382 |
showError(err.message);
|
383 |
} finally {
|
384 |
+
if (error.classList.contains('hidden')) {
|
385 |
+
setTimeout(hideLoading, 500); // Keep the 100% for a bit if successful
|
386 |
+
} else {
|
387 |
+
hideLoading(); // Hide immediately if there's an error
|
388 |
+
}
|
389 |
}
|
390 |
});
|
391 |
|
392 |
function showLoading() {
|
393 |
+
loadingBarContainer.classList.remove('hidden');
|
394 |
loading.classList.remove('hidden');
|
395 |
generateBtn.disabled = true;
|
396 |
generateBtn.classList.add('opacity-50');
|
397 |
}
|
398 |
|
399 |
function hideLoading() {
|
400 |
+
loadingBarContainer.classList.add('hidden');
|
401 |
loading.classList.add('hidden');
|
402 |
generateBtn.disabled = false;
|
403 |
generateBtn.classList.remove('opacity-50');
|
|
|
418 |
}
|
419 |
|
420 |
// Initialize the application
|
421 |
+
fetchModels();
|
422 |
</script>
|
423 |
</body>
|
424 |
</html>
|