diff --git a/index.html b/index.html index 67cf52f..32e420b 100644 --- a/index.html +++ b/index.html @@ -53,7 +53,7 @@ let mediaRecorder, audioChunks = [], userAudioBlob = null, ttsText = ''; let isRecording = false, isAnalyzing = false, micAnalyser = null, micAnimId = null; let recordStartTime = 0, recordDuration = 0; // ---------- Версия ---------- -const VERSION = 'v44'; +const VERSION = 'v45'; document.getElementById('ver').textContent = VERSION; // ---------- Перевод на русский (Groq) ---------- @@ -608,8 +608,6 @@ document.getElementById('btnPlayUser').onclick = async () => { } }; -const CHUNK_SIZE = 4096; - async function transcribe(blob) { if (!GROQ_API_KEY) return { text: '', error: 'no_key' }; const tStart = performance.now(); @@ -637,33 +635,31 @@ async function transcribe(blob) { } } - // Large file: WebSocket - const total = Math.ceil(blob.size / CHUNK_SIZE); + // Large file: WebSocket (entire blob, no chunks) + console.log('[WS] opening, blob=' + (blob.size/1024).toFixed(1) + 'KB'); return new Promise((resolve) => { try { const ws = new WebSocket('wss://proxy.kube5s.ru/ws'); - const timeout = setTimeout(() => { ws.close(); resolve({ text: '', error: 'timeout' }); }, 60000); + const timeout = setTimeout(() => { console.log('[WS] timeout'); ws.close(); resolve({ text: '', error: 'timeout' }); }, 60000); - ws.onopen = () => { - ws.send(JSON.stringify({ token: GROQ_API_KEY, chunks: total })); - (async () => { - for (let i = 0; i < total; i++) { - const chunk = blob.slice(i * CHUNK_SIZE, Math.min((i + 1) * CHUNK_SIZE, blob.size)); - ws.send(await chunk.arrayBuffer()); - } - })(); + ws.onopen = async () => { + console.log('[WS] connected'); + ws.send(JSON.stringify({ token: GROQ_API_KEY })); + ws.send(await blob.arrayBuffer()); + console.log('[WS] blob sent'); }; ws.onmessage = (e) => { clearTimeout(timeout); ws.close(); const data = JSON.parse(e.data); - console.log('[WHISPER] ' + (blob.size/1024).toFixed(1) + 'KB ws/' + total + 'chunks ' + ((performance.now()-tStart)/1000).toFixed(2) + 's → ' + (data.text||'(empty)')); + console.log('[WHISPER] ' + (blob.size/1024).toFixed(1) + 'KB ws ' + ((performance.now()-tStart)/1000).toFixed(2) + 's → ' + (data.text||'(empty)')); if (data.error) resolve({ text: '', error: data.error }); else resolve({ text: data.text || '', error: null }); }; ws.onerror = () => { + console.log('[WS] error'); clearTimeout(timeout); resolve({ text: '', error: 'network' }); };