amauricunha commited on
Commit
31d7049
·
verified ·
1 Parent(s): 397925c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +75 -2
index.html CHANGED
@@ -58,7 +58,8 @@
58
  <div class="card">
59
  <h2 class="text-xl font-semibold mb-4 text-gray-700">Seu Texto de Estudo</h2>
60
  <div id="textEditor" contenteditable="true" spellcheck="true" lang="en" class="w-full p-4 focus:ring-2 focus:ring-indigo-500 text-gray-800"></div>
61
- <p class="text-sm text-right text-gray-500 mt-2">Caracteres: <span id="charCount">0</span>/5000</p>
 
62
  <div class="mt-4 border-t pt-4">
63
  <button id="createCardButton" onclick="createFlashcardFromSelection()" class="btn btn-success disabled:opacity-50" disabled>+ Criar Flashcard da Seleção</button>
64
  </div>
@@ -84,6 +85,13 @@
84
  </select>
85
  </div>
86
  </div>
 
 
 
 
 
 
 
87
  <div class="mt-4">
88
  <audio id="audioPlayer" controls class="w-full"></audio>
89
  </div>
@@ -141,12 +149,76 @@
141
  const activityOutput = document.getElementById('activityOutput');
142
  const activitySpinner = document.getElementById('activitySpinner');
143
  const activityText = document.getElementById('activityText');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
- // --- LÓGICA DO EDITOR E SELEÇÃO ---
146
  textEditor.addEventListener('mouseup', () => {
147
  const selection = window.getSelection().toString().trim();
148
  createCardButton.disabled = !selection;
149
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  // --- GERAÇÃO DE FLASHCARD INTELIGENTE ---
152
  async function createFlashcardFromSelection() {
@@ -334,3 +406,4 @@
334
 
335
  </body>
336
  </html>
 
 
58
  <div class="card">
59
  <h2 class="text-xl font-semibold mb-4 text-gray-700">Seu Texto de Estudo</h2>
60
  <div id="textEditor" contenteditable="true" spellcheck="true" lang="en" class="w-full p-4 focus:ring-2 focus:ring-indigo-500 text-gray-800"></div>
61
+ <!-- CONTADOR DE CARACTERES ATUALIZADO -->
62
+ <p class="text-sm text-right text-gray-500 mt-2">Caracteres: <span id="charCount">0</span>/10000</p>
63
  <div class="mt-4 border-t pt-4">
64
  <button id="createCardButton" onclick="createFlashcardFromSelection()" class="btn btn-success disabled:opacity-50" disabled>+ Criar Flashcard da Seleção</button>
65
  </div>
 
85
  </select>
86
  </div>
87
  </div>
88
+ <!-- BOTÃO PRINCIPAL DE ÁUDIO RE-ADICIONADO -->
89
+ <div class="mt-4">
90
+ <button id="playButton" onclick="handlePlay()" class="btn btn-primary w-full py-2.5 flex items-center justify-center disabled:opacity-50" disabled>
91
+ <span id="playText">Gerar e Tocar Áudio do Texto</span>
92
+ <div id="loadingSpinner" class="spinner ml-3 hidden"></div>
93
+ </button>
94
+ </div>
95
  <div class="mt-4">
96
  <audio id="audioPlayer" controls class="w-full"></audio>
97
  </div>
 
149
  const activityOutput = document.getElementById('activityOutput');
150
  const activitySpinner = document.getElementById('activitySpinner');
151
  const activityText = document.getElementById('activityText');
152
+
153
+ // --- ELEMENTOS DE ÁUDIO RE-ADICIONADOS ---
154
+ const playButton = document.getElementById('playButton');
155
+ const audioPlayer = document.getElementById('audioPlayer');
156
+ const charCount = document.getElementById('charCount');
157
+ const loadingSpinner = document.getElementById('loadingSpinner');
158
+ const playText = document.getElementById('playText');
159
+ const MAX_CHARS = 10000; // Limite de caracteres restaurado
160
+ let lastAudioUrl = '';
161
+
162
+ // --- LÓGICA DO EDITOR, SELEÇÃO E CONTAGEM DE CARACTERES ---
163
+ textEditor.addEventListener('input', () => {
164
+ const currentLength = textEditor.innerText.length;
165
+ charCount.textContent = `${currentLength}/${MAX_CHARS}`;
166
+ playButton.disabled = currentLength === 0 || currentLength > MAX_CHARS;
167
+
168
+ if (currentLength > MAX_CHARS) {
169
+ charCount.classList.add('text-red-600');
170
+ } else {
171
+ charCount.classList.remove('text-red-600');
172
+ }
173
+ });
174
 
 
175
  textEditor.addEventListener('mouseup', () => {
176
  const selection = window.getSelection().toString().trim();
177
  createCardButton.disabled = !selection;
178
  });
179
+
180
+ // --- FUNÇÕES DE ÁUDIO DO TEXTO PRINCIPAL (RE-ADICIONADAS) ---
181
+ async function fetchAudio(text) {
182
+ playButton.disabled = true;
183
+ playText.textContent = "Gerando Áudio...";
184
+ loadingSpinner.classList.remove('hidden');
185
+
186
+ try {
187
+ const response = await fetch('/tts-proxy', {
188
+ method: 'POST',
189
+ headers: { 'Content-Type': 'application/json' },
190
+ body: JSON.stringify({ text: text })
191
+ });
192
+
193
+ if (!response.ok) {
194
+ throw new Error(`Erro HTTP: ${response.status}`);
195
+ }
196
+
197
+ const audioBlob = await response.blob();
198
+
199
+ if (lastAudioUrl) URL.revokeObjectURL(lastAudioUrl);
200
+
201
+ lastAudioUrl = URL.createObjectURL(audioBlob);
202
+ audioPlayer.src = lastAudioUrl;
203
+ audioPlayer.play();
204
+
205
+ } catch (error) {
206
+ console.error('Erro ao gerar áudio:', error);
207
+ alert('Falha ao gerar o áudio. Verifique o console para mais detalhes.');
208
+ } finally {
209
+ playButton.disabled = false;
210
+ playText.textContent = "Gerar e Tocar Áudio do Texto";
211
+ loadingSpinner.classList.add('hidden');
212
+ }
213
+ }
214
+
215
+ function handlePlay() {
216
+ const textToPlay = textEditor.innerText.trim();
217
+ if (textToPlay) {
218
+ fetchAudio(textToPlay);
219
+ }
220
+ }
221
+
222
 
223
  // --- GERAÇÃO DE FLASHCARD INTELIGENTE ---
224
  async function createFlashcardFromSelection() {
 
406
 
407
  </body>
408
  </html>
409
+