From 337f7f3017ea0f4134606564ceb39efa80603a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Fri, 22 May 2026 21:37:10 +0400 Subject: [PATCH] =?UTF-8?q?v76:=20=D0=BF=D1=80=D0=BE=D0=B8=D0=B3=D1=80?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=20trimSilence=20=E2=80=94=20=D0=B1=D0=B5=D0=B7=20=D1=89?= =?UTF-8?q?=D0=B5=D0=BB=D1=87=D0=BA=D0=B0=20=D0=B2=20=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/index.html | 46 +++++++++++++++++++++++++--------------------- js/audio.js | 31 +++++++++++++++++++++---------- js/main.js | 15 ++++----------- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/dist/index.html b/dist/index.html index 074bfc1..c1061ac 100644 --- a/dist/index.html +++ b/dist/index.html @@ -392,22 +392,33 @@ function stopRecording() { if (mediaRecorder && mediaRecorder.state === 'recording') mediaRecorder.stop(); } -// ---------- Воспроизведение ---------- +// ---------- Воспроизведение (с обрезкой тишины) ---------- +async function playTrimmed(blob) { + const t = await trimSilence(blob); + const ctx = 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 src = ctx.createBufferSource(); + src.buffer = buf; + src.connect(ctx.destination); + src.start(); + return new Promise(resolve => { src.onended = resolve; }); +} + async function playRec(id) { try { const db = await openRecDB(); const tx = db.transaction('recs', 'readonly'); const store = tx.objectStore('recs'); const rec = await new Promise(r => { const req = store.get(id); req.onsuccess = () => r(req.result); }); - if (rec?.blob) { - const url = URL.createObjectURL(rec.blob); - const audio = new Audio(url); - await new Promise((resolve, reject) => { - audio.onended = () => { URL.revokeObjectURL(url); resolve(); }; - audio.onerror = () => { URL.revokeObjectURL(url); reject(); }; - audio.play(); - }); - } + if (rec?.blob) await playTrimmed(rec.blob); } catch(e) { /* тихо */ } } @@ -733,7 +744,7 @@ async function doCompare(blob, originalText, duration) {