Hamed744 commited on
Commit
6c93ae9
·
verified ·
1 Parent(s): 8608075

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +1105 -176
index.html CHANGED
@@ -13,15 +13,13 @@
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
- --waveform-color-active: #3B82F6;
23
- --waveform-color-inactive: #D0D9E6;
24
- --waveform-dashed-line-color: #E0E4E9;
25
 
26
  --radius-card: 24px;
27
  --radius-input: 14px;
@@ -29,8 +27,32 @@
29
  --shadow-medium: 0 6px 16px -2px rgba(26, 32, 44, 0.08), 0 3px 8px -3px rgba(26,32,44,0.05);
30
  --shadow-strong: 0 10px 25px -5px rgba(26, 32, 44, 0.12), 0 6px 15px -6px rgba(26,32,44,0.08);
31
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
 
34
  @keyframes spin {
35
  from { transform: rotate(0deg); }
36
  to { transform: rotate(360deg); }
@@ -47,6 +69,7 @@
47
  padding: 2.5rem 0;
48
  min-height: 100vh;
49
  -webkit-font-smoothing: antialiased;
 
50
  display: flex;
51
  justify-content: center;
52
  align-items: flex-start;
@@ -59,14 +82,382 @@
59
  margin: 0 auto;
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  .main-content {
63
  padding: 2.5rem;
64
  background-color: var(--panel-bg);
65
  border-radius: var(--radius-card);
66
  box-shadow: var(--shadow-strong);
67
  border: 1px solid var(--panel-border);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  }
69
 
 
70
  #output-section {
71
  margin-top: 3rem;
72
  display: flex;
@@ -95,13 +486,10 @@
95
  display: none !important;
96
  }
97
 
98
- #status-message {
99
- font-weight: 500;
100
- color: var(--text-secondary);
101
- text-align: center;
102
- font-size: 1.1em;
103
- }
104
 
 
105
  #loading-animation-wrapper {
106
  display: none;
107
  flex-direction: column;
@@ -110,6 +498,57 @@
110
  gap: 1.8rem;
111
  width: 100%;
112
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  /* --- Custom Audio Player Styles --- */
115
  #audio-player-content {
@@ -124,50 +563,67 @@
124
  .audio-waveform-container {
125
  display: flex;
126
  align-items: center;
127
- gap: 1rem;
128
  width: 100%;
129
  margin-bottom: 1rem;
130
  }
131
  .audio-time {
132
  font-size: 0.9em;
133
  color: var(--text-secondary);
134
- min-width: 40px;
135
  text-align: center;
136
- font-variant-numeric: tabular-nums;
 
137
  }
138
 
139
- /* Waveform Display using Canvas */
140
  .audio-waveform {
141
  flex-grow: 1;
142
- height: 60px;
143
  position: relative;
144
- cursor: pointer; /* To indicate it's seekable */
 
 
 
 
145
  }
146
- #waveform-canvas {
 
 
 
 
 
 
 
147
  position: absolute;
148
- top: 0;
149
  left: 0;
150
  width: 100%;
151
- height: 100%;
 
 
 
 
 
152
  }
153
-
154
  /* Audio Controls */
155
  .audio-controls-group {
156
  display: flex;
157
  justify-content: center;
158
  align-items: center;
159
- gap: 1.5rem;
160
- margin-bottom: 1rem;
161
  }
162
  .audio-skip-btn, .audio-play-pause-btn-large, .audio-volume-btn, .audio-speed-btn {
163
  background: none;
164
  border: none;
165
  cursor: pointer;
166
- padding: 8px;
167
  transition: transform 0.2s, opacity 0.2s;
168
  }
169
  .audio-skip-btn, .audio-play-pause-btn-large, .audio-volume-btn {
170
- color: var(--text-secondary);
171
  }
