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