Update index.html
Browse files- index.html +208 -825
index.html
CHANGED
@@ -3,655 +3,152 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Alpha TTS -
|
7 |
<style>
|
8 |
-
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;
|
9 |
|
10 |
:root {
|
11 |
--app-font: 'Vazirmatn', sans-serif;
|
12 |
-
--app-
|
13 |
-
--
|
14 |
-
--panel-
|
15 |
-
--
|
16 |
-
--
|
17 |
-
--
|
18 |
-
--
|
19 |
-
--
|
20 |
-
--
|
21 |
-
--
|
22 |
-
--input-border-focus: var(--accent-primary);
|
23 |
-
|
24 |
--radius-card: 24px;
|
25 |
-
--radius-input:
|
26 |
-
--shadow-
|
27 |
-
--shadow-
|
28 |
-
--
|
29 |
-
--transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
30 |
-
--transition-bounce: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
|
31 |
-
}
|
32 |
-
|
33 |
-
@keyframes fadeInDown {
|
34 |
-
from { opacity: 0; transform: translateY(-20px); }
|
35 |
-
to { opacity: 1; transform: translateY(0); }
|
36 |
-
}
|
37 |
-
@keyframes fadeInUp {
|
38 |
-
from { opacity: 0; transform: translateY(20px); }
|
39 |
-
to { opacity: 1; transform: translateY(0); }
|
40 |
-
}
|
41 |
-
@keyframes modalZoomIn {
|
42 |
-
from { opacity: 0; transform: scale(0.8) translateY(20px); }
|
43 |
-
to { opacity: 1; transform: scale(1) translateY(0); }
|
44 |
-
}
|
45 |
-
@keyframes modalZoomOut {
|
46 |
-
from { opacity: 1; transform: scale(1) translateY(0); }
|
47 |
-
to { opacity: 0; transform: scale(0.8) translateY(20px); }
|
48 |
}
|
49 |
|
50 |
-
|
51 |
body {
|
52 |
font-family: var(--app-font);
|
53 |
direction: rtl;
|
54 |
-
background
|
55 |
-
color: var(--text-primary);
|
56 |
font-size: 16px;
|
57 |
-
line-height: 1.
|
58 |
margin: 0;
|
59 |
-
padding:
|
60 |
min-height: 100vh;
|
61 |
-webkit-font-smoothing: antialiased;
|
62 |
-moz-osx-font-smoothing: grayscale;
|
63 |
-
display: flex;
|
64 |
-
justify-content: center;
|
65 |
-
align-items: flex-start;
|
66 |
-
overflow-x: hidden;
|
67 |
-
}
|
68 |
-
|
69 |
-
.container {
|
70 |
-
max-width: 780px;
|
71 |
-
width: 92%;
|
72 |
-
margin: 0 auto;
|
73 |
-
}
|
74 |
-
|
75 |
-
.app-header {
|
76 |
-
padding: 0.5rem 0 2.5rem 0;
|
77 |
-
text-align: center;
|
78 |
-
margin-bottom: 1.5rem;
|
79 |
-
animation: fadeInDown 0.8s 0.1s ease-out backwards;
|
80 |
-
}
|
81 |
-
.app-header h1 {
|
82 |
-
font-size: 2.1em;
|
83 |
-
font-weight: 900;
|
84 |
-
margin:0 0 0.6rem 0;
|
85 |
-
background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
|
86 |
-
-webkit-background-clip: text;
|
87 |
-
-webkit-text-fill-color: transparent;
|
88 |
-
letter-spacing: -0.5px;
|
89 |
-
}
|
90 |
-
.app-header p {
|
91 |
-
font-size: 1em;
|
92 |
-
color: var(--text-secondary);
|
93 |
-
margin-top:0;
|
94 |
-
opacity: 0.85;
|
95 |
-
font-weight: 400;
|
96 |
-
line-height: 1.6;
|
97 |
-
}
|
98 |
-
|
99 |
-
.main-content {
|
100 |
-
padding: 2.5rem;
|
101 |
-
background-color: var(--panel-bg);
|
102 |
-
border-radius: var(--radius-card);
|
103 |
-
box-shadow: var(--shadow-strong);
|
104 |
-
border: 1px solid var(--panel-border);
|
105 |
-
animation: fadeInUp 0.8s 0.3s ease-out backwards;
|
106 |
-
}
|
107 |
-
|
108 |
-
.form-group { margin-bottom: 2rem; }
|
109 |
-
|
110 |
-
.label-with-info {
|
111 |
-
display: flex;
|
112 |
-
align-items: center;
|
113 |
-
gap: 0.5rem;
|
114 |
-
margin-bottom: 1rem;
|
115 |
-
}
|
116 |
-
.label-with-info label {
|
117 |
-
margin-bottom: 0;
|
118 |
-
}
|
119 |
-
|
120 |
-
.info-icon { /* Renamed from info-tooltip-icon for clarity */
|
121 |
-
display: inline-flex;
|
122 |
-
align-items: center;
|
123 |
-
justify-content: center;
|
124 |
-
width: 22px;
|
125 |
-
height: 22px;
|
126 |
-
border-radius: 50%;
|
127 |
-
background-color: var(--input-bg);
|
128 |
-
border: 1px solid var(--panel-border);
|
129 |
-
color: var(--text-secondary);
|
130 |
-
font-size: 0.9em;
|
131 |
-
font-weight: 700;
|
132 |
-
cursor: pointer;
|
133 |
-
position: relative;
|
134 |
-
transition: var(--transition-smooth);
|
135 |
-
user-select: none;
|
136 |
-
}
|
137 |
-
.info-icon:hover, .info-icon:focus {
|
138 |
-
background-color: var(--accent-primary);
|
139 |
-
color: white;
|
140 |
-
border-color: var(--accent-primary);
|
141 |
-
transform: scale(1.1);
|
142 |
-
outline: none;
|
143 |
}
|
144 |
-
/* Removed .tooltip-text and .info-tooltip-icon.active as it's now a modal */
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
textarea, input[type="text"] {
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
}
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
.
|
176 |
-
|
177 |
-
|
178 |
-
text-align: left;
|
179 |
-
margin-top: 0.5rem;
|
180 |
-
padding: 0 0.2rem;
|
181 |
-
}
|
182 |
-
#char-count { font-weight: 600; color: var(--accent-primary); }
|
183 |
-
|
184 |
-
|
185 |
-
/* --- نمایش گوینده منتخب --- */
|
186 |
-
#selected-speaker-display { text-align: center; margin-top: 1rem; position: relative; }
|
187 |
-
#selected-speaker-card {
|
188 |
-
display: inline-flex;
|
189 |
-
align-items: center;
|
190 |
-
background: linear-gradient(135deg, var(--input-bg) 0%, #fff 100%);
|
191 |
-
border-radius: var(--radius-card);
|
192 |
-
padding: 1rem 1.2rem;
|
193 |
-
box-shadow: var(--shadow-medium);
|
194 |
-
border: 1px solid var(--panel-border);
|
195 |
-
transition: var(--transition-bounce);
|
196 |
-
position: relative;
|
197 |
-
margin-bottom: 1.2rem;
|
198 |
-
cursor: pointer;
|
199 |
-
}
|
200 |
-
#selected-speaker-card:hover {
|
201 |
-
transform: translateY(-6px) scale(1.03);
|
202 |
-
box-shadow: var(--shadow-strong);
|
203 |
-
}
|
204 |
-
#selected-speaker-card img {
|
205 |
-
width: 75px; height: 75px;
|
206 |
-
border-radius: 50%;
|
207 |
-
object-fit: cover;
|
208 |
-
margin-left: 18px;
|
209 |
-
border: 3px solid var(--accent-secondary);
|
210 |
-
box-shadow: 0 0 12px -2px rgba(16, 185, 129, 0.5);
|
211 |
-
background-color: #e0e0e0;
|
212 |
-
transition: var(--transition-smooth);
|
213 |
-
}
|
214 |
-
#selected-speaker-card:hover img {
|
215 |
-
transform: scale(1.08) rotate(3deg);
|
216 |
-
}
|
217 |
-
#selected-speaker-info h3 { margin: 0; font-size: 1.35em; font-weight: 800; color: var(--text-primary); }
|
218 |
-
#selected-speaker-info p { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.88em; font-weight: 500; }
|
219 |
-
|
220 |
-
#change-speaker-btn {
|
221 |
-
display: inline-flex;
|
222 |
-
align-items: center;
|
223 |
-
justify-content: center;
|
224 |
-
margin: 0 auto;
|
225 |
-
padding: 10px 20px;
|
226 |
-
border-radius: var(--radius-input);
|
227 |
-
background: linear-gradient(45deg, var(--accent-primary-hover), var(--accent-primary));
|
228 |
-
border: none;
|
229 |
-
color: #fff;
|
230 |
-
cursor: pointer;
|
231 |
-
font-family: var(--app-font); font-weight: 600;
|
232 |
-
font-size: 1em;
|
233 |
-
transition: var(--transition-smooth);
|
234 |
-
box-shadow: 0 4px 10px -2px rgba(59, 130, 246, 0.35), var(--shadow-subtle);
|
235 |
-
}
|
236 |
-
#change-speaker-btn:hover {
|
237 |
-
background: linear-gradient(45deg, var(--accent-primary), var(--accent-primary-hover));
|
238 |
-
transform: translateY(-3px) scale(1.05);
|
239 |
-
box-shadow: 0 6px 12px -3px rgba(59, 130, 246, 0.45), var(--shadow-medium);
|
240 |
-
}
|
241 |
-
#change-speaker-btn svg {
|
242 |
-
width: 1.1em;
|
243 |
-
height: 1.1em;
|
244 |
-
margin-right: 0.5em;
|
245 |
-
fill: currentColor;
|
246 |
-
}
|
247 |
-
|
248 |
-
|
249 |
-
/* --- مودال عمومی --- */
|
250 |
-
.modal-overlay {
|
251 |
-
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
252 |
-
background-color: rgba(18, 24, 38, 0.6);
|
253 |
-
backdrop-filter: blur(8px) saturate(150%);
|
254 |
-
display: none; /* Hidden by default */
|
255 |
-
align-items: center; justify-content: center;
|
256 |
-
z-index: 1000; opacity: 0;
|
257 |
-
transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
258 |
-
}
|
259 |
-
.modal-overlay.visible { display: flex; opacity: 1; }
|
260 |
-
|
261 |
-
.modal-dialog {
|
262 |
-
background: var(--panel-bg);
|
263 |
-
padding: 2rem;
|
264 |
-
border-radius: var(--radius-card);
|
265 |
-
width: 90%;
|
266 |
-
box-shadow: var(--shadow-strong);
|
267 |
-
border: 1px solid var(--panel-border);
|
268 |
-
opacity: 0; /* For animation */
|
269 |
-
animation-duration: 0.35s;
|
270 |
-
animation-fill-mode: forwards;
|
271 |
-
}
|
272 |
-
.modal-overlay.visible .modal-dialog {
|
273 |
-
animation-name: modalZoomIn;
|
274 |
-
}
|
275 |
-
.modal-overlay.hiding .modal-dialog {
|
276 |
-
animation-name: modalZoomOut;
|
277 |
-
}
|
278 |
-
|
279 |
-
|
280 |
-
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--panel-border); }
|
281 |
-
.modal-header h2 { margin: 0; font-size: 1.6em; font-weight: 800; color: var(--accent-primary);}
|
282 |
-
.close-modal-btn { background: none; border: none; font-size: 2.5rem; cursor: pointer; color: var(--text-secondary); transition: var(--transition-smooth); line-height: 1; }
|
283 |
-
.close-modal-btn:hover { color: var(--accent-primary); transform: rotate(90deg) scale(1.1); }
|
284 |
-
|
285 |
-
|
286 |
-
/* --- مودال گالری گویندگان (اختصاصی) --- */
|
287 |
-
#speaker-modal .modal-dialog { /* Target specific modal dialog */
|
288 |
-
max-width: 700px;
|
289 |
-
max-height: 85vh; overflow-y: auto;
|
290 |
-
}
|
291 |
-
#speaker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1.2rem; }
|
292 |
-
@media (min-width: 640px) { #speaker-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); } }
|
293 |
-
.speaker-card { cursor: pointer; transition: var(--transition-smooth); text-align: center; position: relative;}
|
294 |
-
.speaker-card .speaker-visual {
|
295 |
-
border: 3px solid transparent;
|
296 |
-
border-radius: var(--radius-card);
|
297 |
-
overflow: hidden;
|
298 |
-
box-shadow: var(--shadow-subtle);
|
299 |
-
position: relative;
|
300 |
-
background-color: var(--input-bg);
|
301 |
-
transition: var(--transition-bounce);
|
302 |
-
padding: 6px;
|
303 |
-
}
|
304 |
-
.speaker-card:hover .speaker-visual {
|
305 |
-
transform: translateY(-5px) scale(1.06);
|
306 |
-
box-shadow: var(--shadow-medium);
|
307 |
-
/* border-color: rgba(var(--accent-secondary-rgb), 0.3); */ /* Requires CSS var for RGB components */
|
308 |
-
}
|
309 |
.speaker-card input[type="radio"] { display: none; }
|
310 |
-
.speaker-card img {
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
}
|
317 |
-
.
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
transform: scale(1.05);
|
324 |
-
}
|
325 |
-
.speaker-card input[type="radio"]:checked + .speaker-visual img {
|
326 |
-
border: 2px solid white;
|
327 |
-
transform: scale(1.05);
|
328 |
-
}
|
329 |
-
.speaker-card input[type="radio"]:checked + .speaker-visual .speaker-name {
|
330 |
-
color: #fff;
|
331 |
-
font-weight: 700;
|
332 |
-
}
|
333 |
-
|
334 |
-
/* --- مودال اطلاعات (اختصاصی) --- */
|
335 |
-
#info-modal .modal-dialog {
|
336 |
-
max-width: 480px; /* Smaller width for info */
|
337 |
-
}
|
338 |
-
#info-modal-content p {
|
339 |
-
font-size: 1em;
|
340 |
-
line-height: 1.7;
|
341 |
-
color: var(--text-secondary);
|
342 |
-
margin-bottom: 0.5rem;
|
343 |
-
}
|
344 |
-
#info-modal-content p strong {
|
345 |
-
color: var(--text-primary);
|
346 |
-
font-weight: 600;
|
347 |
-
}
|
348 |
-
#info-modal-content .range-info {
|
349 |
-
font-size: 0.9em;
|
350 |
-
color: var(--accent-primary);
|
351 |
-
font-weight: 500;
|
352 |
-
margin-top: 1rem;
|
353 |
-
display: block;
|
354 |
-
text-align: center;
|
355 |
-
}
|
356 |
-
|
357 |
-
|
358 |
-
/* --- Slider & Button & Output --- */
|
359 |
-
.slider-container { display: flex; align-items: center; gap: 1.2rem; }
|
360 |
-
input[type="range"] {
|
361 |
-
flex-grow: 1; -webkit-appearance: none; appearance: none;
|
362 |
-
width: 100%; height: 8px;
|
363 |
-
background: #EAF0F6;
|
364 |
-
border-radius: 4px; outline: none;
|
365 |
-
cursor: pointer;
|
366 |
-
transition: background 0.2s;
|
367 |
-
}
|
368 |
-
input[type="range"]::-webkit-slider-runnable-track {
|
369 |
-
background: linear-gradient(to right, var(--accent-secondary) 0%, var(--accent-primary) 100%);
|
370 |
-
height: 8px;
|
371 |
-
border-radius: 4px;
|
372 |
-
}
|
373 |
-
input[type="range"]::-webkit-slider-thumb {
|
374 |
-
-webkit-appearance: none; appearance: none;
|
375 |
-
width: 22px; height: 22px;
|
376 |
-
background: #fff;
|
377 |
-
border-radius: 50%; cursor: pointer;
|
378 |
-
border: 3px solid var(--accent-primary);
|
379 |
-
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
|
380 |
-
margin-top: -7px;
|
381 |
-
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
382 |
-
}
|
383 |
-
input[type="range"]::-webkit-slider-thumb:hover, input[type="range"]:focus::-webkit-slider-thumb {
|
384 |
-
transform: scale(1.2);
|
385 |
-
box-shadow: 0 3px 8px rgba(59, 130, 246, 0.35);
|
386 |
-
}
|
387 |
-
input[type="range"]::-moz-range-thumb {
|
388 |
-
width: 22px; height: 22px;
|
389 |
-
background: #fff;
|
390 |
-
border-radius: 50%; cursor: pointer;
|
391 |
-
border: 3px solid var(--accent-primary);
|
392 |
-
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
|
393 |
-
}
|
394 |
-
input[type="range"]::-moz-range-track {
|
395 |
-
background: linear-gradient(to right, var(--accent-secondary) 0%, var(--accent-primary) 100%);
|
396 |
-
height: 8px;
|
397 |
-
border-radius: 4px;
|
398 |
-
border: none;
|
399 |
-
}
|
400 |
-
#temperature-value {
|
401 |
-
font-weight: 700; background-color: var(--input-bg);
|
402 |
-
padding: 0.5rem 1rem;
|
403 |
-
border-radius: 8px;
|
404 |
-
border: 1px solid var(--panel-border);
|
405 |
-
min-width: 45px; text-align: center;
|
406 |
-
color: var(--accent-primary);
|
407 |
-
font-size: 1em;
|
408 |
-
box-shadow: var(--shadow-subtle);
|
409 |
-
}
|
410 |
-
|
411 |
-
#generate-btn {
|
412 |
-
width: 100%; padding: 1rem 1.5rem;
|
413 |
-
font-size: 1.25em; font-weight: 800;
|
414 |
-
font-family: var(--app-font);
|
415 |
-
background: linear-gradient(95deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
|
416 |
-
color: #fff;
|
417 |
-
border: none;
|
418 |
-
border-radius: var(--radius-input);
|
419 |
-
cursor: pointer;
|
420 |
-
transition: var(--transition-smooth), transform 0.15s ease-out;
|
421 |
-
box-shadow: 0 5px 15px -4px rgba(59, 130, 246, 0.45), 0 5px 15px -4px rgba(16, 185, 129, 0.35);
|
422 |
-
position: relative;
|
423 |
-
overflow: hidden;
|
424 |
-
letter-spacing: 0.5px;
|
425 |
-
}
|
426 |
-
#generate-btn::before {
|
427 |
-
content: ''; position: absolute;
|
428 |
-
top: 0; left: -180%; width: 80%; height: 100%;
|
429 |
-
background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 100%);
|
430 |
-
transform: skewX(-30deg);
|
431 |
-
transition: left 0.8s cubic-bezier(0.23, 1, 0.32, 1);
|
432 |
-
}
|
433 |
-
#generate-btn:hover::before { left: 180%; }
|
434 |
-
#generate-btn:hover:not(:disabled) {
|
435 |
-
transform: translateY(-5px) scale(1.02);
|
436 |
-
box-shadow: 0 8px 20px -4px rgba(59, 130, 246, 0.55), 0 8px 20px -4px rgba(16, 185, 129, 0.45);
|
437 |
-
}
|
438 |
-
#generate-btn:active:not(:disabled) {
|
439 |
-
transform: translateY(-2px) scale(0.98);
|
440 |
-
}
|
441 |
-
#generate-btn:disabled {
|
442 |
-
background: #B8C2CC;
|
443 |
-
cursor: not-allowed; box-shadow: none; color: #E8EEF3;
|
444 |
-
transform: none;
|
445 |
-
}
|
446 |
-
#generate-btn:disabled::before { display: none; }
|
447 |
-
#generate-btn svg {
|
448 |
-
display:inline-block; margin-left: 0.5em; width:1.2em; height:1.2em;
|
449 |
-
vertical-align: middle;
|
450 |
-
}
|
451 |
-
|
452 |
-
#output-section {
|
453 |
-
margin-top: 3rem;
|
454 |
-
padding: 2rem;
|
455 |
-
background-color: var(--input-bg);
|
456 |
-
border-radius: var(--radius-card);
|
457 |
-
min-height: 200px;
|
458 |
-
display: flex; align-items: center; justify-content: center;
|
459 |
-
flex-direction: column; gap: 1.5rem;
|
460 |
-
border: 2px dashed var(--panel-border);
|
461 |
-
transition: var(--transition-smooth), border-color 0.5s, box-shadow 0.5s;
|
462 |
-
position: relative;
|
463 |
-
box-shadow: var(--shadow-subtle) inset;
|
464 |
-
}
|
465 |
-
#output-section.has-content {
|
466 |
-
background-color: #fff;
|
467 |
-
border-style: solid;
|
468 |
-
border-color: var(--accent-secondary);
|
469 |
-
box-shadow: 0 0 30px -8px rgba(16, 185, 129, 0.25);
|
470 |
-
padding: 1.5rem;
|
471 |
-
}
|
472 |
-
#output-section.has-content #status-message,
|
473 |
-
#output-section.has-content #loading-animation-wrapper {
|
474 |
-
display: none !important;
|
475 |
-
}
|
476 |
-
|
477 |
-
#status-message { font-weight: 500; color: var(--text-secondary); text-align: center; font-size: 1.1em; }
|
478 |
-
#audio-player { width: 100%; margin-top: 0; display: none; border-radius: 10px; box-shadow: var(--shadow-medium); }
|
479 |
-
#output-section.has-content #audio-player {
|
480 |
-
margin-top: 0;
|
481 |
-
}
|
482 |
-
#audio-player::-webkit-media-controls-panel { background-color: #fdfdff; border-radius: 10px; padding: 5px; box-shadow: var(--shadow-subtle) inset;}
|
483 |
-
#audio-player::-webkit-media-controls-play-button { color: var(--accent-primary); background-color: rgba(59, 130, 246, 0.1); border-radius: 50%; margin: 5px;}
|
484 |
-
#audio-player::-webkit-media-controls-current-time-display,
|
485 |
-
#audio-player::-webkit-media-controls-time-remaining-display { color: var(--text-secondary); font-weight: 500; }
|
486 |
-
#audio-player::-webkit-media-controls-timeline { background-color: #EAF0F6; border-radius: 5px; margin: 0 10px;}
|
487 |
-
|
488 |
-
|
489 |
-
/* --- انیمیشن پردازش --- */
|
490 |
-
#loading-animation-wrapper {
|
491 |
-
display: none;
|
492 |
-
flex-direction: column;
|
493 |
-
align-items: center;
|
494 |
-
justify-content: center;
|
495 |
-
gap: 1.8rem;
|
496 |
-
width: 100%;
|
497 |
-
min-height: 150px;
|
498 |
-
}
|
499 |
-
.orbital-loader {
|
500 |
-
width: 110px;
|
501 |
-
height: 110px;
|
502 |
-
position: relative;
|
503 |
-
animation: rotate-loader-orbital 10s linear infinite;
|
504 |
-
}
|
505 |
-
.orbit {
|
506 |
-
position: absolute;
|
507 |
-
top: 50%; left: 50%;
|
508 |
-
border: 2px dashed rgba(59, 130, 246, 0.25);
|
509 |
-
border-radius: 50%;
|
510 |
-
transform-origin: center center;
|
511 |
-
}
|
512 |
-
.orbit:nth-child(1) { width: 35px; height: 35px; margin: -17.5px 0 0 -17.5px; animation: orbit-spin 2.8s linear infinite reverse; }
|
513 |
-
.orbit:nth-child(2) { width: 65px; height: 65px; margin: -32.5px 0 0 -32.5px; animation: orbit-spin 3.8s linear infinite; }
|
514 |
-
.orbit:nth-child(3) { width: 95px; height: 95px; margin: -47.5px 0 0 -47.5px; animation: orbit-spin 4.8s linear infinite reverse; }
|
515 |
-
|
516 |
-
.orbit .satellite {
|
517 |
-
position: absolute;
|
518 |
-
width: 10px; height: 10px;
|
519 |
-
border-radius: 50%;
|
520 |
-
background-color: var(--accent-primary);
|
521 |
-
box-shadow: 0 0 8px var(--accent-primary), 0 0 12px var(--accent-secondary);
|
522 |
-
}
|
523 |
-
.orbit:nth-child(1) .satellite { top: -5px; left: 50%; animation: satellite-pulse-1 1.4s ease-in-out infinite alternate; }
|
524 |
-
.orbit:nth-child(2) .satellite { top: 50%; left: -5px; background-color: var(--accent-secondary); animation: satellite-pulse-2 1.4s 0.2s ease-in-out infinite alternate; }
|
525 |
-
.orbit:nth-child(3) .satellite { bottom: -5px; right: 50%; animation: satellite-pulse-3 1.4s 0.4s ease-in-out infinite alternate;}
|
526 |
-
|
527 |
-
@keyframes rotate-loader-orbital { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
528 |
-
@keyframes orbit-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
529 |
-
@keyframes satellite-pulse-1 {
|
530 |
-
from { transform: scale(0.7) translateX(-50%); opacity: 0.6; }
|
531 |
-
to { transform: scale(1.1) translateX(-50%); opacity: 1; }
|
532 |
-
}
|
533 |
-
@keyframes satellite-pulse-2 {
|
534 |
-
from { transform: scale(0.7) translateY(-50%); opacity: 0.6; }
|
535 |
-
to { transform: scale(1.1) translateY(-50%); opacity: 1; }
|
536 |
-
}
|
537 |
-
@keyframes satellite-pulse-3 {
|
538 |
-
from { transform: scale(0.7) translateX(50%); opacity: 0.6; }
|
539 |
-
to { transform: scale(1.1) translateX(50%); opacity: 1; }
|
540 |
-
}
|
541 |
-
#loading-text {
|
542 |
-
font-size: 1.2em;
|
543 |
-
font-weight: 700;
|
544 |
-
color: var(--text-primary);
|
545 |
-
text-align: center;
|
546 |
-
background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
|
547 |
-
-webkit-background-clip: text;
|
548 |
-
-webkit-text-fill-color: transparent;
|
549 |
-
}
|
550 |
-
|
551 |
</style>
|
552 |
</head>
|
553 |
<body>
|
554 |
<div class="container">
|
555 |
<header class="app-header">
|
556 |
-
<h1
|
557 |
-
<p
|
558 |
</header>
|
559 |
|
560 |
<main class="main-content">
|
561 |
<form id="tts-form">
|
562 |
<div class="form-group">
|
563 |
-
<label for="text-input">📝 متن
|
564 |
-
<textarea id="text-input" rows="
|
565 |
-
<div class="char-counter-wrapper">
|
566 |
-
<span id="char-count">0</span> / <span id="char-max">50000</span> نویسه
|
567 |
-
</div>
|
568 |
</div>
|
569 |
<div class="form-group">
|
570 |
-
<label for="prompt-input">🗣️
|
571 |
-
<input type="text" id="prompt-input"
|
572 |
</div>
|
573 |
|
574 |
<div class="form-group">
|
575 |
-
<label>🎤
|
576 |
<div id="selected-speaker-display">
|
577 |
-
<div id="selected-speaker-card"
|
578 |
<img id="selected-speaker-img" src="" alt="عکس گوینده">
|
579 |
<div id="selected-speaker-info">
|
580 |
<h3 id="selected-speaker-name"></h3>
|
581 |
-
<p
|
582 |
</div>
|
583 |
</div>
|
584 |
-
<button type="button" id="change-speaker-btn">
|
585 |
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
586 |
-
<path d="M12 2.5a5.5 5.5 0 0 1 5.5 5.5c0 1.826-.889 3.442-2.257 4.494.04.054.082.106.126.158A7.5 7.5 0 0 1 21.75 18H2.25a7.5 7.5 0 0 1 6.381-5.348c.044-.052.087-.104.127-.158A5.502 5.502 0 0 1 6.5 8a5.5 5.5 0 0 1 5.5-5.5Zm3.018 9.589A7.502 7.502 0 0 0 12 11.5a7.502 7.502 0 0 0-3.018.589C6.44 12.51 5.018 13.56 4.135 14.997a.75.75 0 0 0 .614.853A10.51 10.51 0 0 0 12 16.5a10.51 10.51 0 0 0 7.251-.65.75.75 0 0 0 .614-.853 9.998 9.998 0 0 0-4.847-2.408Z" />
|
587 |
-
</svg>
|
588 |
-
تغییر گوینده
|
589 |
-
</button>
|
590 |
</div>
|
591 |
</div>
|
592 |
-
|
593 |
<div class="form-group">
|
594 |
-
<
|
595 |
-
<label for="temperature-slider">🌡️ میزان خلاقیت و نوآوری صدا</label>
|
596 |
-
<div class="info-icon" id="temp-info-icon" role="button" tabindex="0" aria-label="اطلاعات بیشتر">!
|
597 |
-
<!-- Tooltip text removed, will be shown in modal -->
|
598 |
-
</div>
|
599 |
-
</div>
|
600 |
<div class="slider-container">
|
601 |
<input type="range" id="temperature-slider" min="0.1" max="1.5" step="0.05" value="0.9">
|
602 |
<span id="temperature-value">0.9</span>
|
603 |
</div>
|
604 |
</div>
|
605 |
|
606 |
-
<button type="submit" id="generate-btn"
|
607 |
</form>
|
608 |
|
609 |
<div id="output-section">
|
610 |
-
<div id="status-message"
|
611 |
-
<div id="loading-animation-wrapper">
|
612 |
-
<div class="orbital-loader">
|
613 |
-
<div class="orbit"><div class="satellite"></div></div>
|
614 |
-
<div class="orbit"><div class="satellite"></div></div>
|
615 |
-
<div class="orbit"><div class="satellite"></div></div>
|
616 |
-
</div>
|
617 |
-
<p id="loading-text">در حال پردازش هوشمند و تولید صدا...</p>
|
618 |
-
</div>
|
619 |
<audio id="audio-player" controls></audio>
|
620 |
</div>
|
621 |
</main>
|
622 |
</div>
|
623 |
|
624 |
-
|
625 |
-
|
626 |
-
<div class="modal-dialog">
|
627 |
<div class="modal-header">
|
628 |
-
<h2
|
629 |
-
<button type="button" class="close-modal-btn"
|
630 |
-
</div>
|
631 |
-
<div id="speaker-grid">
|
632 |
-
<!-- Speaker cards will be generated here by JS -->
|
633 |
</div>
|
|
|
634 |
</div>
|
635 |
</div>
|
636 |
-
|
637 |
-
<!--
|
638 |
-
<div id="info-modal" class="modal-overlay">
|
639 |
-
<div class="modal-dialog">
|
640 |
-
<div class="modal-header">
|
641 |
-
<h2>🌡️ خلاقیت و نوآوری صدا</h2>
|
642 |
-
<button type="button" class="close-modal-btn" data-modal-id="info-modal" aria-label="بستن توضیحات">×</button>
|
643 |
-
</div>
|
644 |
-
<div id="info-modal-content">
|
645 |
-
<p>این تنظیم مشخص میکند که هوش مصنوعی تا چه حد در تولید صدا <strong>خلاقیت</strong> به خرج دهد.</p>
|
646 |
-
<p><strong>مقادیر بالاتر:</strong> منجر به صدایی متنوعتر، پویاتر و گاهی اوقات غیرمنتظرهتر میشود. مناسب برای زمانی که به دنبال لحنی خاص و منحصربهفرد هستید.</p>
|
647 |
-
<p><strong>مقادیر پایینتر:</strong> صدایی پایدارتر، قابل پیشبینیتر و نزدیکتر به صدای استاندارد گوینده تولید میکند. مناسب برای خوانش متون رسمی یا زمانی که ثبات لحن اهمیت دارد.</p>
|
648 |
-
<span class="range-info">محدوده پیشنهادی: ۰.۱ (پایدار) تا ۱.۵ (بسیار خلاق)</span>
|
649 |
-
</div>
|
650 |
-
</div>
|
651 |
-
</div>
|
652 |
-
|
653 |
-
|
654 |
-
<input type="hidden" id="selected_speaker_id_storage" value="Charon">
|
655 |
|
656 |
<script>
|
657 |
document.addEventListener('DOMContentLoaded', () => {
|
@@ -661,247 +158,144 @@
|
|
661 |
const FILE_URL_BASE = `${HF_SPACE_URL}/gradio_api/file=`;
|
662 |
const FN_INDEX = 1;
|
663 |
|
|
|
664 |
const speakers = [
|
665 |
-
{ id: "
|
666 |
-
{ id: "
|
667 |
-
{ id: "
|
668 |
-
{ id: "
|
669 |
-
{ id: "
|
670 |
-
{ id: "
|
671 |
-
{ id: "
|
672 |
-
{ id: "
|
673 |
-
{ id: "
|
674 |
-
{ id: "
|
675 |
-
{ id: "
|
676 |
-
{ id: "
|
677 |
-
{ id: "
|
678 |
-
{ id: "
|
679 |
-
{ id: "
|
680 |
-
{ id: "
|
681 |
-
{ id: "
|
682 |
-
{ id: "
|
683 |
-
{ id: "
|
684 |
-
{ id: "
|
685 |
-
{ id: "
|
686 |
-
{ id: "
|
687 |
-
{ id: "
|
688 |
-
{ id: "
|
689 |
-
{ id: "
|
690 |
-
{ id: "
|
691 |
-
{ id: "
|
692 |
-
{ id: "Kore", name: "
|
693 |
-
{ id: "Fenrir", name: "
|
694 |
-
{ id: "Leda", name: "لیدا (زن)"
|
695 |
];
|
696 |
-
|
697 |
const form = document.getElementById('tts-form');
|
698 |
const textInput = document.getElementById('text-input');
|
699 |
const promptInput = document.getElementById('prompt-input');
|
700 |
const tempSlider = document.getElementById('temperature-slider');
|
701 |
const tempValueSpan = document.getElementById('temperature-value');
|
702 |
const generateBtn = document.getElementById('generate-btn');
|
703 |
-
|
704 |
-
const outputSection = document.getElementById('output-section');
|
705 |
const statusMessage = document.getElementById('status-message');
|
706 |
const audioPlayer = document.getElementById('audio-player');
|
707 |
-
|
708 |
-
|
709 |
const selectedSpeakerIdStorage = document.getElementById('selected_speaker_id_storage');
|
|
|
710 |
const changeSpeakerBtn = document.getElementById('change-speaker-btn');
|
711 |
-
const
|
712 |
const speakerGridInModal = document.getElementById('speaker-grid');
|
713 |
const selectedSpeakerImgDisplay = document.getElementById('selected-speaker-img');
|
714 |
const selectedSpeakerNameDisplay = document.getElementById('selected-speaker-name');
|
715 |
-
|
716 |
-
|
717 |
-
// Modal Elements
|
718 |
-
const speakerModal = document.getElementById('speaker-modal');
|
719 |
-
const infoModal = document.getElementById('info-modal');
|
720 |
-
const tempInfoIcon = document.getElementById('temp-info-icon');
|
721 |
-
|
722 |
-
|
723 |
-
// Character Counter
|
724 |
-
const charCountSpan = document.getElementById('char-count');
|
725 |
-
const charMaxSpan = document.getElementById('char-max');
|
726 |
-
const MAX_CHARS = 50000;
|
727 |
-
charMaxSpan.textContent = MAX_CHARS.toLocaleString('fa-IR');
|
728 |
-
|
729 |
-
textInput.addEventListener('input', () => {
|
730 |
-
const currentLength = textInput.value.length;
|
731 |
-
charCountSpan.textContent = currentLength.toLocaleString('fa-IR');
|
732 |
-
if (currentLength > MAX_CHARS) {
|
733 |
-
charCountSpan.style.color = 'var(--accent-secondary-hover)';
|
734 |
-
} else {
|
735 |
-
charCountSpan.style.color = 'var(--accent-primary)';
|
736 |
-
}
|
737 |
-
});
|
738 |
-
|
739 |
-
|
740 |
function getSpeakerById(id) {
|
741 |
-
return speakers.find(s => s.id === id)
|
742 |
}
|
743 |
-
|
744 |
-
function getImageUrl(speaker, index
|
745 |
-
const
|
746 |
-
|
747 |
-
|
748 |
-
if (
|
749 |
-
|
|
|
|
|
750 |
}
|
751 |
|
752 |
function updateSelectedSpeakerDisplay(speakerId) {
|
753 |
const speaker = getSpeakerById(speakerId);
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
}
|
761 |
|
762 |
function createSpeakerCardsInModal() {
|
763 |
-
speakerGridInModal.innerHTML = '';
|
764 |
speakers.forEach((speaker, index) => {
|
765 |
-
const
|
766 |
-
|
767 |
-
|
|
|
768 |
const isChecked = speaker.id === selectedSpeakerIdStorage.value ? 'checked' : '';
|
769 |
-
|
|
|
770 |
<input type="radio" name="modal_speaker_selection" value="${speaker.id}" id="modal-speaker-${speaker.id}" ${isChecked}>
|
771 |
<div class="speaker-visual">
|
772 |
-
<img src="${getImageUrl(speaker, index
|
773 |
<div class="speaker-name">${speaker.name}</div>
|
774 |
</div>
|
775 |
`;
|
776 |
-
|
777 |
-
|
778 |
-
const radio = cardLabel.querySelector('input[type="radio"]');
|
779 |
-
if(radio) radio.checked = true;
|
780 |
-
}
|
781 |
updateSelectedSpeakerDisplay(speaker.id);
|
782 |
-
|
783 |
});
|
784 |
-
|
|
|
785 |
});
|
786 |
}
|
787 |
-
|
788 |
-
// --- Modal Management ---
|
789 |
-
function showModal(modalElement) {
|
790 |
-
modalElement.classList.add('visible');
|
791 |
-
// Focus first focusable element in modal
|
792 |
-
setTimeout(() => {
|
793 |
-
const firstFocusable = modalElement.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
794 |
-
if (firstFocusable) firstFocusable.focus();
|
795 |
-
}, 50); // Allow transition to start
|
796 |
-
}
|
797 |
-
|
798 |
-
function hideModal(modalElement) {
|
799 |
-
modalElement.classList.add('hiding'); // Add class for exit animation
|
800 |
-
modalElement.addEventListener('animationend', () => {
|
801 |
-
modalElement.classList.remove('visible', 'hiding');
|
802 |
-
}, { once: true });
|
803 |
-
}
|
804 |
-
|
805 |
-
// Speaker Modal Listeners
|
806 |
changeSpeakerBtn.addEventListener('click', () => {
|
807 |
-
createSpeakerCardsInModal();
|
808 |
-
|
809 |
-
});
|
810 |
-
selectedSpeakerCard.addEventListener('click', () => {
|
811 |
-
createSpeakerCardsInModal();
|
812 |
-
showModal(speakerModal);
|
813 |
-
});
|
814 |
-
|
815 |
-
// Info Modal Listener
|
816 |
-
tempInfoIcon.addEventListener('click', () => showModal(infoModal));
|
817 |
-
tempInfoIcon.addEventListener('keydown', (e) => {
|
818 |
-
if (e.key === 'Enter' || e.key === ' ') {
|
819 |
-
e.preventDefault();
|
820 |
-
showModal(infoModal);
|
821 |
-
}
|
822 |
-
});
|
823 |
-
|
824 |
-
|
825 |
-
// General Modal Close Listeners (for all modals)
|
826 |
-
document.querySelectorAll('.modal-overlay').forEach(overlay => {
|
827 |
-
overlay.addEventListener('click', (e) => {
|
828 |
-
if (e.target === overlay) { // Click on backdrop
|
829 |
-
hideModal(overlay);
|
830 |
-
}
|
831 |
-
});
|
832 |
-
});
|
833 |
-
document.querySelectorAll('.close-modal-btn').forEach(button => {
|
834 |
-
button.addEventListener('click', () => {
|
835 |
-
const modalId = button.dataset.modalId;
|
836 |
-
if (modalId) {
|
837 |
-
hideModal(document.getElementById(modalId));
|
838 |
-
}
|
839 |
-
});
|
840 |
});
|
841 |
-
|
842 |
-
|
843 |
-
|
|
|
844 |
}
|
845 |
});
|
846 |
|
847 |
-
|
848 |
tempSlider.addEventListener('input', () => { tempValueSpan.textContent = tempSlider.value; });
|
849 |
|
850 |
-
|
851 |
-
function showLoadingState() {
|
852 |
-
outputSection.classList.remove('has-content');
|
853 |
-
statusMessage.style.display = 'none';
|
854 |
-
audioPlayer.style.display = 'none';
|
855 |
-
audioPlayer.src = '';
|
856 |
-
loadingAnimationWrapper.style.display = 'flex';
|
857 |
-
generateBtn.disabled = true;
|
858 |
-
generateBtn.innerHTML = `
|
859 |
-
<svg aria-hidden="true" role="status" fill="currentColor" viewBox="0 0 100 101" style="display:inline-block; margin-left: 0.5em; width:1.2em; height:1.2em; vertical-align: middle; animation: spin 1s linear infinite;">
|
860 |
-
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="#E5E7EB"/>
|
861 |
-
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0492C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentColor"/>
|
862 |
-
</svg>
|
863 |
-
در حال پردازش...
|
864 |
-
`;
|
865 |
-
}
|
866 |
-
|
867 |
-
function showResultState(isSuccess, message = '') {
|
868 |
-
loadingAnimationWrapper.style.display = 'none';
|
869 |
-
if (isSuccess) {
|
870 |
-
statusMessage.style.display = 'none';
|
871 |
-
audioPlayer.style.display = 'block';
|
872 |
-
outputSection.classList.add('has-content');
|
873 |
-
} else {
|
874 |
-
statusMessage.textContent = message || 'خطایی رخ داد. لطفاً دوباره تلاش کنید.';
|
875 |
-
statusMessage.style.display = 'block';
|
876 |
-
audioPlayer.style.display = 'none';
|
877 |
-
outputSection.classList.remove('has-content');
|
878 |
-
}
|
879 |
-
generateBtn.disabled = false;
|
880 |
-
generateBtn.innerHTML = '✨ تولید صدا با آلفا';
|
881 |
-
}
|
882 |
-
|
883 |
async function generateAudio(event) {
|
884 |
event.preventDefault();
|
885 |
-
|
|
|
|
|
|
|
|
|
886 |
|
887 |
const text = textInput.value;
|
|
|
|
|
|
|
|
|
|
|
888 |
if (!text.trim()) {
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
if (text.length > MAX_CHARS) {
|
893 |
-
showResultState(false, `خطا: طول متن بیش از ${MAX_CHARS.toLocaleString('fa-IR')} نویسه است.`);
|
894 |
return;
|
895 |
}
|
896 |
-
|
897 |
-
const promptVal = promptInput.value;
|
898 |
-
const temperatureVal = parseFloat(tempSlider.value);
|
899 |
-
const selectedSpeakerVal = selectedSpeakerIdStorage.value;
|
900 |
-
const sessionHash = Math.random().toString(36).substring(2);
|
901 |
-
|
902 |
const payload = {
|
903 |
fn_index: FN_INDEX,
|
904 |
-
data: [false, null, text,
|
905 |
event_data: null,
|
906 |
session_hash: sessionHash
|
907 |
};
|
@@ -915,78 +309,67 @@
|
|
915 |
|
916 |
if (!joinQueueResponse.ok) {
|
917 |
const errorBody = await joinQueueResponse.text();
|
918 |
-
|
919 |
-
throw new Error(`خطا در برقراری ارتباط با سرویس آلفا (${joinQueueResponse.status}). لطفا لحظاتی دیگر تلاش کنید.`);
|
920 |
}
|
921 |
-
|
|
|
|
|
|
|
|
|
|
|
922 |
let finalFilePath = null;
|
923 |
-
|
924 |
-
const timeoutDuration = 90000;
|
925 |
|
926 |
-
while (
|
927 |
-
const
|
928 |
-
if (
|
929 |
-
const errorBody = await dataResponse.text();
|
930 |
-
console.error("Get Data Error Body:", errorBody);
|
931 |
-
throw new Error(`خطا در دریافت داده از سرویس (${dataResponse.status})`);
|
932 |
-
}
|
933 |
|
934 |
-
|
935 |
-
const lines =
|
|
|
936 |
|
937 |
for (const line of lines) {
|
938 |
if (!line.startsWith('data:')) continue;
|
|
|
939 |
try {
|
940 |
const data = JSON.parse(line.substring(5));
|
941 |
-
if (data.msg === 'process_generating'
|
942 |
-
|
943 |
-
}
|
|
|
944 |
if (data.success && data.output.data && data.output.data[0] && (data.output.data[0].name || data.output.data[0].path)) {
|
945 |
finalFilePath = data.output.data[0].name || data.output.data[0].path;
|
946 |
} else {
|
947 |
-
console.error("
|
948 |
-
throw new Error(data.output?.error || 'خطای ناشناخته در پردازش سرور.');
|
949 |
}
|
950 |
-
break;
|
951 |
-
} else if (data.msg === 'queue_full') {
|
952 |
-
throw new Error('صف پردازش پر است. لطفا کمی بعد تلاش کنید.');
|
953 |
}
|
954 |
-
} catch (e) {
|
955 |
-
console.warn("Error parsing JSON from stream:", e, "Line:", line);
|
956 |
-
}
|
957 |
}
|
958 |
-
if (finalFilePath) break;
|
959 |
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
960 |
}
|
961 |
-
|
962 |
if (finalFilePath) {
|
|
|
963 |
const audioUrl = `${FILE_URL_BASE}${finalFilePath}`;
|
964 |
audioPlayer.src = audioUrl;
|
965 |
-
|
966 |
-
|
967 |
-
throw new Error('پردازش بیش از حد طول کشید و متوقف شد.');
|
968 |
} else {
|
969 |
-
|
970 |
}
|
971 |
|
972 |
} catch (error) {
|
973 |
-
console.error('خطا در فرآیند
|
974 |
-
|
|
|
|
|
|
|
975 |
}
|
976 |
}
|
977 |
-
|
978 |
-
updateSelectedSpeakerDisplay(selectedSpeakerIdStorage.value
|
979 |
form.addEventListener('submit', generateAudio);
|
980 |
-
|
981 |
-
statusMessage.style.display = 'block';
|
982 |
-
loadingAnimationWrapper.style.display = 'none';
|
983 |
-
audioPlayer.style.display = 'none';
|
984 |
-
outputSection.classList.remove('has-content');
|
985 |
-
|
986 |
-
const styleSheet = document.createElement("style")
|
987 |
-
styleSheet.type = "text/css"
|
988 |
-
styleSheet.innerText = `@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }`;
|
989 |
-
document.head.appendChild(styleSheet);
|
990 |
});
|
991 |
</script>
|
992 |
</body>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Alpha TTS - رابط کاربری هوشمند با عکس</title>
|
7 |
<style>
|
8 |
+
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700;800&display=swap');
|
9 |
|
10 |
:root {
|
11 |
--app-font: 'Vazirmatn', sans-serif;
|
12 |
+
--app-header-grad-start: #1a2980;
|
13 |
+
--app-header-grad-end: #26d0ce;
|
14 |
+
--app-panel-bg: #FFFFFF;
|
15 |
+
--app-input-bg: #F8F9FA;
|
16 |
+
--app-button-bg: #5f27cd;
|
17 |
+
--app-button-hover-bg: #481e9e;
|
18 |
+
--app-main-bg: linear-gradient(170deg, #F3E8FF 0%, #E0F2FE 100%);
|
19 |
+
--app-text-primary: #2c3e50;
|
20 |
+
--app-text-secondary: #555;
|
21 |
+
--app-border-color: #E0E0E0;
|
|
|
|
|
22 |
--radius-card: 24px;
|
23 |
+
--radius-input: 12px;
|
24 |
+
--shadow-card: 0 10px 30px -5px rgba(0,0,0,0.08);
|
25 |
+
--shadow-button: 0 4px 15px -2px rgba(95, 39, 205, 0.4);
|
26 |
+
--speaker-selected-glow: 0 0 15px rgba(95, 39, 205, 0.5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
|
|
|
29 |
body {
|
30 |
font-family: var(--app-font);
|
31 |
direction: rtl;
|
32 |
+
background: var(--app-main-bg);
|
33 |
+
color: var(--app-text-primary);
|
34 |
font-size: 16px;
|
35 |
+
line-height: 1.65;
|
36 |
margin: 0;
|
37 |
+
padding: 0;
|
38 |
min-height: 100vh;
|
39 |
-webkit-font-smoothing: antialiased;
|
40 |
-moz-osx-font-smoothing: grayscale;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
|
|
42 |
|
43 |
+
.container { max-width: 800px; width: 95%; margin: 0 auto; padding-bottom: 40px; }
|
44 |
+
.app-header { padding: 3rem 1.5rem 5rem 1.5rem; text-align: center; background-image: linear-gradient(135deg, var(--app-header-grad-start) 0%, var(--app-header-grad-end) 100%); color: white; border-bottom-left-radius: var(--radius-card); border-bottom-right-radius: var(--radius-card); box-shadow: 0 6px 20px -5px rgba(0,0,0,0.2); }
|
45 |
+
.app-header h1 { font-size: 2.8em; font-weight: 800; margin:0 0 0.5rem 0; text-shadow: 0 2px 4px rgba(0,0,0,0.15); }
|
46 |
+
.app-header p { font-size: 1.2em; color: rgba(255,255,255,0.9); margin-top:0; opacity: 0.9; }
|
47 |
+
.main-content { padding: 2.5rem; margin: -3.5rem auto 2rem auto; background-color: var(--app-panel-bg); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
|
48 |
+
.form-group { margin-bottom: 2.5rem; }
|
49 |
+
label { display: block; font-weight: 700; color: var(--app-text-primary); font-size: 1.1em; margin-bottom: 0.8rem; }
|
50 |
+
textarea, input[type="text"] { width: 100%; padding: 1rem; border-radius: var(--radius-input); border: 2px solid var(--app-border-color); background-color: var(--app-input-bg); box-shadow: none; font-family: var(--app-font); font-size: 1rem; box-sizing: border-box; transition: all 0.2s ease-in-out; }
|
51 |
+
textarea:focus, input[type="text"]:focus { outline: none; border-color: var(--app-button-bg); box-shadow: 0 0 0 3px rgba(95, 39, 205, 0.2); background-color: #fff; }
|
52 |
+
|
53 |
+
#selected-speaker-display { text-align: center; }
|
54 |
+
#selected-speaker-card { display: inline-flex; align-items: center; background: #fff; border-radius: 99px; padding: 10px; box-shadow: 0 5px 20px rgba(0,0,0,0.1); border: 2px solid var(--app-border-color); }
|
55 |
+
#selected-speaker-card img { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; margin-left: 15px; background-color: #eee; }
|
56 |
+
#selected-speaker-info h3 { margin: 0; font-size: 1.4em; }
|
57 |
+
#selected-speaker-info p { margin: 5px 0 0; color: var(--app-text-secondary); font-size: 0.9em; }
|
58 |
+
#change-speaker-btn { display: block; margin: 1rem auto 0; padding: 8px 20px; border-radius: 8px; background-color: var(--app-input-bg); border: 1px solid var(--app-border-color); cursor: pointer; font-family: var(--app-font); font-weight: 500; transition: all 0.2s ease; }
|
59 |
+
#change-speaker-btn:hover { background-color: #e9ecef; border-color: #ced4da; }
|
60 |
+
|
61 |
+
#speaker-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(5px); display: none; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: opacity 0.3s ease; }
|
62 |
+
#speaker-modal.visible { display: flex; opacity: 1; }
|
63 |
+
.modal-content { background: #fff; padding: 2rem; border-radius: var(--radius-card); width: 90%; max-width: 700px; max-height: 80vh; overflow-y: auto; transform: scale(0.95); transition: transform 0.3s ease; }
|
64 |
+
#speaker-modal.visible .modal-content { transform: scale(1); }
|
65 |
+
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
|
66 |
+
.modal-header h2 { margin: 0; }
|
67 |
+
.close-modal-btn { background: none; border: none; font-size: 2rem; cursor: pointer; color: #aaa; transition: color 0.2s ease; }
|
68 |
+
.close-modal-btn:hover { color: #333; }
|
69 |
+
|
70 |
+
#speaker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1rem; }
|
71 |
+
@media (min-width: 576px) { #speaker-grid { grid-template-columns: repeat(4, 1fr); } }
|
72 |
+
.speaker-card { cursor: pointer; transition: all 0.3s ease; }
|
73 |
+
.speaker-card .speaker-visual { border: 3px solid transparent; border-radius: var(--radius-card); overflow: hidden; text-align: center; box-shadow: 0 4px 10px rgba(0,0,0,0.05); position: relative; background-color: #fff; }
|
74 |
+
.speaker-card:hover .speaker-visual { transform: translateY(-3px); box-shadow: 0 6px 15px rgba(0,0,0,0.1); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
.speaker-card input[type="radio"] { display: none; }
|
76 |
+
.speaker-card img { width: 100%; height: 120px; object-fit: cover; display: block; background-color: #eee; }
|
77 |
+
.speaker-card .speaker-name { padding: 0.7rem 0.5rem; font-weight: 500; font-size: 0.9em; }
|
78 |
+
.speaker-card input[type="radio"]:checked + .speaker-visual { border-color: var(--app-button-bg); box-shadow: var(--speaker-selected-glow); }
|
79 |
+
|
80 |
+
.slider-container { display: flex; align-items: center; gap: 1rem; }
|
81 |
+
input[type="range"] { flex-grow: 1; cursor: pointer; }
|
82 |
+
#temperature-value { font-weight: bold; background-color: var(--app-input-bg); padding: 0.2rem 0.8rem; border-radius: 8px; border: 1px solid var(--app-border-color); min-width: 40px; text-align: center; }
|
83 |
+
#generate-btn { width: 100%; padding: 1rem 1.5rem; font-size: 1.2em; font-weight: 700; font-family: var(--app-font); background: var(--app-button-bg); color: white; border: none; border-radius: var(--radius-input); cursor: pointer; transition: all 0.3s ease; box-shadow: var(--shadow-button); }
|
84 |
+
#generate-btn:hover:not(:disabled) { background-color: var(--app-button-hover-bg); transform: translateY(-2px); box-shadow: 0 6px 20px -3px rgba(95, 39, 205, 0.5); }
|
85 |
+
#generate-btn:disabled { background-color: #999; cursor: not-allowed; box-shadow: none; }
|
86 |
+
#output-section { margin-top: 2.5rem; padding: 1.5rem; background-color: #fff; border-radius: var(--radius-card); min-height: 100px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 1rem; border: 1px solid var(--app-border-color); }
|
87 |
+
#status-message { font-weight: 500; color: var(--app-text-secondary); }
|
88 |
+
#audio-player { width: 100%; margin-top: 1rem; display: none; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
</style>
|
90 |
</head>
|
91 |
<body>
|
92 |
<div class="container">
|
93 |
<header class="app-header">
|
94 |
+
<h1>آلفا TTS</h1>
|
95 |
+
<p>جادوی تبدیل متن به صدا، به سبک شما</p>
|
96 |
</header>
|
97 |
|
98 |
<main class="main-content">
|
99 |
<form id="tts-form">
|
100 |
<div class="form-group">
|
101 |
+
<label for="text-input">📝 متن برای تبدیل</label>
|
102 |
+
<textarea id="text-input" rows="5" placeholder="اینجا متن خود را به فارسی وارد کنید...">این یک آزمایش برای بررسی کیفیت صدای تولید شده توسط هوش مصنوعی آلفا است.</textarea>
|
|
|
|
|
|
|
103 |
</div>
|
104 |
<div class="form-group">
|
105 |
+
<label for="prompt-input">🗣️ سبک و لحن گفتار (اختیاری)</label>
|
106 |
+
<input type="text" id="prompt-input" value="با صدایی طبیعی و روان." placeholder="مثال: با لحنی شاد و پرانرژی">
|
107 |
</div>
|
108 |
|
109 |
<div class="form-group">
|
110 |
+
<label>🎤 گوینده منتخب</label>
|
111 |
<div id="selected-speaker-display">
|
112 |
+
<div id="selected-speaker-card">
|
113 |
<img id="selected-speaker-img" src="" alt="عکس گوینده">
|
114 |
<div id="selected-speaker-info">
|
115 |
<h3 id="selected-speaker-name"></h3>
|
116 |
+
<p>برای تغییر، روی دکمه زیر کلیک کنید</p>
|
117 |
</div>
|
118 |
</div>
|
119 |
+
<button type="button" id="change-speaker-btn">تغییر گوینده</button>
|
|
|
|
|
|
|
|
|
|
|
120 |
</div>
|
121 |
</div>
|
122 |
+
|
123 |
<div class="form-group">
|
124 |
+
<label for="temperature-slider">🌡️ میزان خلاقیت صدا (0.1 تا 1.5)</label>
|
|
|
|
|
|
|
|
|
|
|
125 |
<div class="slider-container">
|
126 |
<input type="range" id="temperature-slider" min="0.1" max="1.5" step="0.05" value="0.9">
|
127 |
<span id="temperature-value">0.9</span>
|
128 |
</div>
|
129 |
</div>
|
130 |
|
131 |
+
<button type="submit" id="generate-btn">🚀 تولید و پخش صدا</button>
|
132 |
</form>
|
133 |
|
134 |
<div id="output-section">
|
135 |
+
<div id="status-message">خروجی صدا در اینجا نمایش داده میشود</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
<audio id="audio-player" controls></audio>
|
137 |
</div>
|
138 |
</main>
|
139 |
</div>
|
140 |
|
141 |
+
<div id="speaker-modal">
|
142 |
+
<div class="modal-content">
|
|
|
143 |
<div class="modal-header">
|
144 |
+
<h2>انتخاب گوینده</h2>
|
145 |
+
<button type="button" class="close-modal-btn">×</button>
|
|
|
|
|
|
|
146 |
</div>
|
147 |
+
<div id="speaker-grid"></div>
|
148 |
</div>
|
149 |
</div>
|
150 |
+
|
151 |
+
<input type="hidden" id="selected_speaker_id_storage" value="Charon"> <!-- مقدار پیشفرض از کد پایتون -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
<script>
|
154 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
158 |
const FILE_URL_BASE = `${HF_SPACE_URL}/gradio_api/file=`;
|
159 |
const FN_INDEX = 1;
|
160 |
|
161 |
+
// --- لیست گویندگان با اسامی فارسی و ID انگلیسی مطابق با کد پایتون ---
|
162 |
const speakers = [
|
163 |
+
{ id: "Achird", name: "آرش (مرد)" },
|
164 |
+
{ id: "Zubenelgenubi", name: "زهره (زن)" },
|
165 |
+
{ id: "Vindemiatrix", name: "ویدا (زن)" },
|
166 |
+
{ id: "Sadachbia", name: "سارا (زن)" },
|
167 |
+
{ id: "Sadaltager", name: "سامان (مرد)" },
|
168 |
+
{ id: "Sulafat", name: "سولماز (زن)" },
|
169 |
+
{ id: "Laomedeia", name: "لیلا (زن)" },
|
170 |
+
{ id: "Achernar", name: "آرمان (مرد)" },
|
171 |
+
{ id: "Alnilam", name: "آیدا (زن)" },
|
172 |
+
{ id: "Schedar", name: "شهاب (مرد)" },
|
173 |
+
{ id: "Gacrux", name: "کاوه (مرد)" },
|
174 |
+
{ id: "Pulcherrima", name: "پریا (زن)" },
|
175 |
+
{ id: "Umbriel", name: "امید (مرد)" },
|
176 |
+
{ id: "Algieba", name: "آزاده (زن)" },
|
177 |
+
{ id: "Despina", name: "دینا (زن)" },
|
178 |
+
{ id: "Erinome", name: "ایرج (مرد)" },
|
179 |
+
{ id: "Algenib", name: "آرشام (مرد)" },
|
180 |
+
{ id: "Rasalthgeti", name: "رها (زن)" },
|
181 |
+
{ id: "Orus", name: "اردلان (مرد)" },
|
182 |
+
{ id: "Aoede", name: "آیدین (؟)" }, // نام خنثی
|
183 |
+
{ id: "Callirrhoe", name: "کیمیا (زن)" },
|
184 |
+
{ id: "Autonoe", name: "آتنا (زن)" },
|
185 |
+
{ id: "Enceladus", name: "انوش (مرد)" },
|
186 |
+
{ id: "Iapetus", name: "یاشار (مرد)" },
|
187 |
+
{ id: "Zephyr", name: "نسیم (زن)" }, // در مثال Gradio زنانه بود
|
188 |
+
{ id: "Puck", name: "پویا (مرد)" },
|
189 |
+
{ id: "Charon", name: "کارن (مرد)" }, // پیشفرض در Gradio شما
|
190 |
+
{ id: "Kore", name: "کوروش (مرد)" },
|
191 |
+
{ id: "Fenrir", name: "فرید (مرد)" },
|
192 |
+
{ id: "Leda", name: "لیدا (زن)" }
|
193 |
];
|
194 |
+
|
195 |
const form = document.getElementById('tts-form');
|
196 |
const textInput = document.getElementById('text-input');
|
197 |
const promptInput = document.getElementById('prompt-input');
|
198 |
const tempSlider = document.getElementById('temperature-slider');
|
199 |
const tempValueSpan = document.getElementById('temperature-value');
|
200 |
const generateBtn = document.getElementById('generate-btn');
|
|
|
|
|
201 |
const statusMessage = document.getElementById('status-message');
|
202 |
const audioPlayer = document.getElementById('audio-player');
|
203 |
+
|
|
|
204 |
const selectedSpeakerIdStorage = document.getElementById('selected_speaker_id_storage');
|
205 |
+
const speakerModal = document.getElementById('speaker-modal');
|
206 |
const changeSpeakerBtn = document.getElementById('change-speaker-btn');
|
207 |
+
const closeModalBtn = document.querySelector('.close-modal-btn');
|
208 |
const speakerGridInModal = document.getElementById('speaker-grid');
|
209 |
const selectedSpeakerImgDisplay = document.getElementById('selected-speaker-img');
|
210 |
const selectedSpeakerNameDisplay = document.getElementById('selected-speaker-name');
|
211 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
function getSpeakerById(id) {
|
213 |
+
return speakers.find(s => s.id === id);
|
214 |
}
|
215 |
+
|
216 |
+
function getImageUrl(speaker, index) {
|
217 |
+
const genderHint = speaker.name.toLowerCase();
|
218 |
+
let gender = 'lego'; // پیشفرض برای موارد نامشخص
|
219 |
+
if (genderHint.includes('(مرد)')) gender = 'men';
|
220 |
+
else if (genderHint.includes('(زن)')) gender = 'women';
|
221 |
+
|
222 |
+
const imageIndex = (index * 5 + (speaker.id.length % 10)) % 100; // فرمول کمی پیچیدهتر برای تنوع بیشتر
|
223 |
+
return `https://randomuser.me/api/portraits/${gender}/${imageIndex}.jpg`;
|
224 |
}
|
225 |
|
226 |
function updateSelectedSpeakerDisplay(speakerId) {
|
227 |
const speaker = getSpeakerById(speakerId);
|
228 |
+
if (speaker) {
|
229 |
+
const speakerIndex = speakers.findIndex(s => s.id === speakerId);
|
230 |
+
selectedSpeakerImgDisplay.src = getImageUrl(speaker, speakerIndex);
|
231 |
+
selectedSpeakerNameDisplay.textContent = speaker.name;
|
232 |
+
selectedSpeakerIdStorage.value = speaker.id;
|
233 |
+
}
|
234 |
}
|
235 |
|
236 |
function createSpeakerCardsInModal() {
|
237 |
+
speakerGridInModal.innerHTML = '';
|
238 |
speakers.forEach((speaker, index) => {
|
239 |
+
const card = document.createElement('label');
|
240 |
+
card.className = 'speaker-card';
|
241 |
+
card.setAttribute('for', `modal-speaker-${speaker.id}`);
|
242 |
+
|
243 |
const isChecked = speaker.id === selectedSpeakerIdStorage.value ? 'checked' : '';
|
244 |
+
|
245 |
+
card.innerHTML = `
|
246 |
<input type="radio" name="modal_speaker_selection" value="${speaker.id}" id="modal-speaker-${speaker.id}" ${isChecked}>
|
247 |
<div class="speaker-visual">
|
248 |
+
<img src="${getImageUrl(speaker, index)}" alt="عکس گوینده ${speaker.name}" loading="lazy">
|
249 |
<div class="speaker-name">${speaker.name}</div>
|
250 |
</div>
|
251 |
`;
|
252 |
+
|
253 |
+
card.addEventListener('click', () => {
|
|
|
|
|
|
|
254 |
updateSelectedSpeakerDisplay(speaker.id);
|
255 |
+
setTimeout(() => speakerModal.classList.remove('visible'), 100);
|
256 |
});
|
257 |
+
|
258 |
+
speakerGridInModal.appendChild(card);
|
259 |
});
|
260 |
}
|
261 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
changeSpeakerBtn.addEventListener('click', () => {
|
263 |
+
createSpeakerCardsInModal();
|
264 |
+
speakerModal.classList.add('visible');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
});
|
266 |
+
closeModalBtn.addEventListener('click', () => speakerModal.classList.remove('visible'));
|
267 |
+
speakerModal.addEventListener('click', (e) => {
|
268 |
+
if (e.target === speakerModal) {
|
269 |
+
speakerModal.classList.remove('visible');
|
270 |
}
|
271 |
});
|
272 |
|
|
|
273 |
tempSlider.addEventListener('input', () => { tempValueSpan.textContent = tempSlider.value; });
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
async function generateAudio(event) {
|
276 |
event.preventDefault();
|
277 |
+
generateBtn.disabled = true;
|
278 |
+
generateBtn.textContent = 'در حال پردازش...';
|
279 |
+
statusMessage.textContent = 'در حال ارسال درخواست به سرور...';
|
280 |
+
audioPlayer.style.display = 'none';
|
281 |
+
audioPlayer.src = '';
|
282 |
|
283 |
const text = textInput.value;
|
284 |
+
const prompt = promptInput.value;
|
285 |
+
const temperature = parseFloat(tempSlider.value);
|
286 |
+
const selectedSpeaker = selectedSpeakerIdStorage.value;
|
287 |
+
const sessionHash = Math.random().toString(36).substring(2);
|
288 |
+
|
289 |
if (!text.trim()) {
|
290 |
+
statusMessage.textContent = 'خطا: متن ورودی نمیتواند خالی باشد.';
|
291 |
+
generateBtn.disabled = false;
|
292 |
+
generateBtn.textContent = '🚀 تولید و پخش صدا';
|
|
|
|
|
293 |
return;
|
294 |
}
|
295 |
+
|
|
|
|
|
|
|
|
|
|
|
296 |
const payload = {
|
297 |
fn_index: FN_INDEX,
|
298 |
+
data: [false, null, text, prompt, selectedSpeaker, temperature],
|
299 |
event_data: null,
|
300 |
session_hash: sessionHash
|
301 |
};
|
|
|
309 |
|
310 |
if (!joinQueueResponse.ok) {
|
311 |
const errorBody = await joinQueueResponse.text();
|
312 |
+
throw new Error(`خطا در اتصال به صف (${joinQueueResponse.status}): ${errorBody}`);
|
|
|
313 |
}
|
314 |
+
|
315 |
+
statusMessage.textContent = 'در انتظار نتیجه از سرور...';
|
316 |
+
|
317 |
+
const dataResponse = await fetch(`${GET_DATA_URL_BASE}?session_hash=${sessionHash}`);
|
318 |
+
const reader = dataResponse.body.getReader();
|
319 |
+
const decoder = new TextDecoder();
|
320 |
let finalFilePath = null;
|
321 |
+
let buffer = '';
|
|
|
322 |
|
323 |
+
while (true) {
|
324 |
+
const { value, done } = await reader.read();
|
325 |
+
if (done) break;
|
|
|
|
|
|
|
|
|
326 |
|
327 |
+
buffer += decoder.decode(value, { stream: true });
|
328 |
+
const lines = buffer.split('\n');
|
329 |
+
buffer = lines.pop();
|
330 |
|
331 |
for (const line of lines) {
|
332 |
if (!line.startsWith('data:')) continue;
|
333 |
+
|
334 |
try {
|
335 |
const data = JSON.parse(line.substring(5));
|
336 |
+
if (data.msg === 'process_generating') {
|
337 |
+
statusMessage.textContent = 'سرور در حال تولید فایل صوتی است...';
|
338 |
+
}
|
339 |
+
if (data.msg === 'process_completed') {
|
340 |
if (data.success && data.output.data && data.output.data[0] && (data.output.data[0].name || data.output.data[0].path)) {
|
341 |
finalFilePath = data.output.data[0].name || data.output.data[0].path;
|
342 |
} else {
|
343 |
+
console.error("ساختار پیام موفقیت مورد انتظار نبود:", data);
|
|
|
344 |
}
|
345 |
+
break;
|
|
|
|
|
346 |
}
|
347 |
+
} catch (e) { /* نادیده گرفتن خطاهای پارس */ }
|
|
|
|
|
348 |
}
|
349 |
+
if (finalFilePath) break;
|
|
|
350 |
}
|
351 |
+
|
352 |
if (finalFilePath) {
|
353 |
+
statusMessage.textContent = 'فایل صوتی با موفقیت دریافت شد!';
|
354 |
const audioUrl = `${FILE_URL_BASE}${finalFilePath}`;
|
355 |
audioPlayer.src = audioUrl;
|
356 |
+
audioPlayer.style.display = 'block';
|
357 |
+
audioPlayer.play();
|
|
|
358 |
} else {
|
359 |
+
throw new Error('فایل صوتی از سرور دریافت نشد. کنسول را برای اطلاعات بیشتر بررسی کنید.');
|
360 |
}
|
361 |
|
362 |
} catch (error) {
|
363 |
+
console.error('یک خطا در فرآیند رخ داد:', error);
|
364 |
+
statusMessage.textContent = `یک خطا رخ داد: ${error.message}`;
|
365 |
+
} finally {
|
366 |
+
generateBtn.disabled = false;
|
367 |
+
generateBtn.textContent = '🚀 تولید و پخش صدا';
|
368 |
}
|
369 |
}
|
370 |
+
|
371 |
+
updateSelectedSpeakerDisplay(selectedSpeakerIdStorage.value);
|
372 |
form.addEventListener('submit', generateAudio);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
});
|
374 |
</script>
|
375 |
</body>
|