172
  .audio-skip-btn:hover, .audio-play-pause-btn-large:hover, .audio-volume-btn:hover {
173
  opacity: 0.8;
@@ -175,17 +631,33 @@
175
  .audio-skip-btn:active, .audio-play-pause-btn-large:active, .audio-volume-btn:active {
176
  transform: scale(0.9);
177
  }
178
- .audio-skip-btn svg { width: 28px; height: 28px; fill: currentColor; }
179
- .audio-play-pause-btn-large { padding: 0; width: 50px; height: 50px; }
180
- .audio-play-pause-btn-large svg { width: 38px; height: 38px; fill: currentColor; }
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  .audio-utility-controls {
183
  display: flex;
184
  align-items: center;
185
- justify-content: space-between;
186
  width: 100%;
187
  }
188
- .audio-volume-btn svg { width: 24px; height: 24px; fill: currentColor; }
 
 
 
 
189
  .audio-speed-btn {
190
  font-family: var(--app-font);
191
  font-size: 0.9em;
@@ -198,41 +670,134 @@
198
  color: var(--text-primary);
199
  box-shadow: var(--shadow-subtle);
200
  }
201
- .audio-speed-btn:hover { background-color: var(--input-bg); }
 
 
202
 
 
203
  #hidden-audio-player { display: none !important; }
204
 
 
205
  @media (max-width: 600px) {
206
- .main-content, #modal-dialog { padding: 1.5rem; }
207
- #audio-player-content { padding: 1rem; }
208
- .audio-controls-group { gap: 1rem; }
209
- .audio-skip-btn svg { width: 24px; height: 24px; }
210
- .audio-play-pause-btn-large { width: 44px; height: 44px; }
211
- .audio-play-pause-btn-large svg { width: 32px; height: 32px; }
212
- }
213
- /* Other styles for modals, forms, etc. are omitted for brevity but should be included from the previous version */
214
- .app-header,.form-group,.modal-overlay,#generate-btn { /* Placeholder for other styles */ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  </style>
216
  </head>
217
  <body>
218
  <div class="container">
219
- <!-- Header, Form, Modals from previous code... -->
 
 
 
 
220
  <main class="main-content">
221
- <!-- Form content goes here... -->
222
- <form id="tts-form">
223
- <!-- All form-groups go here -->
224
- </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
226
  <div id="output-section">
227
  <div id="status-message">صدای تولید شده در اینجا نمایش داده خواهد شد.</div>
228
- <div id="loading-animation-wrapper">...</div>
 
 
 
 
 
 
 
229
 
230
  <!-- Custom Audio Player Structure -->
231
  <div id="audio-player-content">
232
  <div class="audio-waveform-container">
233
  <span class="audio-time audio-current-time">0:00</span>
234
  <div class="audio-waveform">
235
- <canvas id="waveform-canvas"></canvas>
 
236
  </div>
237
  <span class="audio-time audio-total-time">0:00</span>
238
  </div>
@@ -258,22 +823,115 @@
258
  <button class="audio-speed-btn">1x</button>
259
  </div>
260
  </div>
261
- <audio id="hidden-audio-player" crossorigin="anonymous"></audio>
262
  </div>
263
  </main>
264
  </div>
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  <script>
267
  document.addEventListener('DOMContentLoaded', () => {
268
- // All previous variables for elements, modals, etc. go here...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  const hiddenAudioPlayer = document.getElementById('hidden-audio-player');
270
  const audioPlayerContent = document.getElementById('audio-player-content');
271
- const waveformCanvas = document.getElementById('waveform-canvas');
272
- const canvasCtx = waveformCanvas.getContext('2d');
273
-
274
- // Other element variables...
275
  const audioCurrentTimeSpan = audioPlayerContent.querySelector('.audio-current-time');
276
  const audioTotalTimeSpan = audioPlayerContent.querySelector('.audio-total-time');
 
 
277
  const playPauseBtn = audioPlayerContent.querySelector('.audio-play-pause-btn-large');
278
  const playIcon = playPauseBtn.querySelector('.play-icon');
279
  const pauseIcon = playPauseBtn.querySelector('.pause-icon');
@@ -284,98 +942,138 @@
284
  const volumeMuteIcon = volumeBtn.querySelector('.volume-mute-icon');
285
  const speedBtn = audioPlayerContent.querySelector('.audio-speed-btn');
286
 
287
- let audioContext;
288
- let audioBuffer; // To store the decoded audio data
289
 
290
- // --- Web Audio API and Waveform Drawing ---
 
291
 
292
- async function generateRealWaveform(audioUrl) {
293
- // Initialize AudioContext on user interaction
294
- if (!audioContext) {
295
- audioContext = new (window.AudioContext || window.webkitAudioContext)();
 
 
 
 
 
 
 
 
 
 
296
  }
 
297
 
298
- try {
299
- // Fetch the audio file as a blob
300
- const response = await fetch(audioUrl, { mode: 'cors' });
301
- if (!response.ok) {
302
- throw new Error(`HTTP error! status: ${response.status}`);
303
- }
304
- const arrayBuffer = await response.arrayBuffer();
305
 
306
- // Decode the audio data
307
- audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
308
- drawWaveform(audioBuffer);
 
 
 
 
 
309
 
310
- } catch (error) {
311
- console.error('Error processing audio for waveform:', error);
312
- console.error("This is likely a CORS issue. The audio server must send 'Access-Control-Allow-Origin: *' header for waveform analysis to work.");
313
- // Fallback: Clear the canvas if it fails
314
- canvasCtx.clearRect(0, 0, waveformCanvas.width, waveformCanvas.height);
315
- alert("متاسفانه به دلیل محدودیت‌های امنیتی (CORS) امکان تولید موج صوتی واقعی وجود ندارد.");
316
- }
 
317
  }
318
 
319
- function drawWaveform(buffer, progress = 0) {
320
- const canvas = waveformCanvas;
321
- const ctx = canvasCtx;
322
- const dpr = window.devicePixelRatio || 1;
323
-
324
- // Set canvas dimensions based on its display size
325
- const rect = canvas.getBoundingClientRect();
326
- canvas.width = rect.width * dpr;
327
- canvas.height = rect.height * dpr;
328
- ctx.scale(dpr, dpr);
329
-
330
- const data = buffer.getChannelData(0); // Use the first channel
331
- const barWidth = 3;
332
- const barGap = 2;
333
- const totalBarWidth = barWidth + barGap;
334
- const numBars = Math.floor(canvas.width / dpr / totalBarWidth);
335
- const step = Math.floor(data.length / numBars);
336
-
337
- ctx.clearRect(0, 0, canvas.width, canvas.height);
 
 
 
 
 
 
338
 
339
- // Draw the inactive (grey) waveform
340
- for (let i = 0; i < numBars; i++) {
341
- let min = 1.0;
342
- let max = -1.0;
 
 
 
 
343
 
344
- for (let j = 0; j < step; j++) {
345
- const datum = data[(i * step) + j];
346
- if (datum < min) min = datum;
347
- if (datum > max) max = datum;
348
- }
 
349
 
350
- const amp = (max - min); // Amplitude for this segment
351
- const barHeight = Math.max(1, amp * (canvas.height / dpr / 2));
352
- const y = (canvas.height / dpr / 2) - (barHeight / 2);
353
- const x = i * totalBarWidth;
354
-
355
- ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--waveform-color-inactive').trim();
356
- ctx.fillRect(x, y, barWidth, barHeight);
 
 
 
 
 
 
 
 
 
357
  }
358
-
359
- // Draw the active (blue) progress overlay
360
- if (progress > 0) {
361
- ctx.save();
362
- ctx.globalCompositeOperation = 'source-atop'; // This will only draw on top of existing pixels
363
- ctx.fillStyle = getComputedStyle(document.documentElement).getPropertyValue('--waveform-color-active').trim();
364
- ctx.fillRect(0, 0, progress * (canvas.width / dpr), canvas.height);
365
- ctx.restore();
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  }
 
367
 
368
- // Draw the dashed line
369
- ctx.beginPath();
370
- ctx.strokeStyle = getComputedStyle(document.documentElement).getPropertyValue('--waveform-dashed-line-color').trim();
371
- ctx.lineWidth = 1;
372
- ctx.setLineDash([4, 2]);
373
- ctx.moveTo(0, canvas.height / dpr / 2);
374
- ctx.lineTo(canvas.width / dpr, canvas.height / dpr / 2);
375
- ctx.stroke();
376
- }
377
-
378
- // --- Player UI and State Management ---
379
 
380
  function formatTime(seconds) {
381
  if (isNaN(seconds) || seconds < 0) return '0:00';
@@ -384,76 +1082,307 @@
384
  return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
385
  }
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  function updatePlayerUI() {
388
- // Update play/pause icon
389
- playIcon.style.display = hiddenAudioPlayer.paused ? 'block' : 'none';
390
- pauseIcon.style.display = hiddenAudioPlayer.paused ? 'none' : 'block';
391
-
392
- // Update time display
 
 
 
393
  const currentTime = hiddenAudioPlayer.currentTime;
394
  const duration = hiddenAudioPlayer.duration;
 
395
  audioCurrentTimeSpan.textContent = formatTime(currentTime);
396
 
397
  if (isFinite(duration) && duration > 0) {
398
  audioTotalTimeSpan.textContent = formatTime(duration);
399
- if (audioBuffer) {
400
- // Redraw the waveform with the new progress
401
- drawWaveform(audioBuffer, currentTime / duration);
402
- }
403
  } else {
404
  audioTotalTimeSpan.textContent = '0:00';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
405
  }
 
 
406
  }
407
-
408
- // Event listener for seeking on the canvas
409
- waveformCanvas.addEventListener('click', (e) => {
410
- if (!hiddenAudioPlayer.duration) return;
411
- const rect = waveformCanvas.getBoundingClientRect();
412
- const x = e.clientX - rect.left;
413
- const clickPositionRatio = x / rect.width;
414
- hiddenAudioPlayer.currentTime = clickPositionRatio * hiddenAudioPlayer.duration;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  });
416
 
417
 
418
- function showResultState(isSuccess, message = '', audioUrl = '') {
419
- const loadingAnimationWrapper = document.getElementById('loading-animation-wrapper');
420
- const statusMessage = document.getElementById('status-message');
421
- const outputSection = document.getElementById('output-section');
 
 
 
 
 
 
 
 
 
 
 
422
 
 
423
  loadingAnimationWrapper.style.display = 'none';
424
- if (isSuccess && audioUrl) {
425
  statusMessage.style.display = 'none';
426
  audioPlayerContent.style.display = 'flex';
427
  outputSection.classList.add('has-content');
428
-
429
- // Generate the real waveform
430
- generateRealWaveform(audioUrl);
431
-
432
- hiddenAudioPlayer.play();
433
  } else {
434
- // Handle failure...
 
 
 
 
 
 
 
435
  }
 
 
436
  }
437
-
438
- // Rest of your JS code (event listeners for buttons, API calls, etc.)
439
- // Make sure the `generateAudio` function calls `showResultState` like this:
440
- // showResultState(true, '', audioUrl);
441
 
442
- // Placeholder for the main API call function
443
  async function generateAudio(event) {
444
- // ... your existing API call logic ...
445
- // On success:
446
- // const audioUrl = `${FILE_URL_BASE}${finalFilePath}`;
447
- // hiddenAudioPlayer.src = audioUrl;
448
- // showResultState(true, '', audioUrl);
449
- // On failure:
450
- // showResultState(false, 'Error message');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  }
452
 
453
- // All other event listeners for player buttons...
454
- playPauseBtn.addEventListener('click', () => { /* ... */ });
455
- skipBackwardBtn.addEventListener('click', () => { /* ... */ });
456
- // etc.
 
 
 
457
  });
458
  </script>
459
  </body>
 
13
  --panel-bg: #FFFFFF;
14
  --panel-border: #E8EEF3;
15
  --text-primary: #121826;
16
+ --text-secondary: #5C677D; /* Main grey for secondary text and icons */
17
+ --accent-primary: #3B82F6; /* Blue for highlights */
18
  --accent-primary-hover: #2563EB;
19
+ --accent-secondary: #10B981; /* Green for success/other highlights */
20
  --accent-secondary-hover: #059669;
21
  --input-bg: #F8FAFC;
22
+ --input-border-focus: var(--accent-primary);
 
 
23
 
24
  --radius-card: 24px;
25
  --radius-input: 14px;
 
27
  --shadow-medium: 0 6px 16px -2px rgba(26, 32, 44, 0.08), 0 3px 8px -3px rgba(26,32,44,0.05);
28
  --shadow-strong: 0 10px 25px -5px rgba(26, 32, 44, 0.12), 0 6px 15px -6px rgba(26,32,44,0.08);
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
+ /* Custom Audio Player Colors */
33
+ --waveform-color-active: #3B82F6; /* Blue for active part of waveform */
34
+ --waveform-color-inactive: #D0D9E6; /* Lighter shade for inactive part of waveform */
35
+ --waveform-dashed-line-color: #E0E4E9; /* Very light grey for the dashed line */
36
+ }
37
+
38
+ @keyframes fadeInDown {
39
+ from { opacity: 0; transform: translateY(-20px); }
40
+ to { opacity: 1; transform: translateY(0); }
41
+ }
42
+ @keyframes fadeInUp {
43
+ from { opacity: 0; transform: translateY(20px); }
44
+ to { opacity: 1; transform: translateY(0); }
45
+ }
46
+ @keyframes modalZoomIn {
47
+ from { opacity: 0; transform: scale(0.8) translateY(20px); }
48
+ to { opacity: 1; transform: scale(1) translateY(0); }
49
+ }
50
+ @keyframes modalZoomOut {
51
+ from { opacity: 1; transform: scale(1) translateY(0); }
52
+ to { opacity: 0; transform: scale(0.8) translateY(20px); }
53
  }
54
 
55
+ /* Keyframe for loading spinner in button */
56
  @keyframes spin {
57
  from { transform: rotate(0deg); }
58
  to { transform: rotate(360deg); }
 
69
  padding: 2.5rem 0;
70
  min-height: 100vh;
71
  -webkit-font-smoothing: antialiased;
72
+ -moz-osx-font-smoothing: grayscale;
73
  display: flex;
74
  justify-content: center;
75
  align-items: flex-start;
 
82
  margin: 0 auto;
83
  }
84
 
85
+ .app-header {
86
+ padding: 0.5rem 0 2.5rem 0;
87
+ text-align: center;
88
+ margin-bottom: 1.5rem;
89
+ animation: fadeInDown 0.8s 0.1s ease-out backwards;
90
+ }
91
+ .app-header h1 {
92
+ font-size: 2.1em;
93
+ font-weight: 900;
94
+ margin:0 0 0.6rem 0;
95
+ background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
96
+ -webkit-background-clip: text;
97
+ -webkit-text-fill-color: transparent;
98
+ letter-spacing: -0.5px;
99
+ }
100
+ .app-header p {
101
+ font-size: 1em;
102
+ color: var(--text-secondary);
103
+ margin-top:0;
104
+ opacity: 0.85;
105
+ font-weight: 400;
106
+ line-height: 1.6;
107
+ }
108
+
109
  .main-content {
110
  padding: 2.5rem;
111
  background-color: var(--panel-bg);
112
  border-radius: var(--radius-card);
113
  box-shadow: var(--shadow-strong);
114
  border: 1px solid var(--panel-border);
115
+ animation: fadeInUp 0.8s 0.3s ease-out backwards;
116
+ }
117
+
118
+ .form-group { margin-bottom: 2rem; }
119
+
120
+ .label-with-info {
121
+ display: flex;
122
+ align-items: center;
123
+ gap: 0.5rem;
124
+ margin-bottom: 1rem;
125
+ }
126
+ .label-with-info label {
127
+ margin-bottom: 0;
128
+ }
129
+
130
+ .info-icon {
131
+ display: inline-flex;
132
+ align-items: center;
133
+ justify-content: center;
134
+ width: 22px;
135
+ height: 22px;
136
+ border-radius: 50%;
137
+ background-color: var(--input-bg);
138
+ border: 1px solid var(--panel-border);
139
+ color: var(--text-secondary);
140
+ font-size: 0.9em;
141
+ font-weight: 700;
142
+ cursor: pointer;
143
+ position: relative;
144
+ transition: var(--transition-smooth);
145
+ user-select: none;
146
+ }
147
+ .info-icon:hover, .info-icon:focus {
148
+ background-color: var(--accent-primary);
149
+ color: white;
150
+ border-color: var(--accent-primary);
151
+ transform: scale(1.1);
152
+ outline: none;
153
+ }
154
+
155
+ label {
156
+ display: block;
157
+ font-weight: 700;
158
+ color: var(--text-primary);
159
+ font-size: 1.05em;
160
+ margin-bottom: 0.8rem;
161
+ }
162
+
163
+ textarea, input[type="text"] {
164
+ width: 100%;
165
+ padding: 0.9rem 1.1rem;
166
+ border-radius: var(--radius-input);
167
+ border: 1px solid var(--panel-border);
168
+ background-color: var(--input-bg);
169
+ color: var(--text-primary);
170
+ box-shadow: var(--shadow-subtle) inset;
171
+ font-family: var(--app-font);
172
+ font-size: 1rem;
173
+ box-sizing: border-box;
174
+ transition: var(--transition-smooth);
175
+ }
176
+ textarea:focus, input[type="text"]:focus {
177
+ outline: none;
178
+ border-color: var(--input-border-focus);
179
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25), var(--shadow-subtle) inset;
180
+ background-color: #fff;
181
+ }
182
+ textarea { min-height: 100px; resize: vertical; }
183
+
184
+ .char-counter-wrapper {
185
+ font-size: 0.85em;
186
+ color: var(--text-secondary);
187
+ text-align: left;
188
+ margin-top: 0.5rem;
189
+ padding: 0 0.2rem;
190
+ }
191
+ #char-count { font-weight: 600; color: var(--accent-primary); }
192
+
193
+
194
+ /* --- نمایش گوینده منتخب --- */
195
+ #selected-speaker-display { text-align: center; margin-top: 1rem; position: relative; }
196
+ #selected-speaker-card {
197
+ display: inline-flex;
198
+ align-items: center;
199
+ background: linear-gradient(135deg, var(--input-bg) 0%, #fff 100%);
200
+ border-radius: var(--radius-card);
201
+ padding: 1rem 1.2rem;
202
+ box-shadow: var(--shadow-medium);
203
+ border: 1px solid var(--panel-border);
204
+ transition: var(--transition-bounce);
205
+ position: relative;
206
+ margin-bottom: 1.2rem;
207
+ cursor: pointer;
208
+ }
209
+ #selected-speaker-card:hover {
210
+ transform: translateY(-6px) scale(1.03);
211
+ box-shadow: var(--shadow-strong);
212
+ }
213
+ #selected-speaker-card img {
214
+ width: 75px; height: 75px;
215
+ border-radius: 50%;
216
+ object-fit: cover;
217
+ margin-left: 18px;
218
+ border: 3px solid var(--accent-secondary);
219
+ box-shadow: 0 0 12px -2px rgba(16, 185, 129, 0.5);
220
+ background-color: #e0e0e0;
221
+ transition: var(--transition-smooth);
222
+ }
223
+ #selected-speaker-card:hover img {
224
+ transform: scale(1.08) rotate(3deg);
225
+ }
226
+ #selected-speaker-info h3 { margin: 0; font-size: 1.35em; font-weight: 800; color: var(--text-primary); }
227
+ #selected-speaker-info p { margin: 4px 0 0; color: var(--text-secondary); font-size: 0.88em; font-weight: 500; }
228
+
229
+ #change-speaker-btn {
230
+ display: inline-flex;
231
+ align-items: center;
232
+ justify-content: center;
233
+ margin: 0 auto;
234
+ padding: 10px 20px;
235
+ border-radius: var(--radius-input);
236
+ background: linear-gradient(45deg, var(--accent-primary-hover), var(--accent-primary));
237
+ border: none;
238
+ color: #fff;
239
+ cursor: pointer;
240
+ font-family: var(--app-font); font-weight: 600;
241
+ font-size: 1em;
242
+ transition: var(--transition-smooth);
243
+ box-shadow: 0 4px 10px -2px rgba(59, 130, 246, 0.35), var(--shadow-subtle);
244
+ }
245
+ #change-speaker-btn:hover {
246
+ background: linear-gradient(45deg, var(--accent-primary), var(--accent-primary-hover));
247
+ transform: translateY(-3px) scale(1.05);
248
+ box-shadow: 0 6px 12px -3px rgba(59, 130, 246, 0.45), var(--shadow-medium);
249
+ }
250
+ #change-speaker-btn svg {
251
+ width: 1.1em;
252
+ height: 1.1em;
253
+ margin-right: 0.5em;
254
+ fill: currentColor;
255
+ }
256
+
257
+
258
+ /* --- مودال عمومی --- */
259
+ .modal-overlay {
260
+ position: fixed; top: 0; left: 0; width: 100%; height: 100%;
261
+ background-color: rgba(18, 24, 38, 0.6);
262
+ backdrop-filter: blur(8px) saturate(150%);
263
+ display: none; /* Hidden by default */
264
+ align-items: center; justify-content: center;
265
+ z-index: 1000; opacity: 0;
266
+ transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
267
+ }
268
+ .modal-overlay.visible { display: flex; opacity: 1; }
269
+
270
+ .modal-dialog {
271
+ background: var(--panel-bg);
272
+ padding: 2rem;
273
+ border-radius: var(--radius-card);
274
+ width: 90%;
275
+ box-shadow: var(--shadow-strong);
276
+ border: 1px solid var(--panel-border);
277
+ opacity: 0; /* For animation */
278
+ animation-duration: 0.35s;
279
+ animation-fill-mode: forwards;
280
+ }
281
+ .modal-overlay.visible .modal-dialog {
282
+ animation-name: modalZoomIn;
283
+ }
284
+ .modal-overlay.hiding .modal-dialog {
285
+ animation-name: modalZoomOut;
286
+ }
287
+
288
+
289
+ .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); }
290
+ .modal-header h2 { margin: 0; font-size: 1.6em; font-weight: 800; color: var(--accent-primary);}
291
+ .close-modal-btn { background: none; border: none; font-size: 2.5rem; cursor: pointer; color: var(--text-secondary); transition: var(--transition-smooth); line-height: 1; }
292
+ .close-modal-btn:hover { color: var(--accent-primary); transform: rotate(90deg) scale(1.1); }
293
+
294
+
295
+ /* --- مودال گالری گویندگان (اختصاصی) --- */
296
+ #speaker-modal .modal-dialog {
297
+ max-width: 700px;
298
+ max-height: 85vh; overflow-y: auto;
299
+ }
300
+ #speaker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1.2rem; }
301
+ @media (min-width: 640px) { #speaker-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); } }
302
+ .speaker-card { cursor: pointer; transition: var(--transition-smooth); text-align: center; position: relative;}
303
+ .speaker-card .speaker-visual {
304
+ border: 3px solid transparent;
305
+ border-radius: var(--radius-card);
306
+ overflow: hidden;
307
+ box-shadow: var(--shadow-subtle);
308
+ position: relative;
309
+ background-color: var(--input-bg);
310
+ transition: var(--transition-bounce);
311
+ padding: 6px;
312
+ }
313
+ .speaker-card:hover .speaker-visual {
314
+ transform: translateY(-5px) scale(1.06);
315
+ box-shadow: var(--shadow-medium);
316
+ }
317
+ .speaker-card input[type="radio"] { display: none; }
318
+ .speaker-card img {
319
+ width: 100%; height: 120px;
320
+ object-fit: cover; display: block;
321
+ background-color: #e0e0e0;
322
+ transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
323
+ border-radius: calc(var(--radius-card) - 12px);
324
+ }
325
+ .speaker-card:hover img { transform: scale(1.12); }
326
+ .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; }
327
+ .speaker-card input[type="radio"]:checked + .speaker-visual {
328
+ border-color: var(--accent-secondary);
329
+ box-shadow: 0 0 25px -5px rgba(16, 185, 129, 0.75);
330
+ background: linear-gradient(135deg, var(--accent-secondary-hover), var(--accent-primary));
331
+ transform: scale(1.05);
332
+ }
333
+ .speaker-card input[type="radio"]:checked + .speaker-visual img {
334
+ border: 2px solid white;
335
+ transform: scale(1.05);
336
+ }
337
+ .speaker-card input[type="radio"]:checked + .speaker-visual .speaker-name {
338
+ color: #fff;
339
+ font-weight: 700;
340
+ }
341
+
342
+ /* --- مودال اطلاعات (اختصاصی) --- */
343
+ #info-modal .modal-dialog {
344
+ max-width: 480px; /* Smaller width for info */
345
+ }
346
+ #info-modal-content p {
347
+ font-size: 1em;
348
+ line-height: 1.7;
349
+ color: var(--text-secondary);
350
+ margin-bottom: 0.5rem;
351
+ }
352
+ #info-modal-content p strong {
353
+ color: var(--text-primary);
354
+ font-weight: 600;
355
+ }
356
+ #info-modal-content .range-info {
357
+ font-size: 0.9em;
358
+ color: var(--accent-primary);
359
+ font-weight: 500;
360
+ margin-top: 1rem;
361
+ display: block;
362
+ text-align: center;
363
+ }
364
+
365
+
366
+ /* --- Slider & Button & Output --- */
367
+ .slider-container { display: flex; align-items: center; gap: 1.2rem; }
368
+ input[type="range"] {
369
+ flex-grow: 1; -webkit-appearance: none; appearance: none;
370
+ width: 100%; height: 8px;
371
+ background: #EAF0F6;
372
+ border-radius: 4px; outline: none;
373
+ cursor: pointer;
374
+ transition: background 0.2s;
375
+ }
376
+ input[type="range"]::-webkit-slider-runnable-track {
377
+ background: linear-gradient(to right, var(--accent-secondary) 0%, var(--accent-primary) 100%);
378
+ height: 8px;
379
+ border-radius: 4px;
380
+ }
381
+ input[type="range"]::-webkit-slider-thumb {
382
+ -webkit-appearance: none; appearance: none;
383
+ width: 22px; height: 22px;
384
+ background: #fff;
385
+ border-radius: 50%; cursor: pointer;
386
+ border: 3px solid var(--accent-primary);
387
+ box-shadow: 0 2px 6px rgba(0,0,0,0.15);
388
+ margin-top: -7px;
389
+ transition: transform 0.2s ease, box-shadow 0.2s ease;
390
+ }
391
+ input[type="range"]::-webkit-slider-thumb:hover, input[type="range"]:focus::-webkit-slider-thumb {
392
+ transform: scale(1.2);
393
+ box-shadow: 0 3px 8px rgba(59, 130, 246, 0.35);
394
+ }
395
+ input[type="range"]::-moz-range-thumb {
396
+ width: 22px; height: 22px;
397
+ background: #fff;
398
+ border-radius: 50%; cursor: pointer;
399
+ border: 3px solid var(--accent-primary);
400
+ box-shadow: 0 2px 6px rgba(0,0,0,0.15);
401
+ }
402
+ input[type="range"]::-moz-range-track {
403
+ background: linear-gradient(to right, var(--accent-secondary) 0%, var(--accent-primary) 100%);
404
+ height: 8px;
405
+ border-radius: 4px;
406
+ border: none;
407
+ }
408
+ #temperature-value {
409
+ font-weight: 700; background-color: var(--input-bg);
410
+ padding: 0.5rem 1rem;
411
+ border-radius: 8px;
412
+ border: 1px solid var(--panel-border);
413
+ min-width: 45px; text-align: center;
414
+ color: var(--accent-primary);
415
+ font-size: 1em;
416
+ box-shadow: var(--shadow-subtle);
417
+ }
418
+
419
+ #generate-btn {
420
+ width: 100%; padding: 1rem 1.5rem;
421
+ font-size: 1.25em; font-weight: 800;
422
+ font-family: var(--app-font);
423
+ background: linear-gradient(95deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
424
+ color: #fff;
425
+ border: none;
426
+ border-radius: var(--radius-input);
427
+ cursor: pointer;
428
+ transition: var(--transition-smooth), transform 0.15s ease-out;
429
+ box-shadow: 0 5px 15px -4px rgba(59, 130, 246, 0.45), 0 5px 15px -4px rgba(16, 185, 129, 0.35);
430
+ position: relative;
431
+ overflow: hidden;
432
+ letter-spacing: 0.5px;
433
+ }
434
+ #generate-btn::before {
435
+ content: ''; position: absolute;
436
+ top: 0; left: -180%; width: 80%; height: 100%;
437
+ background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 100%);
438
+ transform: skewX(-30deg);
439
+ transition: left 0.8s cubic-bezier(0.23, 1, 0.32, 1);
440
+ }
441
+ #generate-btn:hover::before { left: 180%; }
442
+ #generate-btn:hover:not(:disabled) {
443
+ transform: translateY(-5px) scale(1.02);
444
+ box-shadow: 0 8px 20px -4px rgba(59, 130, 246, 0.55), 0 8px 20px -4px rgba(16, 185, 129, 0.45);
445
+ }
446
+ #generate-btn:active:not(:disabled) {
447
+ transform: translateY(-2px) scale(0.98);
448
+ }
449
+ #generate-btn:disabled {
450
+ background: #B8C2CC;
451
+ cursor: not-allowed; box-shadow: none; color: #E8EEF3;
452
+ transform: none;
453
+ }
454
+ #generate-btn:disabled::before { display: none; }
455
+ #generate-btn svg {
456
+ display:inline-block; margin-left: 0.5em; width:1.2em; height:1.2em;
457
+ vertical-align: middle;
458
  }
