Update index.html
Browse files- index.html +634 -235
index.html
CHANGED
@@ -3,373 +3,772 @@
|
|
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;700;800&display=swap');
|
9 |
|
10 |
:root {
|
11 |
--app-font: 'Vazirmatn', sans-serif;
|
12 |
-
--app-
|
13 |
-
--
|
14 |
-
--
|
15 |
-
--
|
16 |
-
--
|
17 |
-
--
|
18 |
-
--
|
19 |
-
--
|
20 |
-
--
|
21 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
--radius-card: 24px;
|
23 |
-
--radius-input:
|
24 |
-
--shadow-
|
25 |
-
--shadow-
|
26 |
-
--
|
|
|
|
|
27 |
}
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
body {
|
30 |
font-family: var(--app-font);
|
31 |
direction: rtl;
|
32 |
-
background: var(--app-
|
33 |
-
|
|
|
|
|
34 |
font-size: 16px;
|
35 |
-
line-height: 1.
|
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:
|
44 |
-
.app-header { padding:
|
45 |
-
.app-header h1 { font-size: 2.
|
46 |
-
.app-header p { font-size:
|
47 |
-
.main-content { padding: 2.5rem;
|
48 |
-
.form-group { margin-bottom:
|
49 |
-
label { display:
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
#
|
59 |
-
#
|
60 |
-
|
61 |
-
#speaker-
|
62 |
-
#speaker-
|
63 |
-
|
64 |
-
#speaker-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
.
|
73 |
-
.
|
74 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
.speaker-card input[type="radio"] { display: none; }
|
76 |
-
.speaker-card img { width: 100%; height: 120px; object-fit: cover; display: block; background-color: #
|
77 |
-
.speaker-card
|
78 |
-
.speaker-card
|
79 |
-
|
80 |
-
.
|
81 |
-
input[type="
|
82 |
-
#
|
83 |
-
#
|
84 |
-
#
|
85 |
-
#
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
</style>
|
90 |
</head>
|
91 |
<body>
|
92 |
<div class="container">
|
93 |
<header class="app-header">
|
94 |
-
<h1
|
95 |
-
<p
|
96 |
</header>
|
97 |
|
98 |
<main class="main-content">
|
99 |
<form id="tts-form">
|
|
|
100 |
<div class="form-group">
|
101 |
-
<label for="text-input">📝 متن
|
102 |
-
<textarea id="text-input" rows="
|
|
|
|
|
|
|
103 |
</div>
|
104 |
<div class="form-group">
|
105 |
-
<label for="prompt-input">🗣️ سبک و لحن گفتار (اختیاری)</label>
|
106 |
-
<input type="text" id="prompt-input"
|
107 |
</div>
|
108 |
-
|
109 |
<div class="form-group">
|
110 |
-
<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
|
117 |
</div>
|
118 |
</div>
|
119 |
-
<button type="button" id="change-speaker-btn"
|
|
|
|
|
|
|
|
|
|
|
120 |
</div>
|
121 |
</div>
|
122 |
-
|
123 |
<div class="form-group">
|
124 |
-
<
|
|
|
|
|
|
|
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"
|
136 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
</div>
|
138 |
</main>
|
139 |
</div>
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
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', () => {
|
|
|
155 |
const HF_SPACE_URL = "https://hamed744-ttspro.hf.space";
|
156 |
const JOIN_QUEUE_URL = `${HF_SPACE_URL}/gradio_api/queue/join`;
|
157 |
const GET_DATA_URL_BASE = `${HF_SPACE_URL}/gradio_api/queue/data`;
|
158 |
const FILE_URL_BASE = `${HF_SPACE_URL}/gradio_api/file=`;
|
159 |
const FN_INDEX = 1;
|
160 |
-
|
161 |
-
|
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
|
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
|
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 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
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 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
}
|
235 |
-
|
236 |
function createSpeakerCardsInModal() {
|
237 |
-
speakerGridInModal.innerHTML = '';
|
238 |
speakers.forEach((speaker, index) => {
|
239 |
-
const
|
240 |
-
|
241 |
-
|
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="
|
249 |
<div class="speaker-name">${speaker.name}</div>
|
250 |
</div>
|
251 |
`;
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
254 |
updateSelectedSpeakerDisplay(speaker.id);
|
255 |
-
|
256 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
});
|
260 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
262 |
-
|
263 |
-
|
264 |
-
|
|
|
265 |
});
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
|
|
270 |
}
|
271 |
});
|
272 |
|
273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
async function generateAudio(event) {
|
276 |
event.preventDefault();
|
277 |
-
|
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 |
-
|
291 |
-
generateBtn.disabled = false;
|
292 |
-
generateBtn.textContent = '🚀 تولید و پخش صدا';
|
293 |
return;
|
294 |
}
|
295 |
-
|
|
|
|
|
|
|
|
|
296 |
const payload = {
|
297 |
fn_index: FN_INDEX,
|
298 |
-
data: [false, null, text,
|
299 |
event_data: null,
|
300 |
-
session_hash:
|
301 |
};
|
302 |
|
303 |
try {
|
304 |
const joinQueueResponse = await fetch(JOIN_QUEUE_URL, {
|
305 |
-
method: "POST",
|
306 |
-
headers: { "Content-Type": "application/json" },
|
307 |
-
body: JSON.stringify(payload)
|
308 |
});
|
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 |
-
|
322 |
-
|
323 |
-
while (true) {
|
324 |
-
const { value, done } = await reader.read();
|
325 |
-
if (done) break;
|
326 |
|
327 |
-
|
328 |
-
const
|
329 |
-
|
|
|
|
|
330 |
|
331 |
for (const line of lines) {
|
332 |
if (!line.startsWith('data:')) continue;
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
|
|
338 |
}
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
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 |
-
|
357 |
-
|
|
|
|
|
358 |
} else {
|
359 |
-
throw new Error('فایل صوتی از سرور دریافت نشد.
|
360 |
}
|
361 |
|
362 |
} catch (error) {
|
363 |
-
console.error('
|
364 |
-
|
365 |
-
} finally {
|
366 |
-
generateBtn.disabled = false;
|
367 |
-
generateBtn.textContent = '🚀 تولید و پخش صدا';
|
368 |
}
|
369 |
}
|
370 |
|
371 |
-
|
|
|
372 |
form.addEventListener('submit', generateAudio);
|
|
|
|
|
|
|
|
|
|
|
373 |
});
|
374 |
</script>
|
375 |
</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;600;700;800;900&display=swap');
|
9 |
|
10 |
:root {
|
11 |
--app-font: 'Vazirmatn', sans-serif;
|
12 |
+
--app-bg: #F7F9FC;
|
13 |
+
--panel-bg: #FFFFFF;
|
14 |
+
--panel-border: #E8EEF3;
|
15 |
+
--text-primary: #121826;
|
16 |
+
--text-secondary: #5C677D;
|
17 |
+
--accent-primary: #3B82F6;
|
18 |
+
--accent-primary-hover: #2563EB;
|
19 |
+
--accent-secondary: #10B981;
|
20 |
+
--accent-secondary-hover: #059669;
|
21 |
+
--input-bg: #F8FAFC;
|
22 |
+
--input-border-focus: var(--accent-primary);
|
23 |
+
--waveform-bg: #A9B9D0;
|
24 |
+
--waveform-progress: #3B82F6;
|
25 |
+
--player-control-bg: #f0f3f7;
|
26 |
+
--player-control-icon: #6B7A94;
|
27 |
+
--player-control-icon-hover: var(--accent-primary);
|
28 |
+
|
29 |
--radius-card: 24px;
|
30 |
+
--radius-input: 14px;
|
31 |
+
--shadow-subtle: 0 2px 8px rgba(26, 32, 44, 0.04);
|
32 |
+
--shadow-medium: 0 6px 16px -2px rgba(26, 32, 44, 0.08), 0 3px 8px -3px rgba(26,32,44,0.05);
|
33 |
+
--shadow-strong: 0 10px 25px -5px rgba(26, 32, 44, 0.12), 0 6px 15px -6px rgba(26,32,44,0.08);
|
34 |
+
--transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
35 |
+
--transition-bounce: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
|
36 |
}
|
37 |
|
38 |
+
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
|
39 |
+
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
|
40 |
+
@keyframes modalZoomIn { from { opacity: 0; transform: scale(0.8) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }
|
41 |
+
@keyframes modalZoomOut { from { opacity: 1; transform: scale(1) translateY(0); } to { opacity: 0; transform: scale(0.8) translateY(20px); } }
|
42 |
+
|
43 |
body {
|
44 |
font-family: var(--app-font);
|
45 |
direction: rtl;
|
46 |
+
background-color: var(--app-bg);
|
47 |
+
background-image: radial-gradient(var(--panel-border) 1px, transparent 1px);
|
48 |
+
background-size: 30px 30px;
|
49 |
+
color: var(--text-primary);
|
50 |
font-size: 16px;
|
51 |
+
line-height: 1.8;
|
52 |
margin: 0;
|
53 |
+
padding: 2.5rem 0;
|
54 |
min-height: 100vh;
|
55 |
-webkit-font-smoothing: antialiased;
|
56 |
-moz-osx-font-smoothing: grayscale;
|
57 |
+
display: flex;
|
58 |
+
justify-content: center;
|
59 |
+
align-items: flex-start;
|
60 |
+
overflow-x: hidden;
|
61 |
}
|
62 |
|
63 |
+
.container { max-width: 780px; width: 92%; margin: 0 auto; }
|
64 |
+
.app-header { padding: 0.5rem 0 2.5rem 0; text-align: center; margin-bottom: 1.5rem; animation: fadeInDown 0.8s 0.1s ease-out backwards; }
|
65 |
+
.app-header h1 { font-size: 2.1em; font-weight: 900; margin:0 0 0.6rem 0; background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; letter-spacing: -0.5px; }
|
66 |
+
.app-header p { font-size: 1em; color: var(--text-secondary); margin-top:0; opacity: 0.85; font-weight: 400; line-height: 1.6; }
|
67 |
+
.main-content { padding: 2.5rem; background-color: var(--panel-bg); border-radius: var(--radius-card); box-shadow: var(--shadow-strong); border: 1px solid var(--panel-border); animation: fadeInUp 0.8s 0.3s ease-out backwards; }
|
68 |
+
.form-group { margin-bottom: 2rem; }
|
69 |
+
.label-with-info { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
|
70 |
+
.label-with-info label { margin-bottom: 0; }
|
71 |
+
.info-icon { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background-color: var(--input-bg); border: 1px solid var(--panel-border); color: var(--text-secondary); font-size: 0.9em; font-weight: 700; cursor: pointer; position: relative; transition: var(--transition-smooth); user-select: none; }
|
72 |
+
.info-icon:hover, .info-icon:focus { background-color: var(--accent-primary); color: white; border-color: var(--accent-primary); transform: scale(1.1); outline: none; }
|
73 |
+
label { display: block; font-weight: 700; color: var(--text-primary); font-size: 1.05em; margin-bottom: 0.8rem; }
|
74 |
+
textarea, input[type="text"] { width: 100%; padding: 0.9rem 1.1rem; border-radius: var(--radius-input); border: 1px solid var(--panel-border); background-color: var(--input-bg); color: var(--text-primary); box-shadow: var(--shadow-subtle) inset; font-family: var(--app-font); font-size: 1rem; box-sizing: border-box; transition: var(--transition-smooth); }
|
75 |
+
textarea:focus, input[type="text"]:focus { outline: none; border-color: var(--input-border-focus); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25), var(--shadow-subtle) inset; background-color: #fff; }
|
76 |
+
textarea { min-height: 100px; resize: vertical; }
|
77 |
+
.char-counter-wrapper { font-size: 0.85em; color: var(--text-secondary); text-align: left; margin-top: 0.5rem; padding: 0 0.2rem; }
|
78 |
+
#char-count { font-weight: 600; color: var(--accent-primary); }
|
79 |
+
#selected-speaker-display { text-align: center; margin-top: 1rem; position: relative; }
|
80 |
+
#selected-speaker-card { display: inline-flex; align-items: center; background: linear-gradient(135deg, var(--input-bg) 0%, #fff 100%); border-radius: var(--radius-card); padding: 1rem 1.2rem; box-shadow: var(--shadow-medium); border: 1px solid var(--panel-border); transition: var(--transition-bounce); position: relative; margin-bottom: 1.2rem; cursor: pointer; }
|
81 |
+
#selected-speaker-card:hover { transform: translateY(-6px) scale(1.03); box-shadow: var(--shadow-strong); }
|
82 |
+
#selected-speaker-card img { width: 75px; height: 75px; border-radius: 50%; object-fit: cover; margin-left: 18px; border: 3px solid var(--accent-secondary); box-shadow: 0 0 12px -2px rgba(16, 185, 129, 0.5); background-color: #e0e0e0; transition: var(--transition-smooth); }
|
83 |
+
#selected-speaker-card:hover img { transform: scale(1.08) rotate(3deg); }
|
84 |
+
#selected-speaker-info h3 { margin: 0; font-size: 1.35em; font-weight: 800; color: var(--text-primary); }
|
85 |
+
#selected-speaker-info p { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.88em; font-weight: 500; }
|
86 |
+
#change-speaker-btn { display: inline-flex; align-items: center; justify-content: center; margin: 0 auto; padding: 10px 20px; border-radius: var(--radius-input); background: linear-gradient(45deg, var(--accent-primary-hover), var(--accent-primary)); border: none; color: #fff; cursor: pointer; font-family: var(--app-font); font-weight: 600; font-size: 1em; transition: var(--transition-smooth); box-shadow: 0 4px 10px -2px rgba(59, 130, 246, 0.35), var(--shadow-subtle); }
|
87 |
+
#change-speaker-btn:hover { background: linear-gradient(45deg, var(--accent-primary), var(--accent-primary-hover)); transform: translateY(-3px) scale(1.05); box-shadow: 0 6px 12px -3px rgba(59, 130, 246, 0.45), var(--shadow-medium); }
|
88 |
+
#change-speaker-btn svg { width: 1.1em; height: 1.1em; margin-right: 0.5em; fill: currentColor; }
|
89 |
+
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(18, 24, 38, 0.6); backdrop-filter: blur(8px) saturate(150%); display: none; align-items: center; justify-content: center; z-index: 1000; opacity: 0; transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
|
90 |
+
.modal-overlay.visible { display: flex; opacity: 1; }
|
91 |
+
.modal-dialog { background: var(--panel-bg); padding: 2rem; border-radius: var(--radius-card); width: 90%; box-shadow: var(--shadow-strong); border: 1px solid var(--panel-border); opacity: 0; animation-duration: 0.35s; animation-fill-mode: forwards; }
|
92 |
+
.modal-overlay.visible .modal-dialog { animation-name: modalZoomIn; }
|
93 |
+
.modal-overlay.hiding .modal-dialog { animation-name: modalZoomOut; }
|
94 |
+
.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); }
|
95 |
+
.modal-header h2 { margin: 0; font-size: 1.6em; font-weight: 800; color: var(--accent-primary);}
|
96 |
+
.close-modal-btn { background: none; border: none; font-size: 2.5rem; cursor: pointer; color: var(--text-secondary); transition: var(--transition-smooth); line-height: 1; }
|
97 |
+
.close-modal-btn:hover { color: var(--accent-primary); transform: rotate(90deg) scale(1.1); }
|
98 |
+
#speaker-modal .modal-dialog { max-width: 700px; max-height: 85vh; overflow-y: auto; }
|
99 |
+
#speaker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1.2rem; }
|
100 |
+
@media (min-width: 640px) { #speaker-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); } }
|
101 |
+
.speaker-card { cursor: pointer; transition: var(--transition-smooth); text-align: center; position: relative;}
|
102 |
+
.speaker-card .speaker-visual { border: 3px solid transparent; border-radius: var(--radius-card); overflow: hidden; box-shadow: var(--shadow-subtle); position: relative; background-color: var(--input-bg); transition: var(--transition-bounce); padding: 6px; }
|
103 |
+
.speaker-card:hover .speaker-visual { transform: translateY(-5px) scale(1.06); box-shadow: var(--shadow-medium); }
|
104 |
.speaker-card input[type="radio"] { display: none; }
|
105 |
+
.speaker-card img { width: 100%; height: 120px; object-fit: cover; display: block; background-color: #e0e0e0; transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94); border-radius: calc(var(--radius-card) - 12px); }
|
106 |
+
.speaker-card:hover img { transform: scale(1.12); }
|
107 |
+
.speaker-card .speaker-name { padding: 0.8rem 0.4rem 0.1rem; font-weight: 600; font-size: 0.9em; color: var(--text-secondary); transition: color 0.2s; }
|
108 |
+
.speaker-card input[type="radio"]:checked + .speaker-visual { border-color: var(--accent-secondary); box-shadow: 0 0 25px -5px rgba(16, 185, 129, 0.75); background: linear-gradient(135deg, var(--accent-secondary-hover), var(--accent-primary)); transform: scale(1.05); }
|
109 |
+
.speaker-card input[type="radio"]:checked + .speaker-visual img { border: 2px solid white; transform: scale(1.05); }
|
110 |
+
.speaker-card input[type="radio"]:checked + .speaker-visual .speaker-name { color: #fff; font-weight: 700; }
|
111 |
+
#info-modal .modal-dialog { max-width: 480px; }
|
112 |
+
#info-modal-content p { font-size: 1em; line-height: 1.7; color: var(--text-secondary); margin-bottom: 0.5rem; }
|
113 |
+
#info-modal-content p strong { color: var(--text-primary); font-weight: 600; }
|
114 |
+
#info-modal-content .range-info { font-size: 0.9em; color: var(--accent-primary); font-weight: 500; margin-top: 1rem; display: block; text-align: center; }
|
115 |
+
.slider-container { display: flex; align-items: center; gap: 1.2rem; }
|
116 |
+
input[type="range"] { flex-grow: 1; -webkit-appearance: none; appearance: none; width: 100%; height: 8px; background: #EAF0F6; border-radius: 4px; outline: none; cursor: pointer; transition: background 0.2s; }
|
117 |
+
input[type="range"]::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--accent-secondary) 0%, var(--accent-primary) 100%); height: 8px; border-radius: 4px; }
|
118 |
+
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; background: #fff; border-radius: 50%; cursor: pointer; border: 3px solid var(--accent-primary); box-shadow: 0 2px 6px rgba(0,0,0,0.15); margin-top: -7px; transition: transform 0.2s ease, box-shadow 0.2s ease; }
|
119 |
+
input[type="range"]::-webkit-slider-thumb:hover, input[type="range"]:focus::-webkit-slider-thumb { transform: scale(1.2); box-shadow: 0 3px 8px rgba(59, 130, 246, 0.35); }
|
120 |
+
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; background: #fff; border-radius: 50%; cursor: pointer; border: 3px solid var(--accent-primary); box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
|
121 |
+
input[type="range"]::-moz-range-track { background: linear-gradient(to right, var(--accent-secondary) 0%, var(--accent-primary) 100%); height: 8px; border-radius: 4px; border: none; }
|
122 |
+
#temperature-value { font-weight: 700; background-color: var(--input-bg); padding: 0.5rem 1rem; border-radius: 8px; border: 1px solid var(--panel-border); min-width: 45px; text-align: center; color: var(--accent-primary); font-size: 1em; box-shadow: var(--shadow-subtle); }
|
123 |
+
#generate-btn { width: 100%; padding: 1rem 1.5rem; font-size: 1.25em; font-weight: 800; font-family: var(--app-font); background: linear-gradient(95deg, var(--accent-secondary) 0%, var(--accent-primary) 100%); color: #fff; border: none; border-radius: var(--radius-input); cursor: pointer; transition: var(--transition-smooth), transform 0.15s ease-out; box-shadow: 0 5px 15px -4px rgba(59, 130, 246, 0.45), 0 5px 15px -4px rgba(16, 185, 129, 0.35); position: relative; overflow: hidden; letter-spacing: 0.5px; }
|
124 |
+
#generate-btn::before { content: ''; position: absolute; top: 0; left: -180%; width: 80%; height: 100%; background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 100%); transform: skewX(-30deg); transition: left 0.8s cubic-bezier(0.23, 1, 0.32, 1); }
|
125 |
+
#generate-btn:hover::before { left: 180%; }
|
126 |
+
#generate-btn:hover:not(:disabled) { transform: translateY(-5px) scale(1.02); box-shadow: 0 8px 20px -4px rgba(59, 130, 246, 0.55), 0 8px 20px -4px rgba(16, 185, 129, 0.45); }
|
127 |
+
#generate-btn:active:not(:disabled) { transform: translateY(-2px) scale(0.98); }
|
128 |
+
#generate-btn:disabled { background: #B8C2CC; cursor: not-allowed; box-shadow: none; color: #E8EEF3; transform: none; }
|
129 |
+
#generate-btn:disabled::before { display: none; }
|
130 |
+
#generate-btn svg { display:inline-block; margin-left: 0.5em; width:1.2em; height:1.2em; vertical-align: middle; }
|
131 |
+
#output-section { margin-top: 3rem; background-color: #fff; border-radius: var(--radius-card); min-height: 200px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 1.5rem; border: 1px solid var(--panel-border); transition: var(--transition-smooth), border-color 0.5s, box-shadow 0.5s; position: relative; box-shadow: var(--shadow-medium); padding: 1.5rem; }
|
132 |
+
#output-section.has-content { border-color: var(--accent-secondary); box-shadow: 0 0 30px -8px rgba(16, 185, 129, 0.35); }
|
133 |
+
#output-section.is-empty { background-color: var(--input-bg); box-shadow: var(--shadow-subtle) inset; border: 2px dashed var(--panel-border); }
|
134 |
+
#output-section.is-empty #custom-player-container { display: none !important; }
|
135 |
+
#output-section:not(.is-empty) #status-message,
|
136 |
+
#output-section:not(.is-empty) #loading-animation-wrapper { display: none !important; }
|
137 |
+
#status-message { font-weight: 500; color: var(--text-secondary); text-align: center; font-size: 1.1em; }
|
138 |
+
|
139 |
+
/* --- Custom Audio Player --- */
|
140 |
+
#custom-player-container {
|
141 |
+
width: 100%;
|
142 |
+
padding: 1rem 1.2rem;
|
143 |
+
box-sizing: border-box;
|
144 |
+
display: none; /* Hidden by default */
|
145 |
+
}
|
146 |
+
.player-header {
|
147 |
+
display: flex;
|
148 |
+
align-items: center;
|
149 |
+
gap: 0.8rem;
|
150 |
+
margin-bottom: 1.2rem;
|
151 |
+
border: 1px solid var(--panel-border);
|
152 |
+
padding: 0.5rem 0.8rem;
|
153 |
+
border-radius: 12px;
|
154 |
+
background-color: var(--input-bg);
|
155 |
+
}
|
156 |
+
.player-header .icon {
|
157 |
+
color: var(--text-secondary);
|
158 |
+
width: 22px;
|
159 |
+
height: 22px;
|
160 |
+
}
|
161 |
+
.player-header .title {
|
162 |
+
font-weight: 600;
|
163 |
+
color: var(--text-primary);
|
164 |
+
font-size: 1em;
|
165 |
+
}
|
166 |
+
.waveform-container {
|
167 |
+
position: relative;
|
168 |
+
width: 100%;
|
169 |
+
height: 70px;
|
170 |
+
cursor: pointer;
|
171 |
+
display: flex;
|
172 |
+
align-items: center;
|
173 |
+
gap: 2px;
|
174 |
+
}
|
175 |
+
#waveform-canvas {
|
176 |
+
position: absolute;
|
177 |
+
top: 0;
|
178 |
+
left: 0;
|
179 |
+
width: 100%;
|
180 |
+
height: 100%;
|
181 |
+
}
|
182 |
+
.player-timestamps {
|
183 |
+
display: flex;
|
184 |
+
justify-content: space-between;
|
185 |
+
font-size: 0.85em;
|
186 |
+
color: var(--text-secondary);
|
187 |
+
font-weight: 500;
|
188 |
+
margin-top: 0.5rem;
|
189 |
+
padding: 0 0.2rem;
|
190 |
+
}
|
191 |
+
.player-controls {
|
192 |
+
display: flex;
|
193 |
+
justify-content: center;
|
194 |
+
align-items: center;
|
195 |
+
gap: 0.8rem;
|
196 |
+
margin-top: 1.5rem;
|
197 |
+
}
|
198 |
+
.player-controls .ctrl-button {
|
199 |
+
background: var(--player-control-bg);
|
200 |
+
border: 1px solid var(--panel-border);
|
201 |
+
border-radius: 50%;
|
202 |
+
width: 50px;
|
203 |
+
height: 50px;
|
204 |
+
display: flex;
|
205 |
+
align-items: center;
|
206 |
+
justify-content: center;
|
207 |
+
cursor: pointer;
|
208 |
+
transition: all 0.2s ease;
|
209 |
+
color: var(--player-control-icon);
|
210 |
+
}
|
211 |
+
.player-controls .ctrl-button:hover {
|
212 |
+
background-color: var(--accent-primary);
|
213 |
+
color: #fff;
|
214 |
+
border-color: var(--accent-primary);
|
215 |
+
transform: scale(1.1);
|
216 |
+
}
|
217 |
+
.player-controls .ctrl-button.play-pause {
|
218 |
+
width: 60px;
|
219 |
+
height: 60px;
|
220 |
+
background-color: var(--accent-primary);
|
221 |
+
color: #fff;
|
222 |
+
border-color: var(--accent-primary-hover);
|
223 |
+
}
|
224 |
+
.player-controls .ctrl-button.play-pause:hover {
|
225 |
+
background-color: var(--accent-primary-hover);
|
226 |
+
}
|
227 |
+
.player-controls .ctrl-button svg {
|
228 |
+
width: 24px;
|
229 |
+
height: 24px;
|
230 |
+
}
|
231 |
+
.player-controls .play-pause svg {
|
232 |
+
width: 30px;
|
233 |
+
height: 30px;
|
234 |
+
}
|
235 |
+
#play-icon { display: block; }
|
236 |
+
#pause-icon { display: none; }
|
237 |
+
.player-settings {
|
238 |
+
display: flex;
|
239 |
+
align-items: center;
|
240 |
+
gap: 1rem;
|
241 |
+
position: absolute;
|
242 |
+
left: 2rem;
|
243 |
+
}
|
244 |
+
.setting-button {
|
245 |
+
background-color: var(--player-control-bg);
|
246 |
+
border: 1px solid var(--panel-border);
|
247 |
+
color: var(--player-control-icon);
|
248 |
+
padding: 0.4rem 0.8rem;
|
249 |
+
border-radius: 20px;
|
250 |
+
font-size: 0.85em;
|
251 |
+
font-weight: 600;
|
252 |
+
cursor: pointer;
|
253 |
+
transition: all 0.2s ease;
|
254 |
+
display: flex;
|
255 |
+
align-items: center;
|
256 |
+
gap: 0.3rem;
|
257 |
+
}
|
258 |
+
.setting-button:hover {
|
259 |
+
background-color: var(--player-control-icon);
|
260 |
+
color: #fff;
|
261 |
+
}
|
262 |
+
.setting-button svg {
|
263 |
+
width: 18px;
|
264 |
+
height: 18px;
|
265 |
+
}
|
266 |
+
|
267 |
+
/* --- انیمیشن پردازش --- */
|
268 |
+
#loading-animation-wrapper { display: none; flex-direction: column; align-items: center; justify-content: center; gap: 1.8rem; width: 100%; min-height: 150px; }
|
269 |
+
.orbital-loader { width: 110px; height: 110px; position: relative; animation: rotate-loader-orbital 10s linear infinite; }
|
270 |
+
.orbit { position: absolute; top: 50%; left: 50%; border: 2px dashed rgba(59, 130, 246, 0.25); border-radius: 50%; transform-origin: center center; }
|
271 |
+
.orbit:nth-child(1) { width: 35px; height: 35px; margin: -17.5px 0 0 -17.5px; animation: orbit-spin 2.8s linear infinite reverse; }
|
272 |
+
.orbit:nth-child(2) { width: 65px; height: 65px; margin: -32.5px 0 0 -32.5px; animation: orbit-spin 3.8s linear infinite; }
|
273 |
+
.orbit:nth-child(3) { width: 95px; height: 95px; margin: -47.5px 0 0 -47.5px; animation: orbit-spin 4.8s linear infinite reverse; }
|
274 |
+
.orbit .satellite { position: absolute; width: 10px; height: 10px; border-radius: 50%; background-color: var(--accent-primary); box-shadow: 0 0 8px var(--accent-primary), 0 0 12px var(--accent-secondary); }
|
275 |
+
.orbit:nth-child(1) .satellite { top: -5px; left: 50%; animation: satellite-pulse-1 1.4s ease-in-out infinite alternate; }
|
276 |
+
.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; }
|
277 |
+
.orbit:nth-child(3) .satellite { bottom: -5px; right: 50%; animation: satellite-pulse-3 1.4s 0.4s ease-in-out infinite alternate;}
|
278 |
+
@keyframes rotate-loader-orbital { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
279 |
+
@keyframes orbit-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
280 |
+
@keyframes satellite-pulse-1 { from { transform: scale(0.7) translateX(-50%); opacity: 0.6; } to { transform: scale(1.1) translateX(-50%); opacity: 1; } }
|
281 |
+
@keyframes satellite-pulse-2 { from { transform: scale(0.7) translateY(-50%); opacity: 0.6; } to { transform: scale(1.1) translateY(-50%); opacity: 1; } }
|
282 |
+
@keyframes satellite-pulse-3 { from { transform: scale(0.7) translateX(50%); opacity: 0.6; } to { transform: scale(1.1) translateX(50%); opacity: 1; } }
|
283 |
+
#loading-text { font-size: 1.2em; font-weight: 700; color: var(--text-primary); text-align: center; background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
284 |
+
|
285 |
</style>
|
286 |
</head>
|
287 |
<body>
|
288 |
<div class="container">
|
289 |
<header class="app-header">
|
290 |
+
<h1>تبدیل متن به صدا با هوش مصنوعی آلفا</h1>
|
291 |
+
<p>صدایی نو، تجربهای نوین در تبدیل متن به گفتار با هوش مصنوعی پیشرفته</p>
|
292 |
</header>
|
293 |
|
294 |
<main class="main-content">
|
295 |
<form id="tts-form">
|
296 |
+
<!-- Form fields from original code -->
|
297 |
<div class="form-group">
|
298 |
+
<label for="text-input">📝 متن مورد نظر شما</label>
|
299 |
+
<textarea id="text-input" rows="4" placeholder="متن خود را اینجا وارد کنید..."></textarea>
|
300 |
+
<div class="char-counter-wrapper">
|
301 |
+
<span id="char-count">0</span> / <span id="char-max">50000</span> نویسه
|
302 |
+
</div>
|
303 |
</div>
|
304 |
<div class="form-group">
|
305 |
+
<label for="prompt-input">🗣️ توصیف سبک و لحن گفتار (اختیاری)</label>
|
306 |
+
<input type="text" id="prompt-input" placeholder="مثال: با لحنی رسمی و موقر، یا شاد و کودکانه">
|
307 |
</div>
|
|
|
308 |
<div class="form-group">
|
309 |
+
<label>🎤 انتخاب گوینده حرفهای</label>
|
310 |
<div id="selected-speaker-display">
|
311 |
+
<div id="selected-speaker-card" title="برای تغییر گوینده کلیک کنید">
|
312 |
<img id="selected-speaker-img" src="" alt="عکس گوینده">
|
313 |
<div id="selected-speaker-info">
|
314 |
<h3 id="selected-speaker-name"></h3>
|
315 |
+
<p id="selected-speaker-desc">گوینده پیشفرض</p>
|
316 |
</div>
|
317 |
</div>
|
318 |
+
<button type="button" id="change-speaker-btn">
|
319 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
320 |
+
<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" />
|
321 |
+
</svg>
|
322 |
+
تغییر گوینده
|
323 |
+
</button>
|
324 |
</div>
|
325 |
</div>
|
|
|
326 |
<div class="form-group">
|
327 |
+
<div class="label-with-info">
|
328 |
+
<label for="temperature-slider">🌡️ میزان خلاقیت و نوآوری صدا</label>
|
329 |
+
<div class="info-icon" id="temp-info-icon" role="button" tabindex="0" aria-label="اطلاعات بیشتر">!</div>
|
330 |
+
</div>
|
331 |
<div class="slider-container">
|
332 |
<input type="range" id="temperature-slider" min="0.1" max="1.5" step="0.05" value="0.9">
|
333 |
<span id="temperature-value">0.9</span>
|
334 |
</div>
|
335 |
</div>
|
336 |
+
<button type="submit" id="generate-btn">✨ تولید صدا با آلفا</button>
|
|
|
337 |
</form>
|
338 |
|
339 |
+
<div id="output-section" class="is-empty">
|
340 |
+
<div id="status-message">صدای تولید شده در اینجا نمایش داده خواهد شد.</div>
|
341 |
+
<div id="loading-animation-wrapper">
|
342 |
+
<div class="orbital-loader">
|
343 |
+
<div class="orbit"><div class="satellite"></div></div>
|
344 |
+
<div class="orbit"><div class="satellite"></div></div>
|
345 |
+
<div class="orbit"><div class="satellite"></div></div>
|
346 |
+
</div>
|
347 |
+
<p id="loading-text">در حال پردازش هوشمند و تولید صدا...</p>
|
348 |
+
</div>
|
349 |
+
|
350 |
+
<!-- NEW CUSTOM AUDIO PLAYER -->
|
351 |
+
<div id="custom-player-container">
|
352 |
+
<div class="player-header">
|
353 |
+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 17.25V6.75A2.25 2.25 0 0 1 5.25 4.5h13.5A2.25 2.25 0 0 1 21 6.75v10.5A2.25 2.25 0 0 1 18.75 19.5H5.25A2.25 2.25 0 0 1 3 17.25ZM5.25 6A.75.75 0 0 0 4.5 6.75v10.5c0 .414.336.75.75.75h13.5a.75.75 0 0 0 .75-.75V6.75a.75.75 0 0 0-.75-.75H5.25Z" /><path d="M9 15.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm-2.5-4a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm10.5 4a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm-2.5-4a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z" /></svg>
|
354 |
+
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 18.75a6 6 0 0 0 6-6v-1.5a6 6 0 0 0-12 0v1.5a6 6 0 0 0 6 6Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M12 12.75v6.75a6.75 6.75 0 0 0 6.75-6.75V12a6.75 6.75 0 0 0-13.5 0v.75a6.75 6.75 0 0 0 6.75 6.75Z" /></svg>
|
355 |
+
<span class="title">فایل صوتی</span>
|
356 |
+
</div>
|
357 |
+
<div class="waveform-container" id="waveform-container">
|
358 |
+
<canvas id="waveform-canvas"></canvas>
|
359 |
+
</div>
|
360 |
+
<div class="player-timestamps">
|
361 |
+
<span id="current-time">0:00</span>
|
362 |
+
<span id="total-duration">0:00</span>
|
363 |
+
</div>
|
364 |
+
<div class="player-controls">
|
365 |
+
<div class="player-settings">
|
366 |
+
<button class="setting-button" id="volume-btn" aria-label="قطع و وصل صدا">
|
367 |
+
<svg id="volume-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M13.5 4.06c0-1.336-1.616-2.005-2.56-1.06l-4.5 4.5H4.508c-1.141 0-2.318.664-2.66 1.905A9.76 9.76 0 0 0 1.5 12c0 .898.121 1.768.35 2.595.341 1.24 1.518 1.905 2.66 1.905H6.44l4.5 4.5c.944.945 2.56.276 2.56-1.06V4.06Z" /></svg>
|
368 |
+
<svg id="mute-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" style="display: none;"><path d="M13.5 4.06c0-1.336-1.616-2.005-2.56-1.06l-4.5 4.5H4.508c-1.141 0-2.318.664-2.66 1.905A9.76 9.76 0 0 0 1.5 12c0 .898.121 1.768.35 2.595.341 1.24 1.518 1.905 2.66 1.905H6.44l4.5 4.5c.944.945 2.56.276 2.56-1.06V4.06ZM17.28 12a.75.75 0 0 1 0 1.06l-2.12 2.12a.75.75 0 1 1-1.06-1.06l2.12-2.12 2.12 2.12a.75.75 0 1 1-1.06 1.06L17.28 12l-2.12 2.12a.75.75 0 0 1-1.06-1.06l2.12-2.12-2.12-2.12a.75.75 0 1 1 1.06-1.06l2.12 2.12Z" /></svg>
|
369 |
+
</button>
|
370 |
+
<button class="setting-button" id="speed-btn" aria-label="تغییر سرعت پخش">1x</button>
|
371 |
+
</div>
|
372 |
+
|
373 |
+
<button class="ctrl-button" id="rewind-btn" aria-label="۵ ثانیه عقب">
|
374 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M9.53 2.47a.75.75 0 0 1 0 1.06L4.81 8.25H15a6.75 6.75 0 0 1 0 13.5h-3a.75.75 0 0 1 0-1.5h3a5.25 5.25 0 1 0 0-10.5H4.81l4.72 4.72a.75.75 0 1 1-1.06 1.06l-6-6a.75.75 0 0 1 0-1.06l6-6a.75.75 0 0 1 1.06 0Z" clip-rule="evenodd" /></svg>
|
375 |
+
</button>
|
376 |
+
<button class="ctrl-button play-pause" id="play-pause-btn" aria-label="پخش">
|
377 |
+
<svg id="play-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.647c1.295.748 1.295 2.536 0 3.284L7.279 20.99c-1.25.72-2.779-.217-2.779-1.643V5.653Z" clip-rule="evenodd" /></svg>
|
378 |
+
<svg id="pause-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M6.75 5.25a.75.75 0 0 1 .75.75v12a.75.75 0 0 1-1.5 0V6a.75.75 0 0 1 .75-.75Zm9 0a.75.75 0 0 1 .75.75v12a.75.75 0 0 1-1.5 0V6a.75.75 0 0 1 .75-.75Z" clip-rule="evenodd" /></svg>
|
379 |
+
</button>
|
380 |
+
<button class="ctrl-button" id="forward-btn" aria-label="۵ ثانیه جلو">
|
381 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path fill-rule="evenodd" d="M14.47 2.47a.75.75 0 0 1 1.06 0l6 6a.75.75 0 0 1 0 1.06l-6 6a.75.75 0 1 1-1.06-1.06L19.19 8.25H9a6.75 6.75 0 0 0 0 13.5h3a.75.75 0 0 1 0 1.5H9a5.25 5.25 0 0 1 0-10.5h10.19l-4.72 4.72a.75.75 0 1 1-1.06-1.06l6-6Z" clip-rule="evenodd" /></svg>
|
382 |
+
</button>
|
383 |
+
</div>
|
384 |
+
</div>
|
385 |
+
<audio id="audio-player" style="display: none;"></audio>
|
386 |
</div>
|
387 |
</main>
|
388 |
</div>
|
389 |
|
390 |
+
<!-- Modals from original code -->
|
391 |
+
<div id="speaker-modal" class="modal-overlay"> <div class="modal-dialog"> <div class="modal-header"> <h2>گالری گویندگان آلفا نوا</h2> <button type="button" class="close-modal-btn" data-modal-id="speaker-modal" aria-label="بستن مودال">×</button> </div> <div id="speaker-grid"></div> </div> </div>
|
392 |
+
<div id="info-modal" class="modal-overlay"> <div class="modal-dialog"> <div class="modal-header"> <h2>🌡️ خلاقیت و نوآوری صدا</h2> <button type="button" class="close-modal-btn" data-modal-id="info-modal" aria-label="بستن توضیحات">×</button> </div> <div id="info-modal-content"> <p>این تنظیم مشخص میکند که هوش مصنوعی تا چه حد در تولید صدا <strong>خلاقیت</strong> ��ه خرج دهد.</p> <p><strong>مقادیر بالاتر:</strong> منجر به صدایی متنوعتر، پویاتر و گاهی اوقات غیرمنتظرهتر میشود. مناسب برای زمانی که به دنبال لحنی خاص و منحصربهفرد هستید.</p> <p><strong>مقادیر پایینتر:</strong> صدایی پایدارتر، قابل پیشبینیتر و نزدیکتر به صدای استاندارد گوینده تولید میکند. مناسب برای خوانش متون رسمی یا زمانی که ثبات لحن اهمیت دارد.</p> <span class="range-info">محدوده پیشنهادی: ۰.۱ (پایدار) تا ۱.۵ (بسیار خلاق)</span> </div> </div> </div>
|
393 |
+
<input type="hidden" id="selected_speaker_id_storage" value="Charon">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
|
395 |
<script>
|
396 |
document.addEventListener('DOMContentLoaded', () => {
|
397 |
+
// --- CONSTANTS AND CONFIG ---
|
398 |
const HF_SPACE_URL = "https://hamed744-ttspro.hf.space";
|
399 |
const JOIN_QUEUE_URL = `${HF_SPACE_URL}/gradio_api/queue/join`;
|
400 |
const GET_DATA_URL_BASE = `${HF_SPACE_URL}/gradio_api/queue/data`;
|
401 |
const FILE_URL_BASE = `${HF_SPACE_URL}/gradio_api/file=`;
|
402 |
const FN_INDEX = 1;
|
403 |
+
const MAX_CHARS = 50000;
|
404 |
+
const speakers = [ { id: "Charon", name: "شهاب (مرد)", desc: "صدایی قدرتمند و رسا" }, { id: "Zephyr", name: "آوا (زن)", desc: "لطیف و دلنشین" }, { id: "Achird", name: "نوید (مرد)", desc: "جوان و پرانرژی" }, { id: "Zubenelgenubi", name: "رویا (زن)", desc: "گرم و صمیمی" }, { id: "Vindemiatrix", name: "کیان (مرد)", desc: "باوقار و رسمی" }, { id: "Sadachbia", name: "پریسا (زن)", desc: "شاداب و پویا" }, { id: "Sadaltager", name: "آرش (مرد)", desc: "مطمئن و تاثیرگذار" }, { id: "Sulafat", name: "شبنم (زن)", desc: "آرام و متین" }, { id: "Laomedeia", name: "سهیل (مرد)", desc: "دوستانه و گیرا" }, { id: "Achernar", name: "مریم (زن)", desc: "حرفهای و واضح" }, { id: "Alnilam", name: "بهرام (مرد)", desc: "حماسی و نافذ" }, { id: "Schedar", name: "نگار (زن)", desc: "مهربان و شیرین" }, { id: "Gacrux", name: "فرید (مرد)", desc: "پخته و قابل اعتماد" }, { id: "Pulcherrima", name: "سارا (زن)", desc: "جذاب و مدرن" }, { id: "Umbriel", name: "مانی (مرد)", desc: "خلاق و متفاوت" }, { id: "Algieba", name: "آناهیتا (زن)", desc: "با اصالت و شیک" }, { id: "Despina", name: "دلنواز (زن)", desc: "هنری و احساسی" }, { id: "Erinome", name: "رسا (مرد)", desc: "شفاف و گویا" }, { id: "Algenib", name: "امید (مرد)", desc: "انگیزه بخش و مثبت" }, { id: "Rasalthgeti", name: "ا��هه (زن)", desc: "اسرارآمیز و فریبنده" }, { id: "Orus", name: "بردیا (مرد)", desc: "ورزشی و پرهیجان" }, { id: "Aoede", name: "ترانه (زن)", desc: "موزیکال و خوشآهنگ" }, { id: "Callirrhoe", name: "نیما (مرد)", desc: "روایتگر و قصهگو" }, { id: "Autonoe", name: "هستی (زن)", desc: "طبیعی و خودمانی" }, { id: "Enceladus", name: "کامیار (مرد)", desc: "مصمم و جدی" }, { id: "Iapetus", name: "ستاره (زن)", desc: "درخشان و گیرا" }, { id: "Puck", name: "پویا (مرد)", desc: "بازیگوش و سرزنده" }, { id: "Kore", name: "مهتاب (زن)", desc: "نجواگر و آرامشبخش" }, { id: "Fenrir", name: "سام (مرد)", desc: "جسور و بیباک" }, { id: "Leda", name: "لیدا (زن)", desc: "کلاسیک و باوقار" } ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
+
// --- DOM ELEMENTS ---
|
407 |
const form = document.getElementById('tts-form');
|
408 |
const textInput = document.getElementById('text-input');
|
409 |
const promptInput = document.getElementById('prompt-input');
|
410 |
const tempSlider = document.getElementById('temperature-slider');
|
411 |
const tempValueSpan = document.getElementById('temperature-value');
|
412 |
const generateBtn = document.getElementById('generate-btn');
|
413 |
+
const outputSection = document.getElementById('output-section');
|
414 |
const statusMessage = document.getElementById('status-message');
|
415 |
+
const loadingAnimationWrapper = document.getElementById('loading-animation-wrapper');
|
|
|
416 |
const selectedSpeakerIdStorage = document.getElementById('selected_speaker_id_storage');
|
|
|
417 |
const changeSpeakerBtn = document.getElementById('change-speaker-btn');
|
418 |
+
const selectedSpeakerCard = document.getElementById('selected-speaker-card');
|
419 |
const speakerGridInModal = document.getElementById('speaker-grid');
|
420 |
const selectedSpeakerImgDisplay = document.getElementById('selected-speaker-img');
|
421 |
const selectedSpeakerNameDisplay = document.getElementById('selected-speaker-name');
|
422 |
+
const selectedSpeakerDescDisplay = document.getElementById('selected-speaker-desc');
|
423 |
+
const charCountSpan = document.getElementById('char-count');
|
424 |
+
const charMaxSpan = document.getElementById('char-max');
|
425 |
+
|
426 |
+
// Modal Elements
|
427 |
+
const speakerModal = document.getElementById('speaker-modal');
|
428 |
+
const infoModal = document.getElementById('info-modal');
|
429 |
+
const tempInfoIcon = document.getElementById('temp-info-icon');
|
430 |
+
|
431 |
+
// --- NEW CUSTOM PLAYER ELEMENTS ---
|
432 |
+
const customPlayerContainer = document.getElementById('custom-player-container');
|
433 |
+
const audioPlayer = document.getElementById('audio-player');
|
434 |
+
const waveformCanvas = document.getElementById('waveform-canvas');
|
435 |
+
const waveformContainer = document.getElementById('waveform-container');
|
436 |
+
const playPauseBtn = document.getElementById('play-pause-btn');
|
437 |
+
const playIcon = document.getElementById('play-icon');
|
438 |
+
const pauseIcon = document.getElementById('pause-icon');
|
439 |
+
const currentTimeEl = document.getElementById('current-time');
|
440 |
+
const totalDurationEl = document.getElementById('total-duration');
|
441 |
+
const rewindBtn = document.getElementById('rewind-btn');
|
442 |
+
const forwardBtn = document.getElementById('forward-btn');
|
443 |
+
const volumeBtn = document.getElementById('volume-btn');
|
444 |
+
const volumeIcon = document.getElementById('volume-icon');
|
445 |
+
const muteIcon = document.getElementById('mute-icon');
|
446 |
+
const speedBtn = document.getElementById('speed-btn');
|
447 |
+
|
448 |
+
// --- PLAYER STATE ---
|
449 |
+
let audioContext;
|
450 |
+
let waveformData = [];
|
451 |
+
const playbackSpeeds = [1, 1.5, 2];
|
452 |
+
let currentSpeedIndex = 0;
|
453 |
+
|
454 |
+
// --- INITIALIZATION & EVENT LISTENERS ---
|
455 |
|
456 |
+
// Character Counter
|
457 |
+
charMaxSpan.textContent = MAX_CHARS.toLocaleString('fa-IR');
|
458 |
+
textInput.addEventListener('input', () => {
|
459 |
+
const currentLength = textInput.value.length;
|
460 |
+
charCountSpan.textContent = currentLength.toLocaleString('fa-IR');
|
461 |
+
charCountSpan.style.color = currentLength > MAX_CHARS ? 'var(--accent-secondary-hover)' : 'var(--accent-primary)';
|
462 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
463 |
|
464 |
+
// --- SPEAKER SELECTION LOGIC ---
|
465 |
+
function getSpeakerById(id) { return speakers.find(s => s.id === id) || speakers[0]; }
|
466 |
+
function getImageUrl(speaker, index, size = 'thumb') {
|
467 |
+
const gender = speaker.name.includes('(مرد)') ? 'men' : 'women';
|
468 |
+
const imageIndex = (index * 7 + speaker.id.length * 3 + 5) % 100;
|
469 |
+
let portraitSizePath = 'thumb/';
|
470 |
+
if (size === 'large') portraitSizePath = '';
|
471 |
+
return `https://randomuser.me/api/portraits/${portraitSizePath}${gender}/${imageIndex}.jpg`;
|
472 |
+
}
|
473 |
function updateSelectedSpeakerDisplay(speakerId) {
|
474 |
const speaker = getSpeakerById(speakerId);
|
475 |
+
const speakerIndex = speakers.findIndex(s => s.id === speaker.id);
|
476 |
+
selectedSpeakerImgDisplay.src = getImageUrl(speaker, speakerIndex, 'large');
|
477 |
+
selectedSpeakerImgDisplay.alt = `عکس گوینده ${speaker.name}`;
|
478 |
+
selectedSpeakerNameDisplay.textContent = speaker.name;
|
479 |
+
selectedSpeakerDescDisplay.textContent = speaker.desc || "گوینده منتخب شما";
|
480 |
+
selectedSpeakerIdStorage.value = speaker.id;
|
481 |
}
|
|
|
482 |
function createSpeakerCardsInModal() {
|
483 |
+
speakerGridInModal.innerHTML = '';
|
484 |
speakers.forEach((speaker, index) => {
|
485 |
+
const cardLabel = document.createElement('label');
|
486 |
+
cardLabel.className = 'speaker-card';
|
487 |
+
cardLabel.setAttribute('for', `modal-speaker-${speaker.id}`);
|
|
|
488 |
const isChecked = speaker.id === selectedSpeakerIdStorage.value ? 'checked' : '';
|
489 |
+
cardLabel.innerHTML = `
|
|
|
490 |
<input type="radio" name="modal_speaker_selection" value="${speaker.id}" id="modal-speaker-${speaker.id}" ${isChecked}>
|
491 |
<div class="speaker-visual">
|
492 |
+
<img src="${getImageUrl(speaker, index, 'thumb')}" alt="${speaker.name}" loading="lazy">
|
493 |
<div class="speaker-name">${speaker.name}</div>
|
494 |
</div>
|
495 |
`;
|
496 |
+
cardLabel.addEventListener('click', (e) => {
|
497 |
+
if (e.target.name !== "modal_speaker_selection") {
|
498 |
+
const radio = cardLabel.querySelector('input[type="radio"]');
|
499 |
+
if(radio) radio.checked = true;
|
500 |
+
}
|
501 |
updateSelectedSpeakerDisplay(speaker.id);
|
502 |
+
hideModal(speakerModal);
|
503 |
});
|
504 |
+
speakerGridInModal.appendChild(cardLabel);
|
505 |
+
});
|
506 |
+
}
|
507 |
+
|
508 |
+
// --- MODAL MANAGEMENT ---
|
509 |
+
function showModal(modalElement) {
|
510 |
+
modalElement.classList.add('visible');
|
511 |
+
setTimeout(() => {
|
512 |
+
const firstFocusable = modalElement.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
513 |
+
if (firstFocusable) firstFocusable.focus();
|
514 |
+
}, 50);
|
515 |
+
}
|
516 |
+
function hideModal(modalElement) {
|
517 |
+
modalElement.classList.add('hiding');
|
518 |
+
modalElement.addEventListener('animationend', () => {
|
519 |
+
modalElement.classList.remove('visible', 'hiding');
|
520 |
+
}, { once: true });
|
521 |
+
}
|
522 |
+
changeSpeakerBtn.addEventListener('click', () => { createSpeakerCardsInModal(); showModal(speakerModal); });
|
523 |
+
selectedSpeakerCard.addEventListener('click', () => { createSpeakerCardsInModal(); showModal(speakerModal); });
|
524 |
+
tempInfoIcon.addEventListener('click', () => showModal(info-modal));
|
525 |
+
tempInfoIcon.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); showModal(infoModal); } });
|
526 |
+
document.querySelectorAll('.modal-overlay').forEach(overlay => { overlay.addEventListener('click', (e) => { if (e.target === overlay) { hideModal(overlay); } }); });
|
527 |
+
document.querySelectorAll('.close-modal-btn').forEach(button => { button.addEventListener('click', () => { const modalId = button.dataset.modalId; if (modalId) { hideModal(document.getElementById(modalId)); } }); });
|
528 |
+
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') { document.querySelectorAll('.modal-overlay.visible').forEach(hideModal); } });
|
529 |
+
|
530 |
+
tempSlider.addEventListener('input', () => { tempValueSpan.textContent = tempSlider.value; });
|
531 |
+
|
532 |
+
// --- UI STATE MANAGEMENT ---
|
533 |
+
function showLoadingState() {
|
534 |
+
outputSection.classList.remove('has-content', 'is-empty');
|
535 |
+
statusMessage.style.display = 'none';
|
536 |
+
customPlayerContainer.style.display = 'none';
|
537 |
+
loadingAnimationWrapper.style.display = 'flex';
|
538 |
+
generateBtn.disabled = true;
|
539 |
+
generateBtn.innerHTML = `
|
540 |
+
<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;">
|
541 |
+
<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"/>
|
542 |
+
<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"/>
|
543 |
+
</svg>
|
544 |
+
در حال پردازش...
|
545 |
+
`;
|
546 |
+
}
|
547 |
+
|
548 |
+
function showResultState(isSuccess, message = '') {
|
549 |
+
loadingAnimationWrapper.style.display = 'none';
|
550 |
+
if (isSuccess) {
|
551 |
+
customPlayerContainer.style.display = 'block';
|
552 |
+
outputSection.classList.add('has-content');
|
553 |
+
outputSection.classList.remove('is-empty');
|
554 |
+
} else {
|
555 |
+
statusMessage.textContent = message || 'خطایی رخ داد. لطفاً دوباره تلاش کنید.';
|
556 |
+
statusMessage.style.display = 'block';
|
557 |
+
outputSection.classList.remove('has-content');
|
558 |
+
outputSection.classList.add('is-empty');
|
559 |
+
}
|
560 |
+
generateBtn.disabled = false;
|
561 |
+
generateBtn.innerHTML = '✨ تولید صدا با آلفا';
|
562 |
+
}
|
563 |
+
|
564 |
+
// --- AUDIO PROCESSING & WAVEFORM DRAWING ---
|
565 |
+
function formatTime(seconds) {
|
566 |
+
const minutes = Math.floor(seconds / 60);
|
567 |
+
const secs = Math.floor(seconds % 60);
|
568 |
+
return `${minutes}:${secs < 10 ? '0' : ''}${secs}`;
|
569 |
+
}
|
570 |
+
|
571 |
+
async function processAudioForWaveform(url) {
|
572 |
+
if (!window.AudioContext) {
|
573 |
+
console.warn("Web Audio API not supported. Cannot draw waveform.");
|
574 |
+
return;
|
575 |
+
}
|
576 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
577 |
+
try {
|
578 |
+
const response = await fetch(url);
|
579 |
+
const arrayBuffer = await response.arrayBuffer();
|
580 |
+
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
581 |
+
|
582 |
+
const rawData = audioBuffer.getChannelData(0);
|
583 |
+
const samples = 120; // Number of bars in waveform
|
584 |
+
const blockSize = Math.floor(rawData.length / samples);
|
585 |
+
const filteredData = [];
|
586 |
+
for (let i = 0; i < samples; i++) {
|
587 |
+
let blockStart = blockSize * i;
|
588 |
+
let sum = 0;
|
589 |
+
for (let j = 0; j < blockSize; j++) {
|
590 |
+
sum += Math.abs(rawData[blockStart + j]);
|
591 |
+
}
|
592 |
+
filteredData.push(sum / blockSize);
|
593 |
+
}
|
594 |
|
595 |
+
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
596 |
+
waveformData = filteredData.map(n => n * multiplier);
|
597 |
+
|
598 |
+
drawWaveform();
|
599 |
+
} catch (error) {
|
600 |
+
console.error("Error processing audio for waveform:", error);
|
601 |
+
waveformData = []; // Clear data on error
|
602 |
+
}
|
603 |
+
}
|
604 |
+
|
605 |
+
function drawWaveform() {
|
606 |
+
const canvas = waveformCanvas;
|
607 |
+
const ctx = canvas.getContext('2d');
|
608 |
+
const dpr = window.devicePixelRatio || 1;
|
609 |
+
const rect = canvas.getBoundingClientRect();
|
610 |
+
|
611 |
+
canvas.width = rect.width * dpr;
|
612 |
+
canvas.height = rect.height * dpr;
|
613 |
+
ctx.scale(dpr, dpr);
|
614 |
+
|
615 |
+
const width = canvas.width / dpr;
|
616 |
+
const height = canvas.height / dpr;
|
617 |
+
const barWidth = 3;
|
618 |
+
const gap = 2;
|
619 |
+
const numBars = Math.floor(width / (barWidth + gap));
|
620 |
+
|
621 |
+
ctx.clearRect(0, 0, width, height);
|
622 |
+
|
623 |
+
const progress = audioPlayer.currentTime / audioPlayer.duration;
|
624 |
+
const progressIndex = Math.floor(waveformData.length * progress);
|
625 |
+
|
626 |
+
waveformData.forEach((value, i) => {
|
627 |
+
const barHeight = value * height * 0.9;
|
628 |
+
const x = i * (barWidth + gap);
|
629 |
+
const y = (height - barHeight) / 2;
|
630 |
+
|
631 |
+
ctx.fillStyle = i < progressIndex ? 'var(--waveform-progress)' : 'var(--waveform-bg)';
|
632 |
+
ctx.fillRect(x, y, barWidth, barHeight);
|
633 |
});
|
634 |
}
|
635 |
+
|
636 |
+
|
637 |
+
// --- CUSTOM PLAYER CONTROLS ---
|
638 |
+
playPauseBtn.addEventListener('click', () => {
|
639 |
+
if (audioPlayer.paused) {
|
640 |
+
audioPlayer.play();
|
641 |
+
} else {
|
642 |
+
audioPlayer.pause();
|
643 |
+
}
|
644 |
+
});
|
645 |
+
|
646 |
+
audioPlayer.addEventListener('play', () => {
|
647 |
+
playIcon.style.display = 'none';
|
648 |
+
pauseIcon.style.display = 'block';
|
649 |
+
playPauseBtn.setAttribute('aria-label', 'توقف');
|
650 |
+
});
|
651 |
|
652 |
+
audioPlayer.addEventListener('pause', () => {
|
653 |
+
playIcon.style.display = 'block';
|
654 |
+
pauseIcon.style.display = 'none';
|
655 |
+
playPauseBtn.setAttribute('aria-label', 'پخش');
|
656 |
});
|
657 |
+
|
658 |
+
audioPlayer.addEventListener('timeupdate', () => {
|
659 |
+
currentTimeEl.textContent = formatTime(audioPlayer.currentTime);
|
660 |
+
if (waveformData.length > 0) {
|
661 |
+
requestAnimationFrame(drawWaveform);
|
662 |
}
|
663 |
});
|
664 |
|
665 |
+
audioPlayer.addEventListener('loadedmetadata', () => {
|
666 |
+
totalDurationEl.textContent = formatTime(audioPlayer.duration);
|
667 |
+
});
|
668 |
+
|
669 |
+
waveformContainer.addEventListener('click', (e) => {
|
670 |
+
const rect = waveformContainer.getBoundingClientRect();
|
671 |
+
const clickPosition = (e.clientX - rect.left) / rect.width;
|
672 |
+
audioPlayer.currentTime = clickPosition * audioPlayer.duration;
|
673 |
+
});
|
674 |
+
|
675 |
+
rewindBtn.addEventListener('click', () => { audioPlayer.currentTime -= 5; });
|
676 |
+
forwardBtn.addEventListener('click', () => { audioPlayer.currentTime += 5; });
|
677 |
|
678 |
+
volumeBtn.addEventListener('click', () => {
|
679 |
+
audioPlayer.muted = !audioPlayer.muted;
|
680 |
+
volumeIcon.style.display = audioPlayer.muted ? 'none' : 'block';
|
681 |
+
muteIcon.style.display = audioPlayer.muted ? 'block' : 'none';
|
682 |
+
});
|
683 |
+
|
684 |
+
speedBtn.addEventListener('click', () => {
|
685 |
+
currentSpeedIndex = (currentSpeedIndex + 1) % playbackSpeeds.length;
|
686 |
+
const newSpeed = playbackSpeeds[currentSpeedIndex];
|
687 |
+
audioPlayer.playbackRate = newSpeed;
|
688 |
+
speedBtn.textContent = `${newSpeed}x`;
|
689 |
+
});
|
690 |
+
|
691 |
+
// --- MAIN GENERATION LOGIC ---
|
692 |
async function generateAudio(event) {
|
693 |
event.preventDefault();
|
694 |
+
showLoadingState();
|
|
|
|
|
|
|
|
|
695 |
|
696 |
const text = textInput.value;
|
|
|
|
|
|
|
|
|
|
|
697 |
if (!text.trim()) {
|
698 |
+
showResultState(false, 'خطا: متن ورودی نمیتواند خالی باشد.');
|
|
|
|
|
699 |
return;
|
700 |
}
|
701 |
+
if (text.length > MAX_CHARS) {
|
702 |
+
showResultState(false, `خطا: طول متن بیش از ${MAX_CHARS.toLocaleString('fa-IR')} نویسه است.`);
|
703 |
+
return;
|
704 |
+
}
|
705 |
+
|
706 |
const payload = {
|
707 |
fn_index: FN_INDEX,
|
708 |
+
data: [false, null, text, promptInput.value, selectedSpeakerIdStorage.value, parseFloat(tempSlider.value)],
|
709 |
event_data: null,
|
710 |
+
session_hash: Math.random().toString(36).substring(2)
|
711 |
};
|
712 |
|
713 |
try {
|
714 |
const joinQueueResponse = await fetch(JOIN_QUEUE_URL, {
|
715 |
+
method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload)
|
|
|
|
|
716 |
});
|
717 |
+
if (!joinQueueResponse.ok) throw new Error(`خطا در ارتباط با سرویس (${joinQueueResponse.status})`);
|
|
|
|
|
|
|
|
|
718 |
|
|
|
|
|
|
|
|
|
|
|
719 |
let finalFilePath = null;
|
720 |
+
const startTime = Date.now();
|
721 |
+
const timeoutDuration = 90000;
|
|
|
|
|
|
|
722 |
|
723 |
+
while (Date.now() - startTime < timeoutDuration) {
|
724 |
+
const dataResponse = await fetch(`${GET_DATA_URL_BASE}?session_hash=${payload.session_hash}`);
|
725 |
+
if (!dataResponse.ok) throw new Error(`خطا در دریافت داده (${dataResponse.status})`);
|
726 |
+
const responseText = await dataResponse.text();
|
727 |
+
const lines = responseText.trim().split('\n');
|
728 |
|
729 |
for (const line of lines) {
|
730 |
if (!line.startsWith('data:')) continue;
|
731 |
+
const data = JSON.parse(line.substring(5));
|
732 |
+
if (data.msg === 'process_completed') {
|
733 |
+
if (data.success && data.output.data?.[0]?.path) {
|
734 |
+
finalFilePath = data.output.data[0].path;
|
735 |
+
} else {
|
736 |
+
throw new Error(data.output?.error || 'خطای ناشناخته در پردازش سرور.');
|
737 |
}
|
738 |
+
break;
|
739 |
+
} else if (data.msg === 'queue_full') {
|
740 |
+
throw new Error('صف پردازش پر است. لطفا کمی بعد تلاش کنید.');
|
741 |
+
}
|
|
|
|
|
|
|
|
|
|
|
742 |
}
|
743 |
+
if (finalFilePath) break;
|
744 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
745 |
}
|
746 |
+
|
747 |
if (finalFilePath) {
|
|
|
748 |
const audioUrl = `${FILE_URL_BASE}${finalFilePath}`;
|
749 |
audioPlayer.src = audioUrl;
|
750 |
+
await processAudioForWaveform(audioUrl); // Process for waveform
|
751 |
+
showResultState(true);
|
752 |
+
} else if (Date.now() - startTime >= timeoutDuration) {
|
753 |
+
throw new Error('پردازش بیش از حد طول کشید و متوقف شد.');
|
754 |
} else {
|
755 |
+
throw new Error('فایل صوتی از سرور دریافت نشد.');
|
756 |
}
|
757 |
|
758 |
} catch (error) {
|
759 |
+
console.error('خطا در فرآیند تولید صدا:', error);
|
760 |
+
showResultState(false, `${error.message}`);
|
|
|
|
|
|
|
761 |
}
|
762 |
}
|
763 |
|
764 |
+
// --- FINAL SETUP ---
|
765 |
+
updateSelectedSpeakerDisplay(selectedSpeakerIdStorage.value || speakers[0].id);
|
766 |
form.addEventListener('submit', generateAudio);
|
767 |
+
window.addEventListener('resize', () => { if (waveformData.length > 0) drawWaveform(); });
|
768 |
+
const styleSheet = document.createElement("style");
|
769 |
+
styleSheet.type = "text/css";
|
770 |
+
styleSheet.innerText = `@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }`;
|
771 |
+
document.head.appendChild(styleSheet);
|
772 |
});
|
773 |
</script>
|
774 |
</body>
|