From 0f24cf5ec91474456d9989c10b2cea1a584f66ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 23 May 2026 06:13:46 +0400 Subject: [PATCH] =?UTF-8?q?v80:=20=D0=BE=D0=B1=D1=80=D0=B5=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=200.2=D1=81=20=D0=B2=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8=20=E2=80=94=20?= =?UTF-8?q?=D1=83=D0=B1=D0=B8=D1=80=D0=B0=D0=B5=D1=82=20=D1=89=D0=B5=D0=BB?= =?UTF-8?q?=D1=87=D0=BE=D0=BA=20(=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20tr?= =?UTF-8?q?imSilence)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- js/audio.js | 50 ++++++++++++++++++++++++++++++++++++------------ js/main.js | 2 +- js/transcribe.js | 7 +++++-- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/index.html b/index.html index 7416e03..6f42bfc 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@

🇮🇹 Lyngvo тренажёр итальянского произношения · для Google Chrome

- 1. Введите фразу  →  2. ▶ Эталон (прослушайте)  →  3. 🎙 Записать (произнесите)  →  4. 📊 Сравнить + 1. Введите фразу  →  2. ▶ Эталон (прослушайте)  →  3. 🎙 Записать (сделайте короткую паузу перед произнесением)  →  4. 📊 Сравнить
diff --git a/js/audio.js b/js/audio.js index 590c77b..6661997 100644 --- a/js/audio.js +++ b/js/audio.js @@ -90,23 +90,20 @@ function stopRecording() { if (mediaRecorder && mediaRecorder.state === 'recording') mediaRecorder.stop(); } -// ---------- Воспроизведение (с обрезкой тишины) ---------- +// ---------- Воспроизведение (с обрезкой 0.2с в начале) ---------- async function playTrimmed(blob) { - const t = await trimSilence(blob); const ctx = await getAudioCtx(); - let buf; - if (t) { - const offline = new OfflineAudioContext(1, t.data.length, t.sr); - buf = offline.createBuffer(1, t.data.length, t.sr); - buf.getChannelData(0).set(t.data); - } else { - const ab = await blob.arrayBuffer(); - buf = await ctx.decodeAudioData(ab); - } + const ab = await blob.arrayBuffer(); + const rawBuf = await ctx.decodeAudioData(ab); + const sr = rawBuf.sampleRate; + const data = rawBuf.getChannelData(0); + const cutSamples = Math.floor(sr * 0.2); + const trimmed = data.slice(cutSamples); + const buf = ctx.createBuffer(1, trimmed.length, sr); + buf.getChannelData(0).set(trimmed); const src = ctx.createBufferSource(); src.buffer = buf; const gain = ctx.createGain(); - // Fade-in 10мс — убирает щелчок при старте gain.gain.setValueAtTime(0, ctx.currentTime); gain.gain.linearRampToValueAtTime(1, ctx.currentTime + 0.01); src.connect(gain).connect(ctx.destination); @@ -305,3 +302,32 @@ async function trimSilence(blob) { return { buffer: trimmedBuf, data: data.slice(startSample, endSample), sr, startSample, endSample }; } catch(e) { return null; } } + +// ---------- WAV кодирование (для отправки в Whisper) ---------- +function encodeWAV(samples, sampleRate) { + const buf = new ArrayBuffer(44 + samples.length * 2); + const v = new DataView(buf); + const w = (o, s) => { for (let i=0;i