459
 
460
+ /* --- Output Section (now the card container for status/loading/player) --- */
461
  #output-section {
462
  margin-top: 3rem;
463
  display: flex;
 
486
  display: none !important;
487
  }
488
 
489
+ #status-message { font-weight: 500; color: var(--text-secondary); text-align: center; font-size: 1.1em; }
490
+
 
 
 
 
491
 
492
+ /* --- انیمیشن پردازش --- */
493
  #loading-animation-wrapper {
494
  display: none;
495
  flex-direction: column;
 
498
  gap: 1.8rem;
499
  width: 100%;
500
  }
501
+ .orbital-loader {
502
+ width: 110px;
503
+ height: 110px;
504
+ position: relative;
505
+ animation: rotate-loader-orbital 10s linear infinite;
506
+ }
507
+ .orbit {
508
+ position: absolute;
509
+ top: 50%; left: 50%;
510
+ border: 2px dashed rgba(59, 130, 246, 0.25);
511
+ border-radius: 50%;
512
+ transform-origin: center center;
513
+ }
514
+ .orbit:nth-child(1) { width: 35px; height: 35px; margin: -17.5px 0 0 -17.5px; animation: orbit-spin 2.8s linear infinite reverse; }
515
+ .orbit:nth-child(2) { width: 65px; height: 65px; margin: -32.5px 0 0 -32.5px; animation: orbit-spin 3.8s linear infinite; }
516
+ .orbit:nth-child(3) { width: 95px; height: 95px; margin: -47.5px 0 0 -47.5px; animation: orbit-spin 4.8s linear infinite reverse; }
517
+
518
+ .orbit .satellite {
519
+ position: absolute;
520
+ width: 10px; height: 10px;
521
+ border-radius: 50%;
522
+ background-color: var(--accent-primary);
523
+ box-shadow: 0 0 8px var(--accent-primary), 0 0 12px var(--accent-secondary);
524
+ }
525
+ .orbit:nth-child(1) .satellite { top: -5px; left: 50%; animation: satellite-pulse-1 1.4s ease-in-out infinite alternate; }
526
+ .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; }
527
+ .orbit:nth-child(3) .satellite { bottom: -5px; right: 50%; animation: satellite-pulse-3 1.4s 0.4s ease-in-out infinite alternate;}
528
+
529
+ @keyframes rotate-loader-orbital { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
530
+ @keyframes orbit-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
531
+ @keyframes satellite-pulse-1 {
532
+ from { transform: scale(0.7) translateX(-50%); opacity: 0.6; }
533
+ to { transform: scale(1.1) translateX(-50%); opacity: 1; }
534
+ }
535
+ @keyframes satellite-pulse-2 {
536
+ from { transform: scale(0.7) translateY(-50%); opacity: 0.6; }
537
+ to { transform: scale(1.1) translateY(-50%); opacity: 1; }
538
+ }
539
+ @keyframes satellite-pulse-3 {
540
+ from { transform: scale(0.7) translateX(50%); opacity: 0.6; }
541
+ to { transform: scale(1.1) translateX(50%); opacity: 1; }
542
+ }
543
+ #loading-text {
544
+ font-size: 1.2em;
545
+ font-weight: 700;
546
+ color: var(--text-primary);
547
+ text-align: center;
548
+ background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
549
+ -webkit-background-clip: text;
550
+ -webkit-text-fill-color: transparent;
551
+ }
552
 
