create-pmos 0.115.0 → 0.116.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/guide/notes.md +2 -0
- package/workspace/lib/audio-resample.js +76 -0
- package/workspace/lib/notes-audio.js +62 -20
- package/workspace/lib/notes-echo.js +32 -14
- package/workspace/lib/notes-hires.js +94 -0
- package/workspace/lib/notes-polish.js +2 -3
- package/workspace/lib/routes-notes.js +9 -1
- package/workspace/notes-test-signals.js +65 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/audio-capture.js +20 -6
- package/workspace/public/pm/view-notes.js +15 -4
- package/workspace/test-lists/meeting-notes.json +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.116.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
package/payload/KIT-VERSION
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Eval calibration log"
|
|
4
4
|
description: "Append-only record of every PM override of an evaluator verdict."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-08T06:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-08T06:17:49Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-08T06:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-08T06:17:49Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-10-08T06:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-08T06:17:49Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/guide/notes.md
CHANGED
|
@@ -132,6 +132,8 @@ When a meeting was heard with local transcription, its audio is kept on this mac
|
|
|
132
132
|
|
|
133
133
|
When you listened to both your microphone and the meeting, the workspace removes the meeting's echo from your microphone after you press **Stop**. A speaker plays the meeting, your microphone hears it a second time, and this second copy is the echo. The workspace uses the meeting's own recording as the guide. This takes a few minutes for each hour of meeting. It runs in the background, and the replay changes when it is done. Your own voice stays, because it is not in the meeting's recording. A part of the meeting where the clean-up would not help stays as it was recorded. The transcript does not change, because it is made from each source on its own. Headphones are still the best fix, because they stop the echo at its source.
|
|
134
134
|
|
|
135
|
+
The replay of a new note is kept at 24 kHz, so it keeps the high sounds of a voice that a 16 kHz file loses. The transcript is still made from 16 kHz audio, as before. A note you recorded before this change keeps its 16 kHz replay and plays as it did. The 24 kHz file is about 173 MB for each hour, and the workspace deletes it with the note's audio.
|
|
136
|
+
|
|
135
137
|
The replay is your microphone and the meeting added together. When both are loud at the same moment, the workspace lowers the peaks softly, so the sound does not distort. A quiet voice is not changed. The transcript is made from each source on its own, so this does not change what is written.
|
|
136
138
|
|
|
137
139
|
### Clean up the replay sound
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* audio-resample.js — the server's copy of the low-pass resampler in public/pm/audio-capture.js (notes-audio-quality Run 4).
|
|
3
|
+
*
|
|
4
|
+
* makeResampler(inRate, outRate) → { push(Float32Array|Float64Array) → Int16Array, flush() → Int16Array }
|
|
5
|
+
*
|
|
6
|
+
* The page cannot require() a CommonJS file and the server cannot import() a page module without a warning on every start, so the
|
|
7
|
+
* function exists twice. Its text must stay the same in both files: notes-hires.test.js compares the two and runs them on the same
|
|
8
|
+
* sound. Change one, change the other.
|
|
9
|
+
*/
|
|
10
|
+
const RATE = 16000;
|
|
11
|
+
const CUT = 0.45; // the filter cuts at this share of the output rate
|
|
12
|
+
const CROSSINGS = 16; // zero crossings of the sinc on each side of the centre
|
|
13
|
+
|
|
14
|
+
const toS16 = (v) => { const c = v > 1 ? 1 : v < -1 ? -1 : v; return c < 0 ? c * 0x8000 : c * 0x7fff; };
|
|
15
|
+
|
|
16
|
+
function makeResampler(inRate, outRate = RATE) {
|
|
17
|
+
const ratio = inRate / outRate;
|
|
18
|
+
if (ratio === 1) {
|
|
19
|
+
return { push(x) { const o = new Int16Array(x.length); for (let i = 0; i < x.length; i++) o[i] = toS16(x[i]); return o; }, flush() { return new Int16Array(0); } };
|
|
20
|
+
}
|
|
21
|
+
const fc = CUT / Math.max(1, ratio); // cycles per input sample
|
|
22
|
+
const half = Math.ceil(CROSSINGS / (2 * fc)); // input samples either side of the centre
|
|
23
|
+
let buf = new Float64Array(0); // input not yet used up; buf[0] is input sample `base`
|
|
24
|
+
let base = 0;
|
|
25
|
+
let centre = 0; // the next output sample sits at this input position
|
|
26
|
+
let seen = 0; // input samples received
|
|
27
|
+
const weight = (d) => {
|
|
28
|
+
const x = 2 * fc * d;
|
|
29
|
+
const sinc = x === 0 ? 1 : Math.sin(Math.PI * x) / (Math.PI * x);
|
|
30
|
+
const w = 0.42 + 0.5 * Math.cos(Math.PI * d / half) + 0.08 * Math.cos(2 * Math.PI * d / half); // Blackman, centred
|
|
31
|
+
return sinc * w;
|
|
32
|
+
};
|
|
33
|
+
// The weights depend only on the fractional part of the centre, so they are made once for each fraction (3 or 160 of them for the
|
|
34
|
+
// rates in use) and kept: 48 kHz to 16 kHz, or 24 kHz to 16 kHz, would otherwise compute a sine and two cosines per tap per sample.
|
|
35
|
+
const phases = new Map();
|
|
36
|
+
const phaseOf = (frac) => {
|
|
37
|
+
const key = Math.round(frac * 1e6);
|
|
38
|
+
let ph = phases.get(key);
|
|
39
|
+
if (!ph) {
|
|
40
|
+
const c = Math.floor(frac * 1e6 + 0.5) / 1e6; const lo = Math.ceil(c - half) - 0; const hi = Math.floor(c + half);
|
|
41
|
+
const w = new Float64Array(hi - lo + 1); let norm = 0;
|
|
42
|
+
for (let i = lo; i <= hi; i++) { const k = weight(i - c); w[i - lo] = k; norm += k; }
|
|
43
|
+
for (let i = 0; i < w.length; i++) w[i] /= norm;
|
|
44
|
+
ph = { lo, w };
|
|
45
|
+
if (phases.size < 4096) phases.set(key, ph);
|
|
46
|
+
}
|
|
47
|
+
return ph;
|
|
48
|
+
};
|
|
49
|
+
function run(limit, out) {
|
|
50
|
+
while (centre < limit && Math.floor(centre) + half < base + buf.length) {
|
|
51
|
+
const fl = Math.floor(centre); const ph = phaseOf(centre - fl);
|
|
52
|
+
const first = fl + ph.lo - base; let sum = 0;
|
|
53
|
+
for (let k = 0; k < ph.w.length; k++) { const j = first + k; if (j >= 0 && j < buf.length) sum += buf[j] * ph.w[k]; }
|
|
54
|
+
out.push(toS16(sum));
|
|
55
|
+
centre += ratio;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function trim() {
|
|
59
|
+
const keep = Math.max(base, Math.floor(centre) - half);
|
|
60
|
+
if (keep > base) { buf = buf.slice(keep - base); base = keep; }
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
push(x) {
|
|
64
|
+
const merged = new Float64Array(buf.length + x.length); merged.set(buf); merged.set(x, buf.length); buf = merged; seen += x.length;
|
|
65
|
+
const out = []; run(Infinity, out); trim();
|
|
66
|
+
return Int16Array.from(out);
|
|
67
|
+
},
|
|
68
|
+
flush() {
|
|
69
|
+
const pad = new Float64Array(buf.length + half + 1); pad.set(buf); buf = pad;
|
|
70
|
+
const out = []; run(seen, out); trim();
|
|
71
|
+
return Int16Array.from(out);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = { makeResampler, RATE };
|
|
@@ -28,11 +28,16 @@ const RATE = 16000;
|
|
|
28
28
|
const BYTES_PER_MS = (RATE * 2) / 1000;
|
|
29
29
|
const ON_TIME_MS = 1500; // a chunk this close to where its source left off is placed straight after it
|
|
30
30
|
const MAX_BYTES = RATE * 2 * 60 * 60 * 6; // six hours; a longer meeting keeps its first six hours
|
|
31
|
+
const HI_RATE = 24000; // the replay may be stored at this rate (D92 as amended 2026-10-08)
|
|
32
|
+
const HI_BYTES_PER_MS = (HI_RATE * 2) / 1000;
|
|
33
|
+
const HI_MAX_BYTES = HI_RATE * 2 * 60 * 60 * 6;
|
|
31
34
|
const ID_RE = /^n-[0-9a-z]{4,16}-[0-9a-f]{4}$/;
|
|
32
35
|
|
|
33
36
|
const dirOf = (runtimeDir) => path.join(runtimeDir, 'notes', 'recordings');
|
|
34
37
|
const fileOf = (runtimeDir, id) => path.join(dirOf(runtimeDir), id + '.pcm');
|
|
35
38
|
const SOURCES = ['mic', 'meeting'];
|
|
39
|
+
const hiFileOf = (runtimeDir, id) => path.join(dirOf(runtimeDir), id + '.hi.pcm');
|
|
40
|
+
const sideFileOf = (runtimeDir, id, suffix) => path.join(dirOf(runtimeDir), id + suffix);
|
|
36
41
|
const cleanFileOf = (runtimeDir, id) => path.join(dirOf(runtimeDir), id + '.clean.pcm');
|
|
37
42
|
const sourceFileOf = (runtimeDir, id, source) => path.join(dirOf(runtimeDir), id + '.' + source + '.pcm');
|
|
38
43
|
const settingsFile = (runtimeDir) => path.join(runtimeDir, 'notes', 'audio-settings.json');
|
|
@@ -75,7 +80,7 @@ function softLimit(x) {
|
|
|
75
80
|
/** Add one chunk at meeting time `t`. Samples already there (the other source) are added to, then limited by softLimit. With
|
|
76
81
|
* `mixed: false` only the source's own file is written: the PM keeps no audio for replay, and the final pass deletes it when done.
|
|
77
82
|
* The per-source files are never limited: they are what the transcription reads. */
|
|
78
|
-
function write(runtimeDir, { id, source, pcm, t, mixed = true }) {
|
|
83
|
+
function write(runtimeDir, { id, source, pcm, pcm24 = null, t, mixed = true }) {
|
|
79
84
|
if (!ID_RE.test(String(id || '')) || !pcm || !pcm.length || pcm.length % 2) return { ok: false, error: 'nothing to keep' };
|
|
80
85
|
const f = fileOf(runtimeDir, id);
|
|
81
86
|
const key = f + '|' + source;
|
|
@@ -86,7 +91,10 @@ function write(runtimeDir, { id, source, pcm, t, mixed = true }) {
|
|
|
86
91
|
if (at >= MAX_BYTES) return { ok: true, kept: false };
|
|
87
92
|
const len = Math.min(pcm.length, MAX_BYTES - at);
|
|
88
93
|
fs.mkdirSync(dirOf(runtimeDir), { recursive: true });
|
|
89
|
-
|
|
94
|
+
// With 24 kHz audio the replay is the 24 kHz mix and no 16 kHz mix is written; the 16 kHz source files are written either way
|
|
95
|
+
const hiOk = mixed && pcm24 && pcm24.length && pcm24.length % 2 === 0;
|
|
96
|
+
if (hiOk) writeHi(runtimeDir, id, source, pcm24, t);
|
|
97
|
+
if (mixed && !hiOk) {
|
|
90
98
|
const fd = fs.openSync(f, fs.existsSync(f) ? 'r+' : 'w+', 0o600);
|
|
91
99
|
try {
|
|
92
100
|
const old = Buffer.alloc(len);
|
|
@@ -105,9 +113,38 @@ function write(runtimeDir, { id, source, pcm, t, mixed = true }) {
|
|
|
105
113
|
return { ok: true, kept: true, at_ms: at / BYTES_PER_MS };
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
|
|
116
|
+
/** Add one chunk of 24 kHz audio to the note's 24 kHz mix at meeting time `t`, placed as write() places the 16 kHz audio. */
|
|
117
|
+
function writeHi(runtimeDir, id, source, pcm24, t) {
|
|
118
|
+
const f = hiFileOf(runtimeDir, id);
|
|
119
|
+
const key = f + '|' + source;
|
|
120
|
+
let at = Math.max(0, Math.round((Number(t) || 0) * HI_BYTES_PER_MS / 2) * 2);
|
|
121
|
+
const prev = next.get(key);
|
|
122
|
+
if (prev !== undefined && at <= prev + ON_TIME_MS * HI_BYTES_PER_MS) at = prev;
|
|
123
|
+
if (at >= HI_MAX_BYTES) return;
|
|
124
|
+
const len = Math.min(pcm24.length, HI_MAX_BYTES - at);
|
|
125
|
+
const fd = fs.openSync(f, fs.existsSync(f) ? 'r+' : 'w+', 0o600);
|
|
126
|
+
try {
|
|
127
|
+
const old = Buffer.alloc(len);
|
|
128
|
+
fs.readSync(fd, old, 0, len, at);
|
|
129
|
+
const out = Buffer.alloc(len);
|
|
130
|
+
for (let i = 0; i < len; i += 2) out.writeInt16LE(softLimit(old.readInt16LE(i) + pcm24.readInt16LE(i)), i);
|
|
131
|
+
fs.writeSync(fd, out, 0, len, at);
|
|
132
|
+
} finally { fs.closeSync(fd); }
|
|
133
|
+
next.set(key, at + len);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The file the replay is made from: the 24 kHz mix when the note has one, else the 16 kHz mix. { file, bytes, rate } | null. */
|
|
137
|
+
function baseOf(runtimeDir, id) {
|
|
109
138
|
if (!ID_RE.test(String(id || ''))) return null;
|
|
110
|
-
|
|
139
|
+
for (const [file, rate] of [[hiFileOf(runtimeDir, id), HI_RATE], [fileOf(runtimeDir, id), RATE]]) {
|
|
140
|
+
try { const st = fs.statSync(file); if (st.size) return { file, bytes: st.size, rate }; } catch { /* none */ }
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function info(runtimeDir, id) {
|
|
146
|
+
const b = baseOf(runtimeDir, id);
|
|
147
|
+
return b ? { bytes: b.bytes, ms: Math.round(b.bytes / (b.rate * 2 / 1000)), rate: b.rate } : null;
|
|
111
148
|
}
|
|
112
149
|
function removeSources(runtimeDir, id) {
|
|
113
150
|
if (!ID_RE.test(String(id || ''))) return;
|
|
@@ -115,10 +152,14 @@ function removeSources(runtimeDir, id) {
|
|
|
115
152
|
}
|
|
116
153
|
function remove(runtimeDir, id) {
|
|
117
154
|
if (!ID_RE.test(String(id || ''))) return false;
|
|
118
|
-
for (const k of [...next.keys()]) if (k.startsWith(fileOf(runtimeDir, id) + '|')) next.delete(k);
|
|
155
|
+
for (const k of [...next.keys()]) if (k.startsWith(fileOf(runtimeDir, id) + '|') || k.startsWith(hiFileOf(runtimeDir, id) + '|')) next.delete(k);
|
|
119
156
|
for (const src of SOURCES) { try { fs.unlinkSync(sourceFileOf(runtimeDir, id, src)); } catch { /* none */ } }
|
|
120
|
-
|
|
121
|
-
|
|
157
|
+
let removed = false;
|
|
158
|
+
for (const extra of ['.echo.json', '.pcm.echo.tmp', '.hi.pcm.echo.tmp', '.hi.pcm', '.clean.pcm', '.clean.pcm.tmp']) {
|
|
159
|
+
try { fs.unlinkSync(path.join(dirOf(runtimeDir), id + extra)); if (extra === '.hi.pcm') removed = true; } catch { /* none */ }
|
|
160
|
+
}
|
|
161
|
+
try { fs.unlinkSync(fileOf(runtimeDir, id)); removed = true; } catch { /* none */ }
|
|
162
|
+
return removed;
|
|
122
163
|
}
|
|
123
164
|
/** The note's audio, one file per source: [{ source, file, bytes, ms }], the sources that were heard. */
|
|
124
165
|
function sources(runtimeDir, id) {
|
|
@@ -131,27 +172,28 @@ function sources(runtimeDir, id) {
|
|
|
131
172
|
return out;
|
|
132
173
|
}
|
|
133
174
|
|
|
134
|
-
/** The file the replay plays: the cleaned copy when the PM switched cleaning on and the copy is as long as the
|
|
135
|
-
* before listening went on is shorter, so it is stale and the plain
|
|
175
|
+
/** The file the replay plays: the cleaned copy when the PM switched cleaning on and the copy is as long as the replay's base (a copy
|
|
176
|
+
* made before listening went on is shorter, so it is stale and the plain replay plays); otherwise the base. { file, bytes, rate,
|
|
177
|
+
* cleaned } | null. */
|
|
136
178
|
function replayOf(runtimeDir, id) {
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
179
|
+
const base = baseOf(runtimeDir, id);
|
|
180
|
+
if (!base) return null;
|
|
139
181
|
if (getClean(runtimeDir)) {
|
|
140
|
-
try { const st = fs.statSync(cleanFileOf(runtimeDir, id)); if (st.size ===
|
|
182
|
+
try { const st = fs.statSync(cleanFileOf(runtimeDir, id)); if (st.size === base.bytes) return { file: cleanFileOf(runtimeDir, id), bytes: st.size, rate: base.rate, cleaned: true }; } catch { /* none */ }
|
|
141
183
|
}
|
|
142
|
-
return { file:
|
|
184
|
+
return { file: base.file, bytes: base.bytes, rate: base.rate, cleaned: false };
|
|
143
185
|
}
|
|
144
|
-
/** True when a cleaned copy exists and is as long as the
|
|
186
|
+
/** True when a cleaned copy exists and is as long as the replay's base. */
|
|
145
187
|
function hasClean(runtimeDir, id) {
|
|
146
|
-
const
|
|
147
|
-
try { return !!
|
|
188
|
+
const base = baseOf(runtimeDir, id);
|
|
189
|
+
try { return !!base && fs.statSync(cleanFileOf(runtimeDir, id)).size === base.bytes; } catch { return false; }
|
|
148
190
|
}
|
|
149
191
|
|
|
150
|
-
function wavHeader(dataBytes) {
|
|
192
|
+
function wavHeader(dataBytes, rate = RATE) {
|
|
151
193
|
const h = Buffer.alloc(44);
|
|
152
194
|
h.write('RIFF', 0); h.writeUInt32LE(36 + dataBytes, 4); h.write('WAVE', 8);
|
|
153
195
|
h.write('fmt ', 12); h.writeUInt32LE(16, 16); h.writeUInt16LE(1, 20); h.writeUInt16LE(1, 22);
|
|
154
|
-
h.writeUInt32LE(
|
|
196
|
+
h.writeUInt32LE(rate, 24); h.writeUInt32LE(rate * 2, 28); h.writeUInt16LE(2, 32); h.writeUInt16LE(16, 34);
|
|
155
197
|
h.write('data', 36); h.writeUInt32LE(dataBytes, 40);
|
|
156
198
|
return h;
|
|
157
199
|
}
|
|
@@ -159,7 +201,7 @@ function wavHeader(dataBytes) {
|
|
|
159
201
|
function serve(req, res, runtimeDir, id) {
|
|
160
202
|
const inf = replayOf(runtimeDir, id);
|
|
161
203
|
if (!inf) { res.writeHead(404, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ ok: false, error: 'this note has no audio' })); return; }
|
|
162
|
-
const header = wavHeader(inf.bytes);
|
|
204
|
+
const header = wavHeader(inf.bytes, inf.rate);
|
|
163
205
|
const total = header.length + inf.bytes;
|
|
164
206
|
let start = 0; let end = total - 1; let partial = false;
|
|
165
207
|
const m = /^bytes=(\d*)-(\d*)$/.exec(String(req.headers.range || '').trim());
|
|
@@ -178,4 +220,4 @@ function serve(req, res, runtimeDir, id) {
|
|
|
178
220
|
fs.createReadStream(inf.file, { start: from, end: to }).on('error', () => res.end()).pipe(res);
|
|
179
221
|
}
|
|
180
222
|
|
|
181
|
-
module.exports = { write, info, remove, removeSources, sources, serve, getKeep, setKeep, getClean, setClean, hasClean, replayOf, wavHeader, softLimit, replayFile: fileOf, cleanFile: cleanFileOf, RATE, BYTES_PER_MS, MAX_BYTES };
|
|
223
|
+
module.exports = { write, info, remove, removeSources, sources, serve, getKeep, setKeep, getClean, setClean, hasClean, replayOf, wavHeader, softLimit, replayFile: (dir, id) => (baseOf(dir, id) || { file: fileOf(dir, id) }).file, mixFile: fileOf, hiFile: hiFileOf, sideFile: sideFileOf, baseOf, cleanFile: cleanFileOf, HI_RATE, RATE, BYTES_PER_MS, MAX_BYTES };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* cleanStream({ n, readFar, readMic, onChunk }) the canceller, over any two tracks of n samples → a report
|
|
5
5
|
* cleanReplay(runtimeDir, id) rebuild the note's replay file from its two source files → { ok, ... }
|
|
6
6
|
* cleanReplayInWorker(runtimeDir, id) the same, on a worker thread, so the server stays awake → Promise
|
|
7
|
-
* report(runtimeDir, id) what the last clean-up did, or null
|
|
7
|
+
* report(runtimeDir, id) what the last clean-up did (or why it failed), or null
|
|
8
8
|
*
|
|
9
9
|
* THE PROBLEM. The microphone hears the meeting through the speakers, so each voice is recorded twice, the second copy late.
|
|
10
10
|
* lib/notes-audio.js keeps the meeting on its own (<id>.meeting.pcm), which is exactly the signal that leaked into the microphone.
|
|
@@ -26,6 +26,7 @@ const fs = require('fs');
|
|
|
26
26
|
const path = require('path');
|
|
27
27
|
const { Worker } = require('worker_threads');
|
|
28
28
|
const notesAudio = require('./notes-audio');
|
|
29
|
+
const hires = require('./notes-hires');
|
|
29
30
|
|
|
30
31
|
const FS = notesAudio.RATE; // 16000
|
|
31
32
|
const L = 8192; // the echo path kept: 512 ms
|
|
@@ -259,7 +260,7 @@ function cleanStream({ n, readFar, readMic, onChunk }) {
|
|
|
259
260
|
}
|
|
260
261
|
|
|
261
262
|
/* ── the replay file ──────────────────────────────────────────────────────────────────────────── */
|
|
262
|
-
const reportFile = (runtimeDir, id) => notesAudio.
|
|
263
|
+
const reportFile = (runtimeDir, id) => notesAudio.sideFile(runtimeDir, id, '.echo.json');
|
|
263
264
|
function report(runtimeDir, id) { try { return JSON.parse(fs.readFileSync(reportFile(runtimeDir, id), 'utf8')); } catch { return null; } }
|
|
264
265
|
|
|
265
266
|
function readSamples(fd, size, from, count) {
|
|
@@ -282,9 +283,18 @@ function cleanReplay(runtimeDir, id, { beforeCommit } = {}) {
|
|
|
282
283
|
const srcs = notesAudio.sources(runtimeDir, id);
|
|
283
284
|
const mic = srcs.find((s) => s.source === 'mic'); const meet = srcs.find((s) => s.source === 'meeting');
|
|
284
285
|
if (!mic || !meet) return { ok: true, skipped: 'only one source was heard, so there is no echo to take out' };
|
|
285
|
-
|
|
286
|
-
|
|
286
|
+
const base = notesAudio.baseOf(runtimeDir, id);
|
|
287
|
+
if (!base) return { ok: true, skipped: 'the note has no replay file' };
|
|
288
|
+
// A note with a 24 kHz replay is cleaned at 16 kHz, from the source files, and the cleaned speech is then put together with the
|
|
289
|
+
// band above 8 kHz of the 24 kHz recording (lib/notes-hires.js). An older note has a 16 kHz replay and is rebuilt as it always was.
|
|
290
|
+
const hi = base.rate === notesAudio.HI_RATE;
|
|
291
|
+
const mixPath = notesAudio.mixFile(runtimeDir, id); const hiPath = notesAudio.hiFile(runtimeDir, id);
|
|
292
|
+
const out = hi ? hiPath : mixPath; const tmp = mixPath + '.echo.tmp'; const tmpHi = hiPath + '.echo.tmp';
|
|
287
293
|
let fdM = null; let fdX = null; let fdO = null;
|
|
294
|
+
const fail = (error) => {
|
|
295
|
+
for (const f of [tmp, tmpHi]) { try { fs.unlinkSync(f); } catch { /* none */ } }
|
|
296
|
+
return { ok: false, error: String(error).slice(0, 300) };
|
|
297
|
+
};
|
|
288
298
|
try {
|
|
289
299
|
fdM = fs.openSync(mic.file, 'r'); fdX = fs.openSync(meet.file, 'r'); fdO = fs.openSync(tmp, 'w', 0o600);
|
|
290
300
|
const n = Math.floor(Math.max(mic.bytes, meet.bytes) / 2);
|
|
@@ -303,22 +313,30 @@ function cleanReplay(runtimeDir, id, { beforeCommit } = {}) {
|
|
|
303
313
|
},
|
|
304
314
|
});
|
|
305
315
|
fs.closeSync(fdO); fdO = null;
|
|
316
|
+
if (hi) {
|
|
317
|
+
const c = hires.compose({ cleanFile: tmp, hiFile: hiPath, outFile: tmpHi });
|
|
318
|
+
if (!c.ok) { const r = fail(c.error); writeReport(runtimeDir, id, r); return r; }
|
|
319
|
+
}
|
|
306
320
|
if (beforeCommit) beforeCommit(); // the suites use this to make listening go on at the last moment
|
|
307
|
-
// the sources must be as they were: if listening went on meanwhile, the
|
|
308
|
-
const now = notesAudio.sources(runtimeDir, id);
|
|
309
|
-
const same = now.length === srcs.length && now.every((s) => { const o = srcs.find((x) => x.source === s.source); return o && o.bytes === s.bytes; })
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
321
|
+
// the sources and the replay must be as they were: if listening went on meanwhile, the replay as it is is the truth and this one is dropped
|
|
322
|
+
const now = notesAudio.sources(runtimeDir, id); const nowBase = notesAudio.baseOf(runtimeDir, id);
|
|
323
|
+
const same = now.length === srcs.length && now.every((s) => { const o = srcs.find((x) => x.source === s.source); return o && o.bytes === s.bytes; })
|
|
324
|
+
&& (!hi || (nowBase && nowBase.bytes === base.bytes));
|
|
325
|
+
if (!same) return fail('listening went on while the echo was taken out');
|
|
326
|
+
if (hi) { fs.renameSync(tmpHi, hiPath); try { fs.unlinkSync(tmp); } catch { /* none */ } } else fs.renameSync(tmp, mixPath);
|
|
327
|
+
const result = { ok: true, at: new Date().toISOString(), rate: hi ? notesAudio.HI_RATE : notesAudio.RATE, ...rep, took_ms: Date.now() - began };
|
|
328
|
+
writeReport(runtimeDir, id, result);
|
|
314
329
|
return result;
|
|
315
330
|
} catch (e) {
|
|
316
|
-
|
|
317
|
-
return { ok: false, error: String((e && e.message) || e).slice(0, 300) };
|
|
331
|
+
return fail((e && e.message) || e);
|
|
318
332
|
} finally {
|
|
319
333
|
for (const fd of [fdM, fdX, fdO]) if (fd !== null) { try { fs.closeSync(fd); } catch { /* closed */ } }
|
|
320
334
|
}
|
|
321
335
|
}
|
|
336
|
+
/** What the last clean-up did, kept beside the audio so a failure is not silent. */
|
|
337
|
+
function writeReport(runtimeDir, id, result) {
|
|
338
|
+
try { fs.writeFileSync(reportFile(runtimeDir, id), JSON.stringify({ at: new Date().toISOString(), ...result }), { mode: 0o600 }); } catch { /* best effort */ }
|
|
339
|
+
}
|
|
322
340
|
|
|
323
341
|
const running = new Map(); // `${dir}|${id}` → the promise of a clean-up that is under way
|
|
324
342
|
/** cleanReplay on a worker thread. A second call for the same note while one runs gets the same promise. Never rejects. */
|
|
@@ -329,7 +347,7 @@ function cleanReplayInWorker(runtimeDir, id) {
|
|
|
329
347
|
let done = false;
|
|
330
348
|
const w = new Worker(path.join(__dirname, 'notes-echo-worker.js'), { workerData: { runtimeDir, id } });
|
|
331
349
|
const finish = (r) => { if (done) return; done = true; clearTimeout(timer); resolve(r); };
|
|
332
|
-
const timer = setTimeout(() => { w.terminate();
|
|
350
|
+
const timer = setTimeout(() => { w.terminate(); for (const t of [notesAudio.mixFile(runtimeDir, id) + '.echo.tmp', notesAudio.hiFile(runtimeDir, id) + '.echo.tmp']) { try { fs.unlinkSync(t); } catch { /* none */ } } finish({ ok: false, error: 'it took too long' }); }, TIMEOUT_MS);
|
|
333
351
|
w.once('message', finish);
|
|
334
352
|
w.once('error', (e) => finish({ ok: false, error: String((e && e.message) || e).slice(0, 300) }));
|
|
335
353
|
w.once('exit', () => finish({ ok: false, error: 'the worker ended without a result' }));
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* notes-hires.js — put the cleaned speech back into the 24 kHz replay (notes-audio-quality Run 4, D92 as amended 2026-10-08).
|
|
3
|
+
*
|
|
4
|
+
* compose({ cleanFile, hiFile, outFile }) → { ok, samples } | { ok: false, error }
|
|
5
|
+
*
|
|
6
|
+
* THE PROBLEM. The echo clean-up (lib/notes-echo.js) works at 16 kHz, on the two source files, so it cleans the band below 8 kHz.
|
|
7
|
+
* The replay the PM hears is the 24 kHz mix, which also holds the band from 8 to 12 kHz: the air and the hiss of the voices. Rebuilding
|
|
8
|
+
* the replay from the 16 kHz clean-up alone would throw that band away and bring the replay back to 16 kHz quality.
|
|
9
|
+
*
|
|
10
|
+
* THE METHOD. Split the 24 kHz mix at the filter's edge (7.2 kHz): low = the mix taken down to 16 kHz and back up to 24 kHz, high = the
|
|
11
|
+
* mix minus low. The replay is then the cleaned 16 kHz mix taken up to 24 kHz, plus high. The low band is the cleaned speech; the high
|
|
12
|
+
* band is exactly what was recorded. Running it again on its own output changes nothing, because the high band of the result is the
|
|
13
|
+
* high band of the recording, so a second final pass (Listen again) can use it.
|
|
14
|
+
*
|
|
15
|
+
* WHAT IT NEVER DOES. It reads the two files and writes the output file; the caller renames it into place. It does not touch the
|
|
16
|
+
* 16 kHz source files. It opens no network module.
|
|
17
|
+
*/
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const resample = require('./audio-resample');
|
|
20
|
+
const { softLimit } = require('./notes-audio');
|
|
21
|
+
|
|
22
|
+
const HI = 24000;
|
|
23
|
+
const LO = 16000;
|
|
24
|
+
const BLOCK_HI = 480000; // 20 s of the 24 kHz mix at a time
|
|
25
|
+
const BLOCK_LO = BLOCK_HI * LO / HI;
|
|
26
|
+
const TOLERANCE_S = 0.5; // the two files may differ in length by this much: more means they are not the same recording
|
|
27
|
+
|
|
28
|
+
const toFloat = (i16) => { const f = new Float32Array(i16.length); for (let i = 0; i < i16.length; i++) f[i] = i16[i] / 32768; return f; };
|
|
29
|
+
|
|
30
|
+
/** A queue of int16 samples that grows at the back and is eaten from the front. */
|
|
31
|
+
function queue() {
|
|
32
|
+
let a = new Int16Array(0);
|
|
33
|
+
return { get length() { return a.length; }, push(x) { const m = new Int16Array(a.length + x.length); m.set(a); m.set(x, a.length); a = m; },
|
|
34
|
+
take(n) { const out = a.subarray(0, n); a = a.slice(n); return out; } };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function readBlock(fd, size, from, count) {
|
|
38
|
+
const bytes = Math.max(0, Math.min(count * 2, size - from * 2));
|
|
39
|
+
const out = new Int16Array(bytes / 2);
|
|
40
|
+
if (bytes <= 0) return out;
|
|
41
|
+
const buf = Buffer.alloc(bytes);
|
|
42
|
+
fs.readSync(fd, buf, 0, bytes, from * 2);
|
|
43
|
+
for (let i = 0; i < out.length; i++) out[i] = buf.readInt16LE(i * 2);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function compose({ cleanFile, hiFile, outFile }) {
|
|
48
|
+
let fdC = null; let fdH = null; let fdO = null;
|
|
49
|
+
try {
|
|
50
|
+
const sizeC = fs.statSync(cleanFile).size; const sizeH = fs.statSync(hiFile).size;
|
|
51
|
+
const nC = Math.floor(sizeC / 2); const nH = Math.floor(sizeH / 2);
|
|
52
|
+
if (!nH) return { ok: false, error: 'the 24 kHz recording is empty' };
|
|
53
|
+
if (Math.abs(nC / LO - nH / HI) > TOLERANCE_S) return { ok: false, error: 'the two recordings differ in length by more than ' + TOLERANCE_S + ' s' };
|
|
54
|
+
fdC = fs.openSync(cleanFile, 'r'); fdH = fs.openSync(hiFile, 'r'); fdO = fs.openSync(outFile, 'w', 0o600);
|
|
55
|
+
const down = resample.makeResampler(HI, LO); const up = resample.makeResampler(LO, HI); const upClean = resample.makeResampler(LO, HI);
|
|
56
|
+
const raw = queue(); const low = queue(); const clean = queue();
|
|
57
|
+
let written = 0;
|
|
58
|
+
const emit = (n) => {
|
|
59
|
+
if (n <= 0) return;
|
|
60
|
+
const r = raw.take(n); const l = low.take(n); const c = clean.take(n);
|
|
61
|
+
const buf = Buffer.alloc(n * 2);
|
|
62
|
+
for (let i = 0; i < n; i++) buf.writeInt16LE(softLimit(c[i] + (r[i] - l[i])), i * 2);
|
|
63
|
+
fs.writeSync(fdO, buf, 0, buf.length, written * 2); written += n;
|
|
64
|
+
};
|
|
65
|
+
const drain = () => emit(Math.min(raw.length, low.length, clean.length));
|
|
66
|
+
for (let a = 0, b = 0; a < nH || b < nC; a += BLOCK_HI, b += BLOCK_LO) {
|
|
67
|
+
const h = readBlock(fdH, sizeH, a, BLOCK_HI); const c = readBlock(fdC, sizeC, b, BLOCK_LO);
|
|
68
|
+
raw.push(h);
|
|
69
|
+
low.push(up.push(toFloat(down.push(toFloat(h)))));
|
|
70
|
+
clean.push(upClean.push(toFloat(c)));
|
|
71
|
+
drain();
|
|
72
|
+
}
|
|
73
|
+
low.push(up.push(toFloat(down.flush()))); low.push(up.flush());
|
|
74
|
+
clean.push(upClean.flush());
|
|
75
|
+
drain();
|
|
76
|
+
// the last few samples may lack a partner (the filters stop a hair short): the band-limited parts are then taken as silent
|
|
77
|
+
const rest = raw.length;
|
|
78
|
+
if (rest > 0) {
|
|
79
|
+
if (rest > 8) return { ok: false, error: 'the recordings did not line up to the end' };
|
|
80
|
+
const r = raw.take(rest); const l = low.take(Math.min(rest, low.length)); const c = clean.take(Math.min(rest, clean.length));
|
|
81
|
+
const buf = Buffer.alloc(rest * 2);
|
|
82
|
+
for (let i = 0; i < rest; i++) buf.writeInt16LE(softLimit((i < c.length ? c[i] : 0) + (i < l.length ? r[i] - l[i] : 0)), i * 2);
|
|
83
|
+
fs.writeSync(fdO, buf, 0, buf.length, written * 2); written += rest;
|
|
84
|
+
}
|
|
85
|
+
fs.closeSync(fdO); fdO = null;
|
|
86
|
+
return { ok: true, samples: written };
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return { ok: false, error: String((e && e.message) || e).slice(0, 300) };
|
|
89
|
+
} finally {
|
|
90
|
+
for (const fd of [fdC, fdH, fdO]) if (fd !== null) { try { fs.closeSync(fd); } catch { /* closed */ } }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = { compose, HI, LO };
|
|
@@ -19,7 +19,6 @@ const path = require('path');
|
|
|
19
19
|
const notesAudio = require('./notes-audio');
|
|
20
20
|
const { runProgram } = require('./notes-final');
|
|
21
21
|
|
|
22
|
-
const RATE = notesAudio.RATE;
|
|
23
22
|
const FILTER = 'highpass=f=80,afftdn=nr=10:nf=-45,loudnorm=I=-16:TP=-1.5:LRA=11';
|
|
24
23
|
const TIMEOUT_MS = 20 * 60 * 1000;
|
|
25
24
|
const LENGTH_SLACK = 0.02; // the copy may differ from the mix by this share of its length, no more
|
|
@@ -50,8 +49,8 @@ function build(runtimeDir, id, opts = {}) {
|
|
|
50
49
|
const input = notesAudio.replayFile(runtimeDir, id); const out = notesAudio.cleanFile(runtimeDir, id); const tmp = out + '.tmp';
|
|
51
50
|
const began = Date.now();
|
|
52
51
|
try {
|
|
53
|
-
const r = await run(found.bin, ['-nostdin', '-hide_banner', '-loglevel', 'error', '-y', '-f', 's16le', '-ar', String(
|
|
54
|
-
'-af', FILTER, '-f', 's16le', '-ar', String(
|
|
52
|
+
const r = await run(found.bin, ['-nostdin', '-hide_banner', '-loglevel', 'error', '-y', '-f', 's16le', '-ar', String(inf.rate), '-ac', '1', '-i', input,
|
|
53
|
+
'-af', FILTER, '-f', 's16le', '-ar', String(inf.rate), '-ac', '1', tmp], { timeout: TIMEOUT_MS });
|
|
55
54
|
if (!r.ok) { try { fs.unlinkSync(tmp); } catch { /* none */ } return { ok: false, error: r.error || 'ffmpeg failed' }; }
|
|
56
55
|
const size = fs.statSync(tmp).size;
|
|
57
56
|
const now = notesAudio.info(runtimeDir, id);
|
|
@@ -654,13 +654,21 @@ async function handle(req, res, url, ctx) {
|
|
|
654
654
|
if (b64.length > Math.ceil(MAX_PCM_BYTES / 3) * 4) return done({ ok: false, status: 413, error: 'that audio chunk is too long' });
|
|
655
655
|
const pcm = Buffer.from(b64, 'base64');
|
|
656
656
|
if (pcm.length % 2) return done({ ok: false, status: 400, error: 'the audio must be 16-bit samples' });
|
|
657
|
+
// the same time at 24 kHz, for the replay (D92 as amended 2026-10-08); the transcription never reads it
|
|
658
|
+
const b24 = typeof body.pcm24 === 'string' ? body.pcm24 : '';
|
|
659
|
+
if (b24.length > Math.ceil((MAX_PCM_BYTES * 1.5) / 3) * 4) return done({ ok: false, status: 413, error: 'that audio chunk is too long' });
|
|
660
|
+
const pcm24 = b24 ? Buffer.from(b24, 'base64') : null;
|
|
661
|
+
if (pcm24 && pcm24.length % 2) return done({ ok: false, status: 400, error: 'the audio must be 16-bit samples' });
|
|
657
662
|
if (!liveDetect(ctx).ready) return done({ ok: false, status: 409, error: 'local transcription is not set up' });
|
|
658
663
|
const ms = (pcm.length / 2 / whisper.RATE) * 1000;
|
|
659
664
|
const t = Math.max(0, notes.meetingMs(note.note) - ms);
|
|
660
665
|
// the audio is kept for replay unless the PM switched that off (D92); a private note never reaches this line
|
|
661
666
|
arm(ctx, id);
|
|
662
667
|
// each source is also kept apart for the final pass after Stop, which deletes it when the PM keeps no audio (Run 9)
|
|
663
|
-
|
|
668
|
+
// a 24 kHz chunk must cover the same time as the 16 kHz chunk (to a tenth of a second); one that does not is not kept
|
|
669
|
+
const sameTime = !!pcm24 && pcm24.length > 0 && Math.abs(pcm24.length / 2 / notesAudio.HI_RATE - pcm.length / 2 / whisper.RATE) <= 0.1;
|
|
670
|
+
if (pcm24 && pcm24.length && !sameTime) audioErrors.set(id, { at: new Date().toISOString(), error: 'the 24 kHz audio of one chunk did not match its 16 kHz audio, so the replay has a gap there' });
|
|
671
|
+
{ try { notesAudio.write(dir, { id, source, pcm, pcm24: sameTime ? pcm24 : null, t, mixed: notesAudio.getKeep(dir) }); } catch (e) { audioErrors.set(id, { at: new Date().toISOString(), error: 'the audio was not kept: ' + ((e && e.message) || e) }); } }
|
|
664
672
|
return done(transcriberFor(ctx).push({ id, source, pcm, t, final: body.final === true }));
|
|
665
673
|
}
|
|
666
674
|
if (p === '/api/notes/label') return done(notes.setLabel(dir, { id, index: Number(body.index), cat: body.cat, drop: body.drop === true }));
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* notes-test-signals.js — synthetic sound for the notes audio suites (notes-echo.test.js, notes-hires.test.js). Not a test itself.
|
|
3
|
+
*
|
|
4
|
+
* speechLike(seed, secs, talkShare) → { x, active } noise through three resonances, in phrases with pauses
|
|
5
|
+
* makePath(seed, delayMs, gainDb) an echo path: a direct arrival and a decaying tail
|
|
6
|
+
* conv(x, h) conv by overlap-add over FFTs
|
|
7
|
+
* scene({ secs, delayMs, gainDb, tanh, change, noiseDb, seed }) → { far, near, mic, echo, n }
|
|
8
|
+
* the meeting `far`, the PM `near`, and the microphone that hears both
|
|
9
|
+
*/
|
|
10
|
+
const E = require('./lib/notes-echo');
|
|
11
|
+
|
|
12
|
+
const FS = 16000;
|
|
13
|
+
function rng(seed) { let a = seed >>> 0; return () => { a |= 0; a = a + 0x6D2B79F5 | 0; let t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; }
|
|
14
|
+
const gauss = (r) => Math.sqrt(-2 * Math.log(r() + 1e-12)) * Math.cos(2 * Math.PI * r());
|
|
15
|
+
/** Speech-like: noise through three resonances, in phrases of 1 to 3 s with pauses. { x, active }. */
|
|
16
|
+
function speechLike(seed, secs, talkShare) {
|
|
17
|
+
const r = rng(seed); const n = secs * FS; const x = new Float64Array(n); const active = new Uint8Array(n);
|
|
18
|
+
const res = [[500, 80], [1500, 120], [2600, 200]].map(([f, bw]) => { const R = Math.exp(-Math.PI * bw / FS); return { a1: 2 * R * Math.cos(2 * Math.PI * f / FS), a2: -R * R, y1: 0, y2: 0 }; });
|
|
19
|
+
let t = 0;
|
|
20
|
+
while (t < n) {
|
|
21
|
+
const talk = Math.round((1 + 2 * r()) * FS); const quiet = Math.round(talk * (1 - talkShare) / talkShare * (0.5 + r())); const syll = 3 + 3 * r();
|
|
22
|
+
for (let i = 0; i < talk && t + i < n; i++) {
|
|
23
|
+
const env = 0.55 + 0.45 * Math.sin(2 * Math.PI * syll * i / FS) ** 2; const edge = Math.min(1, i / 800, (talk - i) / 800); const e = gauss(r);
|
|
24
|
+
let y = 0; for (const q of res) { const o = e * 0.2 + q.a1 * q.y1 + q.a2 * q.y2; q.y2 = q.y1; q.y1 = o; y += o; }
|
|
25
|
+
x[t + i] = y * env * edge * 0.04; active[t + i] = 1;
|
|
26
|
+
}
|
|
27
|
+
t += talk + quiet;
|
|
28
|
+
}
|
|
29
|
+
let pk = 0; for (let i = 0; i < n; i++) pk = Math.max(pk, Math.abs(x[i]));
|
|
30
|
+
for (let i = 0; i < n; i++) x[i] = x[i] / pk * 0.4;
|
|
31
|
+
return { x, active };
|
|
32
|
+
}
|
|
33
|
+
/** An echo path: a direct arrival after delayMs, then a decaying tail, rolled off at the top. */
|
|
34
|
+
function makePath(seed, delayMs, gainDb) {
|
|
35
|
+
const d = Math.round(delayMs * FS / 1000); const len = d + 4800; const r = rng(seed); const h = new Float64Array(len); const g = 10 ** (gainDb / 20);
|
|
36
|
+
for (let i = 0; i < len - d; i++) h[d + i] = (i === 0 ? 1 : 0.35 * gauss(r) * Math.exp(-i / FS / 0.08)) * g;
|
|
37
|
+
let y = 0; for (let i = 0; i < len; i++) { y = 0.55 * y + 0.45 * h[i]; h[i] = y; }
|
|
38
|
+
return h;
|
|
39
|
+
}
|
|
40
|
+
/** conv(x, h) by overlap-add over FFTs. */
|
|
41
|
+
function conv(x, h) {
|
|
42
|
+
const F = 16384; const B = F - h.length; if (B <= 0) throw new Error('path too long');
|
|
43
|
+
const out = new Float64Array(x.length); const Hr = new Float64Array(F); const Hi = new Float64Array(F); Hr.set(h); E.fft(Hr, Hi, false);
|
|
44
|
+
for (let s = 0; s < x.length; s += B) {
|
|
45
|
+
const re = new Float64Array(F); const im = new Float64Array(F);
|
|
46
|
+
for (let i = 0; i < B && s + i < x.length; i++) re[i] = x[s + i];
|
|
47
|
+
E.fft(re, im, false);
|
|
48
|
+
for (let k = 0; k < F; k++) { const a = re[k] * Hr[k] - im[k] * Hi[k]; im[k] = re[k] * Hi[k] + im[k] * Hr[k]; re[k] = a; }
|
|
49
|
+
E.fft(re, im, true);
|
|
50
|
+
for (let i = 0; i < F && s + i < out.length; i++) out[s + i] += re[i];
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/** A scene: the meeting `far`, the PM `near`, and the microphone that hears both, plus the echo alone. */
|
|
55
|
+
function scene({ secs, delayMs = 120, gainDb = -9, tanh = 0, change = null, noiseDb = -50, seed = 1 }) {
|
|
56
|
+
const far = speechLike(11 + seed, secs, 0.65); const near = speechLike(29 + seed, secs, 0.45); const n = far.x.length;
|
|
57
|
+
const driven = tanh ? Float64Array.from(far.x, (v) => Math.tanh(tanh * v) / tanh) : far.x;
|
|
58
|
+
const echo = conv(driven, makePath(5, delayMs, gainDb));
|
|
59
|
+
if (change) { const second = conv(driven, makePath(6, delayMs + 20, gainDb - 6)); for (let i = Math.round(change * FS); i < n; i++) echo[i] = second[i]; }
|
|
60
|
+
const r = rng(77); const nz = 10 ** (noiseDb / 20) * 0.05; const mic = new Float64Array(n);
|
|
61
|
+
for (let i = 0; i < n; i++) mic[i] = echo[i] + near.x[i] * 0.5 + nz * gauss(r);
|
|
62
|
+
return { far, near, mic, echo, n };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { FS, rng, gauss, speechLike, makePath, conv, scene };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.116.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.116.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
|
@@ -32,14 +32,28 @@ export function makeResampler(inRate, outRate = RATE) {
|
|
|
32
32
|
const w = 0.42 + 0.5 * Math.cos(Math.PI * d / half) + 0.08 * Math.cos(2 * Math.PI * d / half); // Blackman, centred
|
|
33
33
|
return sinc * w;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
// The weights depend only on the fractional part of the centre, so they are made once for each fraction (3 or 160 of them for the
|
|
36
|
+
// rates in use) and kept: 48 kHz to 16 kHz, or 24 kHz to 16 kHz, would otherwise compute a sine and two cosines per tap per sample.
|
|
37
|
+
const phases = new Map();
|
|
38
|
+
const phaseOf = (frac) => {
|
|
39
|
+
const key = Math.round(frac * 1e6);
|
|
40
|
+
let ph = phases.get(key);
|
|
41
|
+
if (!ph) {
|
|
42
|
+
const c = Math.floor(frac * 1e6 + 0.5) / 1e6; const lo = Math.ceil(c - half) - 0; const hi = Math.floor(c + half);
|
|
43
|
+
const w = new Float64Array(hi - lo + 1); let norm = 0;
|
|
44
|
+
for (let i = lo; i <= hi; i++) { const k = weight(i - c); w[i - lo] = k; norm += k; }
|
|
45
|
+
for (let i = 0; i < w.length; i++) w[i] /= norm;
|
|
46
|
+
ph = { lo, w };
|
|
47
|
+
if (phases.size < 4096) phases.set(key, ph);
|
|
48
|
+
}
|
|
49
|
+
return ph;
|
|
50
|
+
};
|
|
36
51
|
function run(limit, out) {
|
|
37
52
|
while (centre < limit && Math.floor(centre) + half < base + buf.length) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
for (let
|
|
41
|
-
|
|
42
|
-
out.push(toS16(sum / norm));
|
|
53
|
+
const fl = Math.floor(centre); const ph = phaseOf(centre - fl);
|
|
54
|
+
const first = fl + ph.lo - base; let sum = 0;
|
|
55
|
+
for (let k = 0; k < ph.w.length; k++) { const j = first + k; if (j >= 0 && j < buf.length) sum += buf[j] * ph.w[k]; }
|
|
56
|
+
out.push(toS16(sum));
|
|
43
57
|
centre += ratio;
|
|
44
58
|
}
|
|
45
59
|
}
|
|
@@ -52,6 +52,7 @@ const POLL_MS = 1500; // while listening, and until the last line is lab
|
|
|
52
52
|
const AGENT_POLL_MS = 3000;
|
|
53
53
|
const CHUNK_SAMPLES = 16000; // one second at 16 kHz
|
|
54
54
|
const RATE = 16000;
|
|
55
|
+
const HI_RATE = 24000; // the replay is kept at this rate when the device has it (D92 as amended 2026-10-08)
|
|
55
56
|
const SEND_TRIES = 3; // a chunk that the server did not take is sent again this many times in all …
|
|
56
57
|
const SEND_BACKOFF_MS = 400; // … after 400 ms, then 1200 ms
|
|
57
58
|
const SECTIONS = [['decision', 'Decisions'], ['action', 'Next steps'], ['question', 'Open questions']];
|
|
@@ -588,7 +589,7 @@ async function openSource(kind) {
|
|
|
588
589
|
return new MediaStream(tracks);
|
|
589
590
|
}
|
|
590
591
|
async function startAudio(ctx, n, want) {
|
|
591
|
-
const a = { id: n.id, state: 'starting', sources: [], streams: [], ctx: null, started: Date.now(), clock: null, msg: null, queue: {}, buf: {}, rs: {}, lost: 0, ended: 0 };
|
|
592
|
+
const a = { id: n.id, state: 'starting', sources: [], streams: [], ctx: null, started: Date.now(), clock: null, msg: null, queue: {}, buf: {}, rs: {}, rs24: {}, buf24: {}, lost: 0, ended: 0 };
|
|
592
593
|
const opened = [];
|
|
593
594
|
// the meeting first, straight from the press: the browser lets a page share a screen only right after a click
|
|
594
595
|
for (const kind of want.slice().sort((x, y) => (x === 'meeting' ? -1 : y === 'meeting' ? 1 : 0))) {
|
|
@@ -604,17 +605,22 @@ async function startAudio(ctx, n, want) {
|
|
|
604
605
|
// the clock counts the meeting time, as the line times do: Listen again carries on from where it stopped
|
|
605
606
|
a.started = Date.parse(r.clock_from || r.recorded_from) || a.started;
|
|
606
607
|
let ac;
|
|
607
|
-
|
|
608
|
+
// the device's own rate: the 16 kHz audio for transcription and the 24 kHz audio for the replay are both made from the same blocks (D92 as amended)
|
|
609
|
+
try { ac = new AudioContext(); } catch { ac = new AudioContext({ sampleRate: RATE }); }
|
|
608
610
|
a.ctx = ac;
|
|
609
611
|
const sink = ac.createGain(); sink.gain.value = 0; sink.connect(ac.destination);
|
|
610
612
|
for (const [kind, stream] of opened) {
|
|
611
613
|
a.streams.push(stream); a.sources.push(kind); a.buf[kind] = []; a.queue[kind] = Promise.resolve();
|
|
612
614
|
const src = ac.createMediaStreamSource(stream);
|
|
613
615
|
const rs = a.rs[kind] = makeResampler(ac.sampleRate);
|
|
616
|
+
// a device slower than 24 kHz has nothing above 12 kHz to keep, so it sends 16 kHz audio only and the replay stays 16 kHz
|
|
617
|
+
const rs24 = ac.sampleRate >= HI_RATE ? (a.rs24[kind] = makeResampler(ac.sampleRate, HI_RATE)) : null;
|
|
618
|
+
a.buf24[kind] = [];
|
|
614
619
|
await openCapture(ac, src, sink, (block) => {
|
|
615
620
|
if (audio !== a) return;
|
|
616
621
|
const s = rs.push(block);
|
|
617
622
|
const b = a.buf[kind]; for (let i = 0; i < s.length; i++) b.push(s[i]);
|
|
623
|
+
if (rs24) { const h = rs24.push(block); const b24 = a.buf24[kind]; for (let i = 0; i < h.length; i++) b24.push(h[i]); }
|
|
618
624
|
if (b.length >= CHUNK_SAMPLES) sendChunk(ctx, a, kind, false);
|
|
619
625
|
});
|
|
620
626
|
for (const t of stream.getTracks()) t.addEventListener('ended', () => { if (audio !== a) return; a.ended++; if (a.ended >= a.streams.length) stopAudio(ctx); });
|
|
@@ -627,11 +633,13 @@ async function startAudio(ctx, n, want) {
|
|
|
627
633
|
function sendChunk(ctx, a, kind, final) {
|
|
628
634
|
const b = a.buf[kind] || []; a.buf[kind] = [];
|
|
629
635
|
const pcm = b64(Int16Array.from(b));
|
|
636
|
+
const b24 = a.buf24[kind] || []; a.buf24[kind] = [];
|
|
637
|
+
const pcm24 = b24.length ? b64(Int16Array.from(b24)) : undefined;
|
|
630
638
|
const seconds = b.length / RATE;
|
|
631
639
|
a.queue[kind] = a.queue[kind].then(async () => {
|
|
632
640
|
let r = null;
|
|
633
641
|
for (let tries = 0; tries < SEND_TRIES; tries++) {
|
|
634
|
-
r = await pmPost('/api/notes/audio', { id: a.id, source: kind, pcm, final });
|
|
642
|
+
r = await pmPost('/api/notes/audio', { id: a.id, source: kind, pcm, pcm24, final });
|
|
635
643
|
if (r && r.ok) return;
|
|
636
644
|
if (r && (r.status === 409 || r.status === 404)) break; // the server refused this note's audio: sending again changes nothing
|
|
637
645
|
if (tries + 1 < SEND_TRIES) await new Promise((res) => setTimeout(res, SEND_BACKOFF_MS * 3 ** tries));
|
|
@@ -656,7 +664,10 @@ async function stopAudio(ctx, { discard = false } = {}) {
|
|
|
656
664
|
try { if (a.ctx) await a.ctx.close(); } catch { /* closed */ }
|
|
657
665
|
if (discard) { ctx.setState({}); return; }
|
|
658
666
|
// the rest of what was said, then the summary once the last line is transcribed
|
|
659
|
-
for (const k of a.sources) {
|
|
667
|
+
for (const k of a.sources) {
|
|
668
|
+
const tail = a.rs[k] ? a.rs[k].flush() : []; const b = a.buf[k]; for (let i = 0; i < tail.length; i++) b.push(tail[i]);
|
|
669
|
+
const tail24 = a.rs24[k] ? a.rs24[k].flush() : []; const b24 = a.buf24[k]; for (let i = 0; i < tail24.length; i++) b24.push(tail24[i]);
|
|
670
|
+
}
|
|
660
671
|
await Promise.all(a.sources.map((k) => sendChunk(ctx, a, k, true)));
|
|
661
672
|
await pmPost('/api/notes/pause', { id: a.id });
|
|
662
673
|
ctx.setState({});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_comment": "meeting-notes Runs 1 to 10: the Notes engine and routes (notes.test.js), local Whisper, line labels and repository checks (notes-listen.test.js), the final pass after Stop and the Wispr Flow fetch (notes-final.test.js), Qwen3-ASR kept loaded (notes-qwen.test.js), and the Notes view in a browser (pm-notes-test.js), the echo canceller for the replay (notes-echo.test.js, notes-audio-quality Run 2) and the optional cleaned copy of the replay (notes-polish.test.js, Run 3), plus the note pop-up patched in place while it listens (pm-note-dock-test.js).",
|
|
2
|
+
"_comment": "meeting-notes Runs 1 to 10: the Notes engine and routes (notes.test.js), local Whisper, line labels and repository checks (notes-listen.test.js), the final pass after Stop and the Wispr Flow fetch (notes-final.test.js), Qwen3-ASR kept loaded (notes-qwen.test.js), and the Notes view in a browser (pm-notes-test.js), the echo canceller for the replay (notes-echo.test.js, notes-audio-quality Run 2) and the optional cleaned copy of the replay (notes-polish.test.js, Run 3) and the 24 kHz replay (notes-hires.test.js, Run 4), plus the note pop-up patched in place while it listens (pm-note-dock-test.js).",
|
|
3
3
|
"modules": [
|
|
4
4
|
"notes.test.js",
|
|
5
5
|
"notes-listen.test.js",
|
|
6
6
|
"notes-final.test.js",
|
|
7
7
|
"notes-qwen.test.js",
|
|
8
8
|
"notes-echo.test.js",
|
|
9
|
-
"notes-polish.test.js"
|
|
9
|
+
"notes-polish.test.js",
|
|
10
|
+
"notes-hires.test.js"
|
|
10
11
|
],
|
|
11
12
|
"panels": [
|
|
12
13
|
"pm-notes-test.js",
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"notes-qwen.test.js": 4,
|
|
21
22
|
"pm-note-dock-test.js": 20,
|
|
22
23
|
"notes-echo.test.js": 25,
|
|
23
|
-
"notes-polish.test.js": 3
|
|
24
|
+
"notes-polish.test.js": 3,
|
|
25
|
+
"notes-hires.test.js": 10
|
|
24
26
|
}
|
|
25
27
|
}
|