Spaces:
Running
Running
Update js/recordingModule.js
Browse files- js/recordingModule.js +42 -12
js/recordingModule.js
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
// js/recordingModule.js
|
| 2 |
|
| 3 |
-
|
|
|
|
| 4 |
let mediaRecorder, audioChunks = [], transcriptText = '';
|
| 5 |
|
| 6 |
-
// Listener para el bot贸n Iniciar (
|
| 7 |
btnStart.addEventListener('click', async () => {
|
| 8 |
console.log('[Recorder] Bot贸n Iniciar pulsado');
|
| 9 |
|
| 10 |
-
// --- INICIO: Limpieza
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
const aiProviderUrl = getProvider();
|
| 17 |
if (!aiProviderUrl) {
|
|
@@ -58,7 +71,7 @@ export function initRecorder({ btnStart, btnStop, transcriptEl, getProvider }) {
|
|
| 58 |
}
|
| 59 |
});
|
| 60 |
|
| 61 |
-
// --- INICIO: Funci贸n onStop (Sin cambios
|
| 62 |
async function onStop() {
|
| 63 |
console.log('[Recorder] Grabaci贸n detenida (onStop), procesando audio...');
|
| 64 |
if (audioChunks.length === 0) {
|
|
@@ -77,7 +90,7 @@ export function initRecorder({ btnStart, btnStop, transcriptEl, getProvider }) {
|
|
| 77 |
const transProvider = cfg.transcription.provider;
|
| 78 |
const apiKey = cfg.transcription.apiKeys[transProvider];
|
| 79 |
const transModel = cfg.transcription.models[transProvider];
|
| 80 |
-
const providerBaseUrl = getProvider();
|
| 81 |
if (!apiKey) {
|
| 82 |
alert(`API Key para ${transProvider} no encontrada.`);
|
| 83 |
const status = document.getElementById('recorder-status'); if(status) status.innerHTML = `<i class="fas fa-exclamation-circle text-red-500 mr-2"></i>Falta API Key (${transProvider}).`;
|
|
@@ -119,9 +132,9 @@ export function initRecorder({ btnStart, btnStop, transcriptEl, getProvider }) {
|
|
| 119 |
} else { throw new Error(`Proveedor de transcripci贸n no soportado: ${transProvider}`); }
|
| 120 |
|
| 121 |
// Actualizar UI y disparar evento (ESTA L脥NEA SIGUE ACTIVA)
|
| 122 |
-
transcriptEl.value = transcript;
|
| 123 |
document.dispatchEvent(new CustomEvent('transcriptionReady', { detail: transcript }));
|
| 124 |
-
console.log("[Recorder] Evento 'transcriptionReady' DESPACHADO con detalle:", { detail: transcript });
|
| 125 |
|
| 126 |
} catch (e) {
|
| 127 |
console.error('[Recorder] Error durante la llamada API de transcripci贸n:', e);
|
|
@@ -134,7 +147,24 @@ export function initRecorder({ btnStart, btnStop, transcriptEl, getProvider }) {
|
|
| 134 |
const statusElement = document.getElementById('recorder-status');
|
| 135 |
if (statusElement && !statusElement.innerHTML.includes('Error')) {
|
| 136 |
statusElement.innerHTML = '<i class="fas fa-check-circle text-green-500 mr-2"></i>Transcripci贸n lista.';
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
}
|
| 140 |
}
|
|
|
|
| 1 |
// js/recordingModule.js
|
| 2 |
|
| 3 |
+
// Modificamos la firma para aceptar el nuevo callback
|
| 4 |
+
export function initRecorder({ btnStart, btnStop, transcriptEl, getProvider, clearFieldsCallback }) {
|
| 5 |
let mediaRecorder, audioChunks = [], transcriptText = '';
|
| 6 |
|
| 7 |
+
// Listener para el bot贸n Iniciar (MODIFICADO para usar el callback)
|
| 8 |
btnStart.addEventListener('click', async () => {
|
| 9 |
console.log('[Recorder] Bot贸n Iniciar pulsado');
|
| 10 |
|
| 11 |
+
// --- INICIO: Limpieza usando Callback ---
|
| 12 |
+
if (typeof clearFieldsCallback === 'function') {
|
| 13 |
+
console.log('[Recorder] Llamando a clearFieldsCallback...');
|
| 14 |
+
try {
|
| 15 |
+
clearFieldsCallback(); // <-- LLAMADA AL CALLBACK
|
| 16 |
+
} catch (error) {
|
| 17 |
+
console.error('[Recorder] Error al ejecutar clearFieldsCallback:', error);
|
| 18 |
+
}
|
| 19 |
+
} else {
|
| 20 |
+
console.warn('[Recorder] clearFieldsCallback no fue proporcionado o no es una funci贸n.');
|
| 21 |
+
// Opcionalmente, limpiar al menos la transcripci贸n aqu铆 como fallback
|
| 22 |
+
if (transcriptEl) transcriptEl.value = ''; // Fallback si no hay callback
|
| 23 |
+
}
|
| 24 |
+
// --- FIN: Limpieza usando Callback ---
|
| 25 |
+
|
| 26 |
+
// Ya no se necesitan las l铆neas de evento y log desactivado
|
| 27 |
+
// console.log('[Recorder] Evento newRecordingStarted DESACTIVADO TEMPORALMENTE'); // Eliminado
|
| 28 |
|
| 29 |
const aiProviderUrl = getProvider();
|
| 30 |
if (!aiProviderUrl) {
|
|
|
|
| 71 |
}
|
| 72 |
});
|
| 73 |
|
| 74 |
+
// --- INICIO: Funci贸n onStop (Sin cambios en su l贸gica interna) ---
|
| 75 |
async function onStop() {
|
| 76 |
console.log('[Recorder] Grabaci贸n detenida (onStop), procesando audio...');
|
| 77 |
if (audioChunks.length === 0) {
|
|
|
|
| 90 |
const transProvider = cfg.transcription.provider;
|
| 91 |
const apiKey = cfg.transcription.apiKeys[transProvider];
|
| 92 |
const transModel = cfg.transcription.models[transProvider];
|
| 93 |
+
const providerBaseUrl = getProvider(); // Llama a la funci贸n pasada desde main.js
|
| 94 |
if (!apiKey) {
|
| 95 |
alert(`API Key para ${transProvider} no encontrada.`);
|
| 96 |
const status = document.getElementById('recorder-status'); if(status) status.innerHTML = `<i class="fas fa-exclamation-circle text-red-500 mr-2"></i>Falta API Key (${transProvider}).`;
|
|
|
|
| 132 |
} else { throw new Error(`Proveedor de transcripci贸n no soportado: ${transProvider}`); }
|
| 133 |
|
| 134 |
// Actualizar UI y disparar evento (ESTA L脥NEA SIGUE ACTIVA)
|
| 135 |
+
if (transcriptEl) transcriptEl.value = transcript; // Asegurarse que transcriptEl existe
|
| 136 |
document.dispatchEvent(new CustomEvent('transcriptionReady', { detail: transcript }));
|
| 137 |
+
console.log("[Recorder] Evento 'transcriptionReady' DESPACHADO con detalle:", { detail: transcript });
|
| 138 |
|
| 139 |
} catch (e) {
|
| 140 |
console.error('[Recorder] Error durante la llamada API de transcripci贸n:', e);
|
|
|
|
| 147 |
const statusElement = document.getElementById('recorder-status');
|
| 148 |
if (statusElement && !statusElement.innerHTML.includes('Error')) {
|
| 149 |
statusElement.innerHTML = '<i class="fas fa-check-circle text-green-500 mr-2"></i>Transcripci贸n lista.';
|
| 150 |
+
// Actualizar estado despu茅s de un tiempo si sigue en "lista"
|
| 151 |
+
setTimeout(() => {
|
| 152 |
+
const currentStatusElement = document.getElementById('recorder-status');
|
| 153 |
+
if(currentStatusElement && currentStatusElement.innerHTML.includes('lista')) {
|
| 154 |
+
currentStatusElement.innerHTML = '<i class="fas fa-circle text-gray-400 mr-2"></i>No hay consulta en progreso';
|
| 155 |
+
}
|
| 156 |
+
}, 4000);
|
| 157 |
+
} else if (statusElement && statusElement.innerHTML.includes('Error')) {
|
| 158 |
+
// Si hubo error, dejar el mensaje de error por un tiempo y luego resetear
|
| 159 |
+
setTimeout(() => {
|
| 160 |
+
const currentStatusElement = document.getElementById('recorder-status');
|
| 161 |
+
if(currentStatusElement && currentStatusElement.innerHTML.includes('Error')) {
|
| 162 |
+
currentStatusElement.innerHTML = '<i class="fas fa-circle text-gray-400 mr-2"></i>No hay consulta en progreso';
|
| 163 |
+
}
|
| 164 |
+
}, 5000); // Un poco m谩s de tiempo para leer el error
|
| 165 |
+
} else if (statusElement) {
|
| 166 |
+
// Si no hubo error pero tampoco est谩 'lista' (caso raro, ej. no audio chunks), resetear
|
| 167 |
+
statusElement.innerHTML = '<i class="fas fa-circle text-gray-400 mr-2"></i>No hay consulta en progreso';
|
| 168 |
}
|
| 169 |
}
|
| 170 |
}
|