553
  /* --- Custom Audio Player Styles --- */
554
  #audio-player-content {
 
563
  .audio-waveform-container {
564
  display: flex;
565
  align-items: center;
566
+ gap: 1rem; /* Space between time labels and waveform */
567
  width: 100%;
568
  margin-bottom: 1rem;
569
  }
570
  .audio-time {
571
  font-size: 0.9em;
572
  color: var(--text-secondary);
573
+ min-width: 40px; /* Consistent width for time labels */
574
  text-align: center;
575
+ font-variant-numeric: tabular-nums; /* Ensures numbers align vertically */
576
+ user-select: none; /* Prevent selection of time text */
577
  }
578
 
579
+ /* Waveform Display (Canvas now) */
580
  .audio-waveform {
581
  flex-grow: 1;
582
+ height: 60px; /* Fixed height for the waveform area */
583
  position: relative;
584
+ overflow: hidden; /* To contain dashed line */
585
+ display: flex; /* Flex context for canvas alignment */
586
+ align-items: center; /* Vertically center canvas */
587
+ justify-content: center; /* Horizontally center canvas */
588
+ margin-bottom: 0.5rem; /* Slightly less space from controls for compact feel */
589
  }
590
+
591
+ #audio-waveform-canvas {
592
+ display: block; /* Remove extra space below canvas */
593
+ max-width: 100%; /* Ensure canvas doesn't overflow */
594
+ height: 100%; /* Canvas takes full height of its container */
595
+ }
596
+
597
+ .audio-waveform-dashed-line {
598
  position: absolute;
599
+ top: 50%;
600
  left: 0;
601
  width: 100%;
602
+ height: 1px;
603
+ background-image: linear-gradient(to right, var(--waveform-dashed-line-color) 33%, transparent 0%);
604
+ background-position: center;
605
+ background-size: 10px 1px;
606
+ transform: translateY(-50%);
607
+ z-index: 1; /* Above the canvas */
608
  }
