From 8f8a21bbcc03e7120f72effc6f4ee02d217faffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Fri, 22 May 2026 17:01:30 +0400 Subject: [PATCH] =?UTF-8?q?v48:=20WS=20=E2=80=94=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=20JSON=20=D1=81=20base64,=20=D0=B1=D0=B5=D0=B7=20=D1=87?= =?UTF-8?q?=D0=B0=D0=BD=D0=BA=D0=BE=D0=B2,=20=D0=B1=D0=B5=D0=B7=20=D0=B1?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D1=80=D0=BD=D1=8B=D1=85=20=D1=84=D1=80=D0=B5?= =?UTF-8?q?=D0=B9=D0=BC=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index c35ddf7..9126097 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 = 'v47'; +const VERSION = 'v48'; document.getElementById('ver').textContent = VERSION; // ---------- Перевод на русский (Groq) ---------- @@ -612,7 +612,7 @@ async function transcribe(blob) { if (!GROQ_API_KEY) return { text: '', error: 'no_key' }; const tStart = performance.now(); - // Кодируем в base64 — только текстовые WS-фреймы, DPI не режет + // Кодируем blob в base64 (только текстовые WS-фреймы — DPI не режет) const base64 = await new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(reader.result.split(',')[1]); @@ -620,9 +620,7 @@ async function transcribe(blob) { reader.readAsDataURL(blob); }); - const CHUNK = 4096; // 4KB на чанк - const total = Math.ceil(base64.length / CHUNK); - console.log('[WS] blob=' + (blob.size/1024).toFixed(1) + 'KB b64=' + base64.length + ' chunks=' + total); + console.log('[WS] b64=' + (base64.length/1024).toFixed(1) + 'KB'); return new Promise((resolve) => { try { @@ -632,26 +630,18 @@ async function transcribe(blob) { }, 60000); ws.onopen = () => { - console.log('[WS] connected, chunks=' + total); - ws.send(JSON.stringify({ token: GROQ_API_KEY, total, mime: blob.type || 'audio/webm' })); - for (let i = 0; i < base64.length; i += CHUNK) { - ws.send(JSON.stringify({ chunk: base64.slice(i, i + CHUNK) })); - } - console.log('[WS] all sent'); + ws.send(JSON.stringify({ token: GROQ_API_KEY, audio_b64: base64, mime: blob.type || 'audio/webm' })); + console.log('[WS] sent'); }; ws.onmessage = (e) => { - clearTimeout(timeout); - ws.close(); + clearTimeout(timeout); ws.close(); const data = JSON.parse(e.data); - console.log('[WHISPER] ' + (blob.size/1024).toFixed(1) + 'KB ws-b64 ' + ((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 }); + console.log('[WS] ← ' + ((performance.now()-tStart)/1000).toFixed(2) + 's → ' + (data.text||'(empty)')); + resolve(data.error ? { text: '', error: data.error } : { text: data.text || '', error: null }); }; - ws.onerror = () => { - console.log('[WS] error'); clearTimeout(timeout); resolve({ text: '', error: 'network' }); - }; + ws.onerror = () => { clearTimeout(timeout); resolve({ text: '', error: 'network' }); }; } catch (err) { resolve({ text: '', error: 'network' }); }