609
+
610
  /* Audio Controls */
611
  .audio-controls-group {
612
  display: flex;
613
  justify-content: center;
614
  align-items: center;
615
+ gap: 1.5rem; /* Space between play/skip buttons */
616
+ margin-bottom: 1rem; /* Space between main controls and utility controls */
617
  }
618
  .audio-skip-btn, .audio-play-pause-btn-large, .audio-volume-btn, .audio-speed-btn {
619
  background: none;
620
  border: none;
621
  cursor: pointer;
622
+ padding: 8px; /* Default padding for clickable area */
623
  transition: transform 0.2s, opacity 0.2s;
624
  }
625
  .audio-skip-btn, .audio-play-pause-btn-large, .audio-volume-btn {
626
+ color: var(--text-secondary); /* Grey for icons */
627
  }
628
  .audio-skip-btn:hover, .audio-play-pause-btn-large:hover, .audio-volume-btn:hover {
629
  opacity: 0.8;
 
631
  .audio-skip-btn:active, .audio-play-pause-btn-large:active, .audio-volume-btn:active {
632
  transform: scale(0.9);
633
  }
634
+ .audio-skip-btn svg {
635
+ width: 28px;
636
+ height: 28px;
637
+ fill: currentColor;
638
+ }
639
+ .audio-play-pause-btn-large {
640
+ padding: 0; /* Remove padding for this button to control size via width/height */
641
+ width: 50px;
642
+ height: 50px;
643
+ }
644
+ .audio-play-pause-btn-large svg {
645
+ width: 38px;
646
+ height: 38px;
647
+ fill: currentColor;
648
+ }
649
 
650
  .audio-utility-controls {
651
  display: flex;
652
  align-items: center;
653
+ justify-content: space-between; /* Volume left, Speed right */
654
  width: 100%;
655
  }
656
+ .audio-volume-btn svg {
657
+ width: 24px;
658
+ height: 24px;
659
+ fill: currentColor;
660
+ }
661
  .audio-speed-btn {
662
  font-family: var(--app-font);
663
  font-size: 0.9em;
 
670
  color: var(--text-primary);
671
  box-shadow: var(--shadow-subtle);
672
  }
673
+ .audio-speed-btn:hover {
674
+ background-color: var(--input-bg);
675
+ }
676
 
677
+ /* Hide the default audio player */
678
  #hidden-audio-player { display: none !important; }
679
 
680
+ /* Responsive adjustments for mobile */
681
  @media (max-width: 600px) {
682
+ .container {
683
+ width: 95%;
684
+ }
685
+ .main-content {
686
+ padding: 1.5rem;
687
+ }
688
+ .app-header h1 {
689
+ font-size: 1.8em;
690
+ }
691
+ #audio-player-content {
692
+ padding: 1rem;
693
+ gap: 0.8rem; /* Reduce gap inside player */
694
+ }
695
+ .audio-waveform-container {
696
+ gap: 0.5rem; /* Reduce gap around waveform */
697
+ }
698
+ .audio-time {
699
+ font-size: 0.85em; /* Smaller time font */
700
+ min-width: 35px;
701
+ }
702
+ .audio-skip-btn svg {
703
+ width: 24px;
704
+ height: 24px;
705
+ }
706
+ .audio-play-pause-btn-large {
707
+ width: 44px;
708
+ height: 44px;
709
+ }
710
+ .audio-play-pause-btn-large svg {
711
+ width: 32px;
712
+ height: 32px;
713
+ }
714
+ .audio-controls-group {
715
+ gap: 1rem; /* Reduce gap between play/skip */
716
+ }
717
+ .audio-volume-btn svg {
718
+ width: 20px;
719
+ height: 20px;
720
+ }
721
+ .audio-speed-btn {
722
+ font-size: 0.8em;
723
+ padding: 5px 10px;
724
+ }
725
+ }
726
  </style>
727
  </head>
728
  <body>
729
  <div class="container">
730
+ <header class="app-header">
731
+ <h1>تبدیل متن به صدا با هوش مصنوعی آلفا</h1>
732
+ <p>صدایی نو، تجربه‌ای نوین در تبدیل متن به گفتار با هوش مصنوعی پیشرفته</p>
733
+ </header>
734
+
735
  <main class="main-content">
736
+ <form id="tts-form">
737
+ <div class="form-group">
738
+ <label for="text-input">📝 متن مورد نظر شما</label>
739
+ <textarea id="text-input" rows="4" placeholder="متن خود را اینجا وارد کنید..."></textarea>
740
+ <div class="char-counter-wrapper">
741
+ <span id="char-count">0</span> / <span id="char-max">50000</span> نویسه
742
+ </div>
743
+ </div>
744
+ <div class="form-group">
745
+ <label for="prompt-input">🗣️ توصیف سبک و لحن گفتار (اختیاری)</label>
746
+ <input type="text" id="prompt-input" placeholder="مثال: با لحنی رسمی و موقر، یا شاد و کودکانه">
747
+ </div>
748
+
749
+ <div class="form-group">
750
+ <label>🎤 انتخاب گوینده حرفه‌ای</label>
751
+ <div id="selected-speaker-display">
752
+ <div id="selected-speaker-card" title="برای تغییر گوینده کلیک کنید">
753
+ <img id="selected-speaker-img" src="" alt="عکس گوینده">
754
+ <div id="selected-speaker-info">
755
+ <h3 id="selected-speaker-name"></h3>
756
+ <p id="selected-speaker-desc">گوینده پیش‌فرض</p>
757
+ </div>
758
+ </div>
759
+ <button type="button" id="change-speaker-btn">
760
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
761
+ <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" />
762
+ </svg>
763
+ تغییر گوینده
764
+ </button>
765
+ </div>
766
+ </div>
767
+
768
+ <div class="form-group">
769
+ <div class="label-with-info">
770
+ <label for="temperature-slider">🌡️ میزان خلاقیت و نوآوری صدا</label>
771
+ <div class="info-icon" id="temp-info-icon" role="button" tabindex="0" aria-label="اطلاعات بیشتر">!
772
+ </div>
773
+ </div>
774
+ <div class="slider-container">
775
+ <input type="range" id="temperature-slider" min="0.1" max="1.5" step="0.05" value="0.9">
776
+ <span id="temperature-value">0.9</span>
777
+ </div>
778
+ </div>
779
+
780
+ <button type="submit" id="generate-btn">✨ تولید صدا با آلفا</button>
781
+ </form>
782
 
783
  <div id="output-section">
784
  <div id="status-message">صدای تولید شده در اینجا نمایش داده خواهد شد.</div>
785
+ <div id="loading-animation-wrapper">
786
+ <div class="orbital-loader">
787
+ <div class="orbit"><div class="satellite"></div></div>
788
+ <div class="orbit"><div class="satellite"></div></div>
789
+ <div class="orbit"><div class="satellite"></div></div>
790
+ </div>
791
+ <p id="loading-text">در حال پردازش هوشمند و تولید صدا...</p>
792
+ </div>
793
 
794
  <!-- Custom Audio Player Structure -->
795
  <div id="audio-player-content">
796
  <div class="audio-waveform-container">
797
  <span class="audio-time audio-current-time">0:00</span>
798
  <div class="audio-waveform">
799
+ <canvas id="audio-waveform-canvas"></canvas>
800
+ <div class="audio-waveform-dashed-line"></div>
801
  </div>
802
  <span class="audio-time audio-total-time">0:00</span>
803
  </div>
 
823
  <button class="audio-speed-btn">1x</button>
824
  </div>
825
  </div>
826
+ <audio id="hidden-audio-player" style="display: none;"></audio>
827
  </div>
828
  </main>
829
  </div>
830
 
831
+ <!-- مودال گالری گویندگان -->
832
+ <div id="speaker-modal" class="modal-overlay">
833
+ <div class="modal-dialog">
834
+ <div class="modal-header">
835
+ <h2>گالری گویندگان آلفا نوا</h2>
836
+ <button type="button" class="close-modal-btn" data-modal-id="speaker-modal" aria-label="بستن مودال">×</button>
837
+ </div>
838
+ <div id="speaker-grid">
839
+ <!-- Speaker cards will be generated here by JS -->
840
+ </div>
841
+ </div>
842
+ </div>
843
+
844
+ <!-- مودال اطلاعات خلاقیت صدا -->
845
+ <div id="info-modal" class="modal-overlay">
846
+ <div class="modal-dialog">
847
+ <div class="modal-header">
848
+ <h2>🌡️ خلاقیت و نوآوری صدا</h2>
849
+ <button type="button" class="close-modal-btn" data-modal-id="info-modal" aria-label="بستن توضیحات">×</button>
850
+ </div>
851
+ <div id="info-modal-content">
852
+ <p>این تنظیم مشخص می‌کند که هوش مصنوعی تا چه حد در تولید صدا <strong>خلاقیت</strong> به خرج دهد.</p>
853
+ <p><strong>مقادیر بالاتر:</strong> منجر به صدایی متنوع‌تر، پویاتر و گاهی او��ات غیرمنتظره‌تر می‌شود. مناسب برای زمانی که به دنبال لحنی خاص و منحصربه‌فرد هستید.</p>
854
+ <p><strong>مقادیر پایین‌تر:</strong> صدایی پایدارتر، قابل پیش‌بینی‌تر و نزدیک‌تر به صدای استاندارد گوینده تولید می‌کند. مناسب برای خوانش متون رسمی یا زمانی که ثبات لحن اهمیت دارد.</p>
855
+ <span class="range-info">محدوده پیشنهادی: ۰.۱ (پایدار) تا ۱.۵ (بسیار خلاق)</span>
856
+ </div>
857
+ </div>
858
+ </div>
859
+
860
+
861
+ <input type="hidden" id="selected_speaker_id_storage" value="Charon">
862
+
863
  <script>
864
  document.addEventListener('DOMContentLoaded', () => {
865
+ const HF_SPACE_URL = "https://hamed744-ttspro.hf.space";
866
+ const JOIN_QUEUE_URL = `${HF_SPACE_URL}/gradio_api/queue/join`;
867
+ const GET_DATA_URL_BASE = `${HF_SPACE_URL}/gradio_api/queue/data`;
868
+ const FILE_URL_BASE = `${HF_SPACE_URL}/gradio_api/file=`;
869
+ const FN_INDEX = 1;
870
+
871
+ const speakers = [
872
+ { id: "Charon", name: "شهاب (مرد)", desc: "صدایی قدرتمند و رسا" },
873
+ { id: "Zephyr", name: "آوا (زن)", desc: "لطیف و دلنشین" },
874
+ { id: "Achird", name: "نوید (مرد)", desc: "جوان و پرانرژی" },
875
+ { id: "Zubenelgenubi", name: "رویا (زن)", desc: "گرم و صمیمی" },
876
+ { id: "Vindemiatrix", name: "کیان (مرد)", desc: "باوقار و رسمی" },
877
+ { id: "Sadachbia", name: "پریسا (زن)", desc: "شاداب و پویا" },
878
+ { id: "Sadaltager", name: "آرش (مرد)", desc: "مطمئن و تاثیرگذار" },
879
+ { id: "Sulafat", name: "شبنم (زن)", desc: "آرام و متین" },
880
+ { id: "Laomedeia", name: "سهیل (مرد)", desc: "دوستانه و گیرا" },
881
+ { id: "Achernar", name: "مریم (زن)", desc: "حرفه‌ای و واضح" },
882
+ { id: "Alnilam", name: "بهرام (مرد)", desc: "حماسی و نافذ" },
883
+ { id: "Schedar", name: "نگار (زن)", desc: "مهربان و شیرین" },
884
+ { id: "Gacrux", name: "فرید (مرد)", desc: "پخته و قابل اعتماد" },
885
+ { id: "Pulcherrima", name: "سارا (زن)", desc: "جذاب و مدرن" },
886
+ { id: "Umbriel", name: "مانی (مرد)", desc: "خلاق و متفاوت" },
887
+ { id: "Algieba", name: "آناهیتا (زن)", desc: "با اصالت و شیک" },
888
+ { id: "Despina", name: "دلنواز (زن)", desc: "هنری و احساسی" },
889
+ { id: "Erinome", name: "رسا (مرد)", desc: "شفاف و گویا" },
890
+ { id: "Algenib", name: "امید (مرد)", desc: "انگیزه بخش و مثبت" },
891
+ { id: "Rasalthgeti", name: "الهه (زن)", desc: "اسرارآمیز و فریبنده" },
892
+ { id: "Orus", name: "بردیا (مرد)", desc: "ورزشی و پرهیجان" },
893
+ { id: "Aoede", name: "ترانه (زن)", desc: "موزیکال و خوش‌آهنگ" },
894
+ { id: "Callirrhoe", name: "نیما (مرد)", desc: "روایتگر و قصه‌گو" },
895
+ { id: "Autonoe", name: "هستی (زن)", "desc": "طبیعی و خودمانی" },
896
+ { id: "Enceladus", name: "کامیار (مرد)", desc: "مصمم و جدی" },
897
+ { id: "Iapetus", name: "ستاره (زن)", desc: "درخشان و گیرا" },
898
+ { id: "Puck", name: "پویا (مرد)", desc: "بازیگوش و سرزنده" },
899
+ { id: "Kore", name: "مهتاب (زن)", desc: "نجواگر و آرامش‌بخش" },
900
+ { id: "Fenrir", name: "سام (مرد)", desc: "جسور و بی‌باک" },
901
+ { id: "Leda", name: "لیدا (زن)", desc: "کلاسیک و باوقار" }
902
+ ];
903
+
904
+ const form = document.getElementById('tts-form');
905
+ const textInput = document.getElementById('text-input');
906
+ const promptInput = document.getElementById('prompt-input');
907
+ const tempSlider = document.getElementById('temperature-slider');
908
+ const tempValueSpan = document.getElementById('temperature-value');
909
+ const generateBtn = document.getElementById('generate-btn');
910
+
911
+ const outputSection = document.getElementById('output-section');
912
+ const statusMessage = document.getElementById('status-message');
913
+ const loadingAnimationWrapper = document.getElementById('loading-animation-wrapper');
914
+
915
+ const selectedSpeakerIdStorage = document.getElementById('selected_speaker_id_storage');
916
+ const changeSpeakerBtn = document.getElementById('change-speaker-btn');
917
+ const selectedSpeakerCard = document.getElementById('selected-speaker-card');
918
+ const speakerGridInModal = document.getElementById('speaker-grid');
919
+ const selectedSpeakerImgDisplay = document.getElementById('selected-speaker-img');
920
+ const selectedSpeakerNameDisplay = document.getElementById('selected-speaker-name');
921
+ const selectedSpeakerDescDisplay = document.getElementById('selected-speaker-desc');
922
+
923
+ // Modal Elements
924
+ const speakerModal = document.getElementById('speaker-modal');
925
+ const infoModal = document.getElementById('info-modal');
926
+ const tempInfoIcon = document.getElementById('temp-info-icon');
927
+
928
+ // --- Custom Audio Player Elements ---
929
  const hiddenAudioPlayer = document.getElementById('hidden-audio-player');
930
  const audioPlayerContent = document.getElementById('audio-player-content');
 
 
 
 
931
  const audioCurrentTimeSpan = audioPlayerContent.querySelector('.audio-current-time');
932
  const audioTotalTimeSpan = audioPlayerContent.querySelector('.audio-total-time');
933
+ const audioWaveformCanvas = document.getElementById('audio-waveform-canvas');
934
+ const waveformCtx = audioWaveformCanvas.getContext('2d');
935
  const playPauseBtn = audioPlayerContent.querySelector('.audio-play-pause-btn-large');
936
  const playIcon = playPauseBtn.querySelector('.play-icon');
937
  const pauseIcon = playPauseBtn.querySelector('.pause-icon');
 
942
  const volumeMuteIcon = volumeBtn.querySelector('.volume-mute-icon');
943
  const speedBtn = audioPlayerContent.querySelector('.audio-speed-btn');
944
 
945
+ let currentPlaybackSpeedIndex = 0;
946
+ const playbackSpeeds = [1.0, 1.25, 1.5, 0.75]; // Adjusted speeds as common values
947
 
948
+ let audioPeaks = []; // Stores calculated peaks for waveform
949
+ let audioContext = null; // Will be initialized when needed
950
 
951
+
952
+ // Character Counter
953
+ const charCountSpan = document.getElementById('char-count');
954
+ const charMaxSpan = document.getElementById('char-max');
955
+ const MAX_CHARS = 50000;
956
+ charMaxSpan.textContent = MAX_CHARS.toLocaleString('fa-IR');
957
+
958
+ textInput.addEventListener('input', () => {
959
+ const currentLength = textInput.value.length;
960
+ charCountSpan.textContent = currentLength.toLocaleString('fa-IR');
961
+ if (currentLength > MAX_CHARS) {
962
+ charCountSpan.style.color = 'var(--accent-secondary-hover)';
963
+ } else {
964
+ charCountSpan.style.color = 'var(--accent-primary)';
965
  }
966
+ });
967
 
968
+ function getSpeakerById(id) {
969
+ return speakers.find(s => s.id === id) || speakers[0];
970
+ }
 
 
 
 
971
 
972
+ function getImageUrl(speaker, index, size = 'thumb') {
973
+ const gender = speaker.name.includes('(مرد)') ? 'men' : 'women';
974
+ const imageSeed = speaker.id.charCodeAt(0) + speaker.id.length + index;
975
+ const imageIndex = (imageSeed * 7 + 5) % 100;
976
+ let portraitSizePath = 'thumb/';
977
+ if (size === 'large') portraitSizePath = '';
978
+ return `https://randomuser.me/api/portraits/${portraitSizePath}${gender}/${imageIndex}.jpg`;
979
+ }
980
 
981
+ function updateSelectedSpeakerDisplay(speakerId) {
982
+ const speaker = getSpeakerById(speakerId);
983
+ const speakerIndex = speakers.findIndex(s => s.id === speaker.id);
984
+ selectedSpeakerImgDisplay.src = getImageUrl(speaker, speakerIndex, 'large');
985
+ selectedSpeakerImgDisplay.alt = `عکس گوینده ${speaker.name}`;
986
+ selectedSpeakerNameDisplay.textContent = speaker.name;
987
+ selectedSpeakerDescDisplay.textContent = speaker.desc || "گوینده منتخب شما";
988
+ selectedSpeakerIdStorage.value = speaker.id;
989
  }
990
 
991
+ function createSpeakerCardsInModal() {
992
+ speakerGridInModal.innerHTML = '';
993
+ speakers.forEach((speaker, index) => {
994
+ const cardLabel = document.createElement('label');
995
+ cardLabel.className = 'speaker-card';
996
+ cardLabel.setAttribute('for', `modal-speaker-${speaker.id}`);
997
+ const isChecked = speaker.id === selectedSpeakerIdStorage.value ? 'checked' : '';
998
+ cardLabel.innerHTML = `
999
+ <input type="radio" name="modal_speaker_selection" value="${speaker.id}" id="modal-speaker-${speaker.id}" ${isChecked}>
1000
+ <div class="speaker-visual">
1001
+ <img src="${getImageUrl(speaker, index, 'thumb')}" alt="${speaker.name}" loading="lazy">
1002
+ <div class="speaker-name">${speaker.name}</div>
1003
+ </div>
1004
+ `;
1005
+ cardLabel.addEventListener('click', (e) => {
1006
+ if (e.target.name !== "modal_speaker_selection") {
1007
+ const radio = cardLabel.querySelector('input[type="radio"]');
1008
+ if(radio) radio.checked = true;
1009
+ }
1010
+ updateSelectedSpeakerDisplay(speaker.id);
1011
+ hideModal(speakerModal);
1012
+ });
1013
+ speakerGridInModal.appendChild(cardLabel);
1014
+ });
1015
+ }
1016
 
1017
+ // --- Modal Management ---
1018
+ function showModal(modalElement) {
1019
+ modalElement.classList.add('visible');
1020
+ setTimeout(() => {
1021
+ const firstFocusable = modalElement.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
1022
+ if (firstFocusable) firstFocusable.focus();
1023
+ }, 50);
1024
+ }
1025
 
1026
+ function hideModal(modalElement) {
1027
+ modalElement.classList.add('hiding');
1028
+ modalElement.addEventListener('animationend', () => {
1029
+ modalElement.classList.remove('visible', 'hiding');
1030
+ }, { once: true });
1031
+ }
1032
 
1033
+ // Speaker Modal Listeners
1034
+ changeSpeakerBtn.addEventListener('click', () => {
1035
+ createSpeakerCardsInModal();
1036
+ showModal(speakerModal);
1037
+ });
1038
+ selectedSpeakerCard.addEventListener('click', () => {
1039
+ createSpeakerCardsInModal();
1040
+ showModal(speakerModal);
1041
+ });
1042
+
1043
+ // Info Modal Listener
1044
+ tempInfoIcon.addEventListener('click', () => showModal(infoModal));
1045
+ tempInfoIcon.addEventListener('keydown', (e) => {
1046
+ if (e.key === 'Enter' || e.key === ' ') {
1047
+ e.preventDefault();
1048
+ showModal(infoModal);
1049
  }
1050
+ });
1051
+
1052
+ // General Modal Close Listeners (for all modals)
1053
+ document.querySelectorAll('.modal-overlay').forEach(overlay => {
1054
+ overlay.addEventListener('click', (e) => {
1055
+ if (e.target === overlay) {
1056
+ hideModal(overlay);
1057
+ }
1058
+ });
1059
+ });
1060
+ document.querySelectorAll('.close-modal-btn').forEach(button => {
1061
+ button.addEventListener('click', () => {
1062
+ const modalId = button.dataset.modalId;
1063
+ if (modalId) {
1064
+ hideModal(document.getElementById(modalId));
1065
+ }
1066
+ });
1067
+ });
1068
+ document.addEventListener('keydown', (e) => {
1069
+ if (e.key === 'Escape') {
1070
+ document.querySelectorAll('.modal-overlay.visible').forEach(hideModal);
1071
  }
1072
+ });
1073
 
1074
+ tempSlider.addEventListener('input', () => { tempValueSpan.textContent = tempSlider.value; });
1075
+
1076
+ // --- Custom Audio Player Functions ---
 
 
 
 
 
 
 
 
1077
 
1078
  function formatTime(seconds) {
1079
  if (isNaN(seconds) || seconds < 0) return '0:00';
 
1082
  return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
1083
  }
1084
 
1085
+ // Function to draw waveform on canvas
1086
+ function drawWaveform(progressRatio = 0) {
1087
+ waveformCtx.clearRect(0, 0, audioWaveformCanvas.width, audioWaveformCanvas.height); // Clear canvas
1088
+
1089
+ const barWidth = 3; // From CSS
1090
+ const barGap = 2; // Space between bars (adjust for visual appeal)
1091
+ const totalBarAndGap = barWidth + barGap;
1092
+ const numBars = Math.floor(audioWaveformCanvas.width / totalBarAndGap);
1093
+ const offset = (audioWaveformCanvas.width - (numBars * totalBarAndGap)) / 2; // Center bars
1094
+
1095
+ const activeBars = Math.floor(progressRatio * numBars);
1096
+
1097
+ for (let i = 0; i < numBars; i++) {
1098
+ const peak = audioPeaks[i] || 0; // Use actual peak or 0 if data isn't enough
1099
+ const barHeight = peak * audioWaveformCanvas.height;
1100
+
1101
+ waveformCtx.fillStyle = i < activeBars ?
1102
+ getComputedStyle(document.documentElement).getPropertyValue('--waveform-color-active').trim() :
1103
+ getComputedStyle(document.documentElement).getPropertyValue('--waveform-color-inactive').trim();
1104
+
1105
+ const x = offset + i * totalBarAndGap;
1106
+ const y = (audioWaveformCanvas.height - barHeight) / 2; // Center vertically
1107
+
1108
+ waveformCtx.fillRect(x, y, barWidth, barHeight);
1109
+ }
1110
+ }
1111
+
1112
+ // Update custom player UI (play/pause icon, time, progress)
1113
  function updatePlayerUI() {
1114
+ if (hiddenAudioPlayer.paused || hiddenAudioPlayer.ended) {
1115
+ playIcon.style.display = 'block';
1116
+ pauseIcon.style.display = 'none';
1117
+ } else {
1118
+ playIcon.style.display = 'none';
1119
+ pauseIcon.style.display = 'block';
1120
+ }
1121
+
1122
  const currentTime = hiddenAudioPlayer.currentTime;
1123
  const duration = hiddenAudioPlayer.duration;
1124
+
1125
  audioCurrentTimeSpan.textContent = formatTime(currentTime);
1126
 
1127
  if (isFinite(duration) && duration > 0) {
1128
  audioTotalTimeSpan.textContent = formatTime(duration);
1129
+ const progressRatio = currentTime / duration;
1130
+ drawWaveform(progressRatio); // Redraw waveform based on progress
 
 
1131
  } else {
1132
  audioTotalTimeSpan.textContent = '0:00';
1133
+ drawWaveform(0); // Draw empty waveform
1134
+ }
1135
+ }
1136
+
1137
+ // Process audio data for waveform visualization
1138
+ async function processAudioForWaveform(audioBuffer) {
1139
+ if (!audioBuffer) {
1140
+ audioPeaks = [];
1141
+ return;
1142
+ }
1143
+ const channelData = audioBuffer.getChannelData(0); // Get data from first channel
1144
+
1145
+ // Determine number of bars based on current canvas width
1146
+ const barWidth = 3;
1147
+ const barGap = 2;
1148
+ const totalBarAndGap = barWidth + barGap;
1149
+ const numBars = Math.floor(audioWaveformCanvas.offsetWidth / totalBarAndGap);
1150
+
1151
+ const samplesPerBar = Math.floor(channelData.length / numBars);
1152
+ const peaks = [];
1153
+
1154
+ for (let i = 0; i < numBars; i++) {
1155
+ let sum = 0;
1156
+ let maxPeak = 0;
1157
+ const start = i * samplesPerBar;
1158
+ const end = Math.min(start + samplesPerBar, channelData.length);
1159
+
1160
+ for (let j = start; j < end; j++) {
1161
+ const value = Math.abs(channelData[j]);
1162
+ sum += value;
1163
+ if (value > maxPeak) {
1164
+ maxPeak = value;
1165
+ }
1166
+ }
1167
+ // Use max peak for sharper visualization, or average for smoother
1168
+ // Clamp between 0 and 1
1169
+ peaks.push(Math.min(1, Math.max(0, maxPeak)));
1170
  }
1171
+ audioPeaks = peaks;
1172
+ drawWaveform(0); // Draw initial waveform
1173
  }
1174
+
1175
+ // Event Listeners for Custom Player Controls
1176
+ playPauseBtn.addEventListener('click', () => {
1177
+ if (hiddenAudioPlayer.paused) {
1178
+ hiddenAudioPlayer.play();
1179
+ } else {
1180
+ hiddenAudioPlayer.pause();
1181
+ }
1182
+ });
1183
+ skipBackwardBtn.addEventListener('click', () => {
1184
+ hiddenAudioPlayer.currentTime = Math.max(0, hiddenAudioPlayer.currentTime - 5);
1185
+ });
1186
+ skipForwardBtn.addEventListener('click', () => {
1187
+ hiddenAudioPlayer.currentTime = Math.min(hiddenAudioPlayer.duration, hiddenAudioPlayer.currentTime + 5);
1188
+ });
1189
+ volumeBtn.addEventListener('click', () => {
1190
+ hiddenAudioPlayer.muted = !hiddenAudioPlayer.muted;
1191
+ volumeHighIcon.style.display = hiddenAudioPlayer.muted ? 'none' : 'block';
1192
+ volumeMuteIcon.style.display = hiddenAudioPlayer.muted ? 'block' : 'none';
1193
+ });
1194
+ speedBtn.addEventListener('click', () => {
1195
+ currentPlaybackSpeedIndex = (currentPlaybackSpeedIndex + 1) % playbackSpeeds.length;
1196
+ const newSpeed = playbackSpeeds[currentPlaybackSpeedIndex];
1197
+ hiddenAudioPlayer.playbackRate = newSpeed;
1198
+ speedBtn.textContent = `${newSpeed}x`;
1199
+ });
1200
+
1201
+ hiddenAudioPlayer.addEventListener('timeupdate', updatePlayerUI);
1202
+ hiddenAudioPlayer.addEventListener('loadedmetadata', async () => {
1203
+ // Ensure AudioContext is available
1204
+ if (!audioContext) {
1205
+ audioContext = new (window.AudioContext || window.webkitAudioContext)();
1206
+ }
1207
+ // Fetch and decode audio to get waveform data
1208
+ try {
1209
+ const response = await fetch(hiddenAudioPlayer.src);
1210
+ const arrayBuffer = await response.arrayBuffer();
1211
+ const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
1212
+
1213
+ // Set canvas dimensions
1214
+ audioWaveformCanvas.width = audioWaveformCanvas.offsetWidth;
1215
+ audioWaveformCanvas.height = audioWaveformCanvas.offsetHeight;
1216
+
1217
+ await processAudioForWaveform(audioBuffer);
1218
+ } catch (e) {
1219
+ console.error("Error decoding audio for waveform:", e);
1220
+ audioPeaks = []; // Clear peaks on error
1221
+ }
1222
+ updatePlayerUI(); // Update UI with total duration and initial state
1223
+ });
1224
+ hiddenAudioPlayer.addEventListener('play', updatePlayerUI);
1225
+ hiddenAudioPlayer.addEventListener('pause', updatePlayerUI);
1226
+ hiddenAudioPlayer.addEventListener('ended', () => {
1227
+ hiddenAudioPlayer.currentTime = 0;
1228
+ updatePlayerUI();
1229
+ });
1230
+
1231
+ // Handle window resize for responsive waveform
1232
+ let resizeTimeout;
1233
+ window.addEventListener('resize', () => {
1234
+ clearTimeout(resizeTimeout);
1235
+ resizeTimeout = setTimeout(() => {
1236
+ if (outputSection.classList.contains('has-content') && hiddenAudioPlayer.src) {
1237
+ // Re-process audio buffer on resize to adjust number of bars
1238
+ // This assumes the audio buffer is still in memory or re-fetches it.
1239
+ // A more efficient way for real apps might be to store the AudioBuffer.
1240
+ // For simplicity here, we trigger the loadedmetadata logic again.
1241
+ hiddenAudioPlayer.dispatchEvent(new Event('loadedmetadata'));
1242
+ }
1243
+ }, 250); // Debounce resize events
1244
  });
1245
 
1246
 
1247
+ // --- State Management Functions ---
1248
+ function showLoadingState() {
1249
+ audioPlayerContent.style.display = 'none';
1250
+ outputSection.classList.remove('has-content');
1251
+ statusMessage.style.display = 'none'; // Hide initial message
1252
+ loadingAnimationWrapper.style.display = 'flex';
1253
+ generateBtn.disabled = true;
1254
+ generateBtn.innerHTML = `
1255
+ <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;">
1256
+ <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"/>
1257
+ <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"/>
1258
+ </svg>
1259
+ در حال پردازش...
1260
+ `;
1261
+ }
1262
 
1263
+ function showResultState(isSuccess, message = '') {
1264
  loadingAnimationWrapper.style.display = 'none';
1265
+ if (isSuccess) {
1266
  statusMessage.style.display = 'none';
1267
  audioPlayerContent.style.display = 'flex';
1268
  outputSection.classList.add('has-content');
1269
+ // Play is triggered by loadedmetadata listener after waveform processing
 
 
 
 
1270
  } else {
1271
+ statusMessage.textContent = message || 'خطایی رخ داد. لطفاً دوباره ت��اش کنید.';
1272
+ statusMessage.style.display = 'block';
1273
+ audioPlayerContent.style.display = 'none';
1274
+ outputSection.classList.remove('has-content');
1275
+ hiddenAudioPlayer.pause();
1276
+ hiddenAudioPlayer.src = '';
1277
+ audioPeaks = []; // Clear waveform data
1278
+ drawWaveform(0); // Clear canvas
1279
  }
1280
+ generateBtn.disabled = false;
1281
+ generateBtn.innerHTML = '✨ تولید صدا با آلفا';
1282
  }
 
 
 
 
1283
 
 
1284
  async function generateAudio(event) {
1285
+ event.preventDefault();
1286
+ showLoadingState();
1287
+
1288
+ const text = textInput.value;
1289
+ if (!text.trim()) {
1290
+ showResultState(false, 'خطا: متن ورودی نمی‌تواند خالی باشد.');
1291
+ return;
1292
+ }
1293
+ if (text.length > MAX_CHARS) {
1294
+ showResultState(false, `خطا: طول متن بیش از ${MAX_CHARS.toLocaleString('fa-IR')} نویسه است.`);
1295
+ return;
1296
+ }
1297
+
1298
+ const promptVal = promptInput.value;
1299
+ const temperatureVal = parseFloat(tempSlider.value);
1300
+ const selectedSpeakerVal = selectedSpeakerIdStorage.value;
1301
+ const sessionHash = Math.random().toString(36).substring(2);
1302
+
1303
+ const payload = {
1304
+ fn_index: FN_INDEX,
1305
+ data: [false, null, text, promptVal, selectedSpeakerVal, temperatureVal],
1306
+ event_data: null,
1307
+ session_hash: sessionHash
1308
+ };
1309
+
1310
+ try {
1311
+ const joinQueueResponse = await fetch(JOIN_QUEUE_URL, {
1312
+ method: "POST",
1313
+ headers: { "Content-Type": "application/json" },
1314
+ body: JSON.stringify(payload)
1315
+ });
1316
+
1317
+ if (!joinQueueResponse.ok) {
1318
+ const errorBody = await joinQueueResponse.text();
1319
+ console.error("Join Queue Error Body:", errorBody);
1320
+ throw new Error(`خطا در برقراری ارتباط با سرویس آلفا (${joinQueueResponse.status}). لطفا لحظاتی دیگر تلاش کنید.`);
1321
+ }
1322
+
1323
+ let finalFilePath = null;
1324
+ const startTime = Date.now();
1325
+ const timeoutDuration = 90000;
1326
+
1327
+ while (Date.now() - startTime < timeoutDuration) {
1328
+ const dataResponse = await fetch(`${GET_DATA_URL_BASE}?session_hash=${sessionHash}`);
1329
+ if (!dataResponse.ok) {
1330
+ const errorBody = await dataResponse.text();
1331
+ console.error("Get Data Error Body:", errorBody);
1332
+ throw new Error(`خطا در دریافت داده از سرویس (${dataResponse.status})`);
1333
+ }
1334
+
1335
+ const responseText = await dataResponse.text();
1336
+ const lines = responseText.trim().split('\n');
1337
+
1338
+ for (const line of lines) {
1339
+ if (!line.startsWith('data:')) continue;
1340
+ try {
1341
+ const data = JSON.parse(line.substring(5));
1342
+ if (data.msg === 'process_generating' || data.msg === 'process_starts') {
1343
+ // console.log("Processing:", data.output?.progress_data?.[0]?.desc || data.msg);
1344
+ } else if (data.msg === 'process_completed') {
1345
+ if (data.success && data.output.data && data.output.data[0] && (data.output.data[0].name || data.output.data[0].path)) {
1346
+ finalFilePath = data.output.data[0].name || data.output.data[0].path;
1347
+ } else {
1348
+ console.error("Invalid server response structure or unsuccessful processing:", data);
1349
+ throw new Error(data.output?.error || 'خطای ناشناخته در پردازش سرور.');
1350
+ }
1351
+ break;
1352
+ } else if (data.msg === 'queue_full') {
1353
+ throw new Error('صف پردازش پر است. لطفا کمی بعد تلاش کنید.');
1354
+ }
1355
+ } catch (e) {
1356
+ console.warn("Error parsing JSON from stream:", e, "Line:", line);
1357
+ }
1358
+ }
1359
+ if (finalFilePath) break;
1360
+ await new Promise(resolve => setTimeout(resolve, 1000));
1361
+ }
1362
+
1363
+ if (finalFilePath) {
1364
+ const audioUrl = `${FILE_URL_BASE}${finalFilePath}`;
1365
+ hiddenAudioPlayer.src = audioUrl;
1366
+ showResultState(true);
1367
+ } else if (Date.now() - startTime >= timeoutDuration) {
1368
+ throw new Error('پردازش بیش از حد طول کشید و متوقف شد.');
1369
+ } else {
1370
+ throw new Error('فایل صوتی از سرور دریافت نشد یا پردازش ناموفق بود.');
1371
+ }
1372
+
1373
+ } catch (error) {
1374
+ console.error('خطا در فرآیند تولید صدا:', error);
1375
+ showResultState(false, `${error.message}`);
1376
+ }
1377
  }
1378
 
1379
+ // Initial setup
1380
+ updateSelectedSpeakerDisplay(selectedSpeakerIdStorage.value || speakers[0].id);
1381
+ form.addEventListener('submit', generateAudio);
1382
+ statusMessage.style.display = 'block';
1383
+ loadingAnimationWrapper.style.display = 'none';
1384
+ audioPlayerContent.style.display = 'none';
1385
+ outputSection.classList.remove('has-content');
1386
  });
1387
  </script>
1388
  </body>