canvas-recorder-lib 0.6.0 → 0.7.1
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/BREAKING-CHANGES.md +6 -0
- package/README.md +37 -23
- package/dev/audio-builder.ts +69 -163
- package/dev/canvas-recorder.ts +350 -169
- package/dev/player-body.ts +8 -0
- package/dev/sound-clips.ts +3 -2
- package/dev/soundtrack.ts +442 -0
- package/dev/transcripts.ts +55 -4
- package/dev/video-clip-panel.ts +1 -1
- package/dev/voice/chirp.ts +129 -0
- package/dev/voice/folder.ts +84 -0
- package/dev/voice/voice-panel.ts +523 -0
- package/dev/voice/voice-recorder.ts +603 -0
- package/dist/dev/audio-builder.d.ts +14 -31
- package/dist/dev/audio-builder.d.ts.map +1 -1
- package/dist/dev/audio-builder.js +62 -135
- package/dist/dev/audio-builder.js.map +1 -1
- package/dist/dev/canvas-recorder.js +336 -156
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/player-body.d.ts +1 -1
- package/dist/dev/player-body.d.ts.map +1 -1
- package/dist/dev/player-body.js +8 -0
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/sound-clips.d.ts +3 -2
- package/dist/dev/sound-clips.d.ts.map +1 -1
- package/dist/dev/sound-clips.js +3 -2
- package/dist/dev/sound-clips.js.map +1 -1
- package/dist/dev/soundtrack.d.ts +115 -0
- package/dist/dev/soundtrack.d.ts.map +1 -0
- package/dist/dev/soundtrack.js +376 -0
- package/dist/dev/soundtrack.js.map +1 -0
- package/dist/dev/transcripts.d.ts +5 -0
- package/dist/dev/transcripts.d.ts.map +1 -1
- package/dist/dev/transcripts.js +50 -4
- package/dist/dev/transcripts.js.map +1 -1
- package/dist/dev/video-clip-panel.js +1 -1
- package/dist/dev/video-clip-panel.js.map +1 -1
- package/dist/dev/voice/chirp.d.ts +27 -0
- package/dist/dev/voice/chirp.d.ts.map +1 -0
- package/dist/dev/voice/chirp.js +107 -0
- package/dist/dev/voice/chirp.js.map +1 -0
- package/dist/dev/voice/folder.d.ts +18 -0
- package/dist/dev/voice/folder.d.ts.map +1 -0
- package/dist/dev/voice/folder.js +68 -0
- package/dist/dev/voice/folder.js.map +1 -0
- package/dist/dev/voice/voice-panel.d.ts +44 -0
- package/dist/dev/voice/voice-panel.d.ts.map +1 -0
- package/dist/dev/voice/voice-panel.js +428 -0
- package/dist/dev/voice/voice-panel.js.map +1 -0
- package/dist/dev/voice/voice-recorder.d.ts +141 -0
- package/dist/dev/voice/voice-recorder.d.ts.map +1 -0
- package/dist/dev/voice/voice-recorder.js +506 -0
- package/dist/dev/voice/voice-recorder.js.map +1 -0
- package/dist/src/showable.d.ts +9 -0
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.js.map +1 -1
- package/dist/src/snapshot.d.ts.map +1 -1
- package/dist/src/snapshot.js +27 -11
- package/dist/src/snapshot.js.map +1 -1
- package/package.json +1 -1
- package/src/showable.ts +9 -0
- package/src/snapshot.ts +30 -15
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { canWrite, chooseFolder, rememberedFolder } from "./folder.js";
|
|
2
|
+
import { DEFAULT_PROCESSING, supportedProcessing, VoiceRecorder, } from "./voice-recorder.js";
|
|
3
|
+
/** The meter shows −60 to 0 dBFS. */
|
|
4
|
+
const METER_FLOOR = -60;
|
|
5
|
+
/** Where your voice's peaks should land. The usual target for speech. */
|
|
6
|
+
const VOICE_TARGET_DB = -12;
|
|
7
|
+
/** Peaks louder than this count as clipping. */
|
|
8
|
+
const CLIP_DB = -1;
|
|
9
|
+
/** The bar averages the level over about this long, in seconds. Meters usually do. */
|
|
10
|
+
const METER_SECONDS = 0.3;
|
|
11
|
+
const STORAGE = {
|
|
12
|
+
processing: "voice-recorder.processing",
|
|
13
|
+
chirpLevel: "voice-recorder.chirp-level",
|
|
14
|
+
};
|
|
15
|
+
const CSS = /* css */ `
|
|
16
|
+
.vr-panel {
|
|
17
|
+
margin-top: 0.5em;
|
|
18
|
+
padding: 10px 12px;
|
|
19
|
+
border-radius: 10px;
|
|
20
|
+
border: 1px solid rgba(160, 180, 230, 0.25);
|
|
21
|
+
background: rgb(14, 18, 32);
|
|
22
|
+
color: #e6ecfa;
|
|
23
|
+
font: 13px/1.35 system-ui, sans-serif;
|
|
24
|
+
font-variant-numeric: tabular-nums;
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
gap: 7px;
|
|
28
|
+
}
|
|
29
|
+
.vr-panel.vr-recording {
|
|
30
|
+
border-color: #ff5a5f;
|
|
31
|
+
}
|
|
32
|
+
.vr-head {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: space-between;
|
|
36
|
+
font-weight: 650;
|
|
37
|
+
}
|
|
38
|
+
.vr-panel button {
|
|
39
|
+
font: inherit;
|
|
40
|
+
color: inherit;
|
|
41
|
+
background: rgba(255, 255, 255, 0.08);
|
|
42
|
+
border: 1px solid rgba(160, 180, 230, 0.25);
|
|
43
|
+
border-radius: 6px;
|
|
44
|
+
padding: 4px 10px;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
}
|
|
47
|
+
.vr-panel button:hover {
|
|
48
|
+
background: rgba(255, 255, 255, 0.16);
|
|
49
|
+
}
|
|
50
|
+
.vr-panel button:disabled {
|
|
51
|
+
opacity: 0.5;
|
|
52
|
+
cursor: default;
|
|
53
|
+
}
|
|
54
|
+
.vr-close {
|
|
55
|
+
padding: 0 7px !important;
|
|
56
|
+
font-size: 16px !important;
|
|
57
|
+
}
|
|
58
|
+
.vr-meter {
|
|
59
|
+
display: flex;
|
|
60
|
+
align-items: center;
|
|
61
|
+
gap: 8px;
|
|
62
|
+
}
|
|
63
|
+
.vr-track {
|
|
64
|
+
position: relative;
|
|
65
|
+
flex: 1;
|
|
66
|
+
height: 14px;
|
|
67
|
+
border-radius: 3px;
|
|
68
|
+
background: linear-gradient(to right, #1f6f3d 0%, #1f6f3d 75%, #7a6a10 75%, #7a6a10 93%, #7a1f22 93%);
|
|
69
|
+
overflow: hidden;
|
|
70
|
+
}
|
|
71
|
+
.vr-level {
|
|
72
|
+
position: absolute;
|
|
73
|
+
inset: 0;
|
|
74
|
+
background: linear-gradient(to right, #3ddc84 0%, #3ddc84 75%, #f2d14c 75%, #f2d14c 93%, #ff5a5f 93%);
|
|
75
|
+
}
|
|
76
|
+
.vr-peak {
|
|
77
|
+
position: absolute;
|
|
78
|
+
top: 0;
|
|
79
|
+
bottom: 0;
|
|
80
|
+
width: 2px;
|
|
81
|
+
background: #fff;
|
|
82
|
+
}
|
|
83
|
+
.vr-mark {
|
|
84
|
+
position: absolute;
|
|
85
|
+
top: -2px;
|
|
86
|
+
bottom: -2px;
|
|
87
|
+
width: 0;
|
|
88
|
+
border-left: 2px dashed;
|
|
89
|
+
}
|
|
90
|
+
.vr-mark.vr-voice {
|
|
91
|
+
border-color: #7fd0ff;
|
|
92
|
+
}
|
|
93
|
+
.vr-mark.vr-sound {
|
|
94
|
+
border-color: #ff9df2;
|
|
95
|
+
}
|
|
96
|
+
.vr-db {
|
|
97
|
+
width: 62px;
|
|
98
|
+
text-align: right;
|
|
99
|
+
}
|
|
100
|
+
.vr-clipping .vr-db {
|
|
101
|
+
color: #ff5a5f;
|
|
102
|
+
font-weight: 700;
|
|
103
|
+
}
|
|
104
|
+
.vr-legend {
|
|
105
|
+
display: flex;
|
|
106
|
+
gap: 12px;
|
|
107
|
+
font-size: 11px;
|
|
108
|
+
color: #9aa7c4;
|
|
109
|
+
}
|
|
110
|
+
.vr-legend span::before {
|
|
111
|
+
content: "";
|
|
112
|
+
display: inline-block;
|
|
113
|
+
width: 10px;
|
|
114
|
+
margin-right: 4px;
|
|
115
|
+
vertical-align: middle;
|
|
116
|
+
border-top: 2px dashed;
|
|
117
|
+
}
|
|
118
|
+
.vr-legend .vr-voice::before {
|
|
119
|
+
border-color: #7fd0ff;
|
|
120
|
+
}
|
|
121
|
+
.vr-legend .vr-sound::before {
|
|
122
|
+
border-color: #ff9df2;
|
|
123
|
+
}
|
|
124
|
+
.vr-choice {
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
gap: 6px;
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
}
|
|
130
|
+
.vr-got {
|
|
131
|
+
margin-left: auto;
|
|
132
|
+
font-size: 11px;
|
|
133
|
+
color: #9aa7c4;
|
|
134
|
+
}
|
|
135
|
+
.vr-got.vr-mismatch {
|
|
136
|
+
color: #ff9a5f;
|
|
137
|
+
}
|
|
138
|
+
.vr-small {
|
|
139
|
+
font-size: 11px;
|
|
140
|
+
color: #9aa7c4;
|
|
141
|
+
overflow: hidden;
|
|
142
|
+
text-overflow: ellipsis;
|
|
143
|
+
white-space: nowrap;
|
|
144
|
+
}
|
|
145
|
+
.vr-buttons {
|
|
146
|
+
display: flex;
|
|
147
|
+
align-items: center;
|
|
148
|
+
gap: 8px;
|
|
149
|
+
}
|
|
150
|
+
.vr-record {
|
|
151
|
+
min-width: 92px;
|
|
152
|
+
}
|
|
153
|
+
.vr-recording .vr-record {
|
|
154
|
+
background: rgba(255, 90, 95, 0.3) !important;
|
|
155
|
+
border-color: #ff5a5f !important;
|
|
156
|
+
}
|
|
157
|
+
.vr-past-end {
|
|
158
|
+
color: #ff9a5f;
|
|
159
|
+
}
|
|
160
|
+
.vr-time {
|
|
161
|
+
margin-left: auto;
|
|
162
|
+
font-size: 15px;
|
|
163
|
+
}
|
|
164
|
+
.vr-recording .vr-time::before {
|
|
165
|
+
content: "● ";
|
|
166
|
+
color: #ff5a5f;
|
|
167
|
+
}
|
|
168
|
+
.vr-status:empty {
|
|
169
|
+
display: none;
|
|
170
|
+
}
|
|
171
|
+
.vr-status.vr-warning {
|
|
172
|
+
color: #ff9a5f;
|
|
173
|
+
}
|
|
174
|
+
`;
|
|
175
|
+
function addStyles() {
|
|
176
|
+
if (!document.getElementById("vr-styles")) {
|
|
177
|
+
const style = document.createElement("style");
|
|
178
|
+
style.id = "vr-styles";
|
|
179
|
+
style.textContent = CSS;
|
|
180
|
+
document.head.append(style);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** Make an element, with a class and some content. */
|
|
184
|
+
function element(tag, className = "", ...content) {
|
|
185
|
+
const result = document.createElement(tag);
|
|
186
|
+
result.className = className;
|
|
187
|
+
result.append(...content);
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
const toDb = (level) => 20 * Math.log10(Math.max(level, 1e-6));
|
|
191
|
+
/** Where on the meter, 0 to 1. */
|
|
192
|
+
const meterFraction = (db) => Math.min(1, Math.max(0, (db - METER_FLOOR) / -METER_FLOOR));
|
|
193
|
+
const formatDb = (db) => db <= METER_FLOOR ? "−∞ dB" : `${db.toFixed(1).replace("-", "−")} dB`;
|
|
194
|
+
function loadChoices() {
|
|
195
|
+
try {
|
|
196
|
+
const saved = localStorage.getItem(STORAGE.processing);
|
|
197
|
+
return saved ? JSON.parse(saved) : { ...DEFAULT_PROCESSING };
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return { ...DEFAULT_PROCESSING };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Open the panel and turn on the mic. Call this from a click, so the browser lets audio start.
|
|
205
|
+
* The browser asks for permission to use the mic the first time.
|
|
206
|
+
*/
|
|
207
|
+
export async function openVoicePanel(options) {
|
|
208
|
+
addStyles();
|
|
209
|
+
const panel = element("div", "vr-panel");
|
|
210
|
+
const close = element("button", "vr-close", "×");
|
|
211
|
+
close.title = "Close record mode, and turn the mic off";
|
|
212
|
+
const level = element("div", "vr-level");
|
|
213
|
+
const peak = element("div", "vr-peak");
|
|
214
|
+
const voiceMark = element("div", "vr-mark vr-voice");
|
|
215
|
+
const soundMark = element("div", "vr-mark vr-sound");
|
|
216
|
+
const db = element("span", "vr-db", formatDb(-Infinity));
|
|
217
|
+
const meter = element("div", "vr-meter", element("div", "vr-track", level, peak, voiceMark, soundMark), db);
|
|
218
|
+
const legend = element("div", "vr-legend", element("span", "vr-voice", "voice target"), element("span", "vr-sound", "chirp, last time"));
|
|
219
|
+
const choicesBox = element("div");
|
|
220
|
+
const micLine = element("div", "vr-small", "Turning on the mic…");
|
|
221
|
+
const folderName = element("b", "", "…");
|
|
222
|
+
const changeFolder = element("button", "", "Change…");
|
|
223
|
+
changeFolder.style.padding = "0 6px";
|
|
224
|
+
const folderLine = element("div", "vr-small", "Folder: ", folderName, " ", changeFolder);
|
|
225
|
+
const record = element("button", "vr-record", "● Record");
|
|
226
|
+
record.title =
|
|
227
|
+
"Play the chirp, then record your voice while the video plays. Pause the video to stop. " +
|
|
228
|
+
"Each seek starts a new sound clip.";
|
|
229
|
+
const pastEnd = element("span", "vr-past-end");
|
|
230
|
+
const time = element("span", "vr-time", "0:00");
|
|
231
|
+
const status = element("div", "vr-status");
|
|
232
|
+
panel.append(element("div", "vr-head", element("span", "", "🎙 Record mode"), close), meter, legend, choicesBox, micLine, folderLine, element("div", "vr-buttons", record, pastEnd, time), status);
|
|
233
|
+
options.parent.append(panel);
|
|
234
|
+
const say = (text, warning = false) => {
|
|
235
|
+
status.textContent = text;
|
|
236
|
+
status.classList.toggle("vr-warning", warning);
|
|
237
|
+
};
|
|
238
|
+
const placeMark = (mark, value) => {
|
|
239
|
+
mark.hidden = value === undefined;
|
|
240
|
+
mark.style.left = `${meterFraction(value ?? 0) * 100}%`;
|
|
241
|
+
};
|
|
242
|
+
placeMark(voiceMark, VOICE_TARGET_DB);
|
|
243
|
+
const savedChirpLevel = Number(localStorage.getItem(STORAGE.chirpLevel));
|
|
244
|
+
placeMark(soundMark, Number.isFinite(savedChirpLevel) && savedChirpLevel < 0 ? savedChirpLevel : undefined);
|
|
245
|
+
const closed = () => {
|
|
246
|
+
panel.remove();
|
|
247
|
+
options.onClose?.();
|
|
248
|
+
};
|
|
249
|
+
// The folder. Independent of the mic, so it shows even if the mic is refused.
|
|
250
|
+
// Not awaited: the mic should start while this click still counts as a click.
|
|
251
|
+
let folder;
|
|
252
|
+
const showFolder = () => {
|
|
253
|
+
folderName.textContent = folder ? folder.name || "browser storage" : "not chosen yet";
|
|
254
|
+
};
|
|
255
|
+
void rememberedFolder().then((remembered) => {
|
|
256
|
+
// ??=, in case Change… or setFolder() got here first.
|
|
257
|
+
folder ??= remembered;
|
|
258
|
+
showFolder();
|
|
259
|
+
});
|
|
260
|
+
changeFolder.addEventListener("click", async () => {
|
|
261
|
+
changeFolder.blur();
|
|
262
|
+
try {
|
|
263
|
+
folder = (await chooseFolder()) ?? folder;
|
|
264
|
+
showFolder();
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
say(error instanceof Error ? error.message : String(error), true);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
let recorder;
|
|
271
|
+
try {
|
|
272
|
+
recorder = await VoiceRecorder.open(options.context, loadChoices());
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
micLine.textContent = "No mic.";
|
|
276
|
+
say(`Couldn't turn on the mic: ${error instanceof Error ? error.message : error}`, true);
|
|
277
|
+
// Leave the panel up, so you can read why.
|
|
278
|
+
close.addEventListener("click", closed);
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
// The level meter. The bar is the average level, and the line is the peak, held for a moment.
|
|
282
|
+
let held = -Infinity;
|
|
283
|
+
let heldAt = 0;
|
|
284
|
+
let lastLevel = performance.now();
|
|
285
|
+
let clippedAt = -Infinity;
|
|
286
|
+
let meanSquare = 0;
|
|
287
|
+
recorder.onLevel = (peakLevel, rms) => {
|
|
288
|
+
const now = performance.now();
|
|
289
|
+
const seconds = (now - lastLevel) / 1000;
|
|
290
|
+
lastLevel = now;
|
|
291
|
+
meanSquare += (rms * rms - meanSquare) * (1 - Math.exp(-seconds / METER_SECONDS));
|
|
292
|
+
const peakDb = toDb(peakLevel);
|
|
293
|
+
if (peakDb >= held) {
|
|
294
|
+
held = peakDb;
|
|
295
|
+
heldAt = now;
|
|
296
|
+
}
|
|
297
|
+
else if (now - heldAt > 1000) {
|
|
298
|
+
// Hold the peak for a second, then let it fall 20 dB a second.
|
|
299
|
+
held = Math.max(peakDb, held - 20 * seconds);
|
|
300
|
+
}
|
|
301
|
+
if (peakDb >= CLIP_DB) {
|
|
302
|
+
clippedAt = now;
|
|
303
|
+
}
|
|
304
|
+
level.style.clipPath = `inset(0 ${(1 - meterFraction(toDb(Math.sqrt(meanSquare)))) * 100}% 0 0)`;
|
|
305
|
+
peak.style.left = `calc(${meterFraction(held) * 100}% - 1px)`;
|
|
306
|
+
db.textContent = formatDb(held);
|
|
307
|
+
panel.classList.toggle("vr-clipping", now - clippedAt < 2000);
|
|
308
|
+
};
|
|
309
|
+
// The voice processing checkboxes, and what the mic actually got.
|
|
310
|
+
const gotLabels = new Map();
|
|
311
|
+
const showSettings = () => {
|
|
312
|
+
const actual = recorder.actualSettings();
|
|
313
|
+
const requested = loadChoices();
|
|
314
|
+
for (const [name, got] of gotLabels) {
|
|
315
|
+
const value = actual[name];
|
|
316
|
+
got.textContent = value === undefined ? "got: ?" : `got: ${value ? "on" : "off"}`;
|
|
317
|
+
got.classList.toggle("vr-mismatch", value !== undefined && value !== (requested[name] ?? false));
|
|
318
|
+
}
|
|
319
|
+
const rate = actual.sampleRate ? ` · ${Number(actual.sampleRate) / 1000} kHz` : "";
|
|
320
|
+
micLine.textContent = `Mic: ${recorder.micName || "unknown"}${rate}`;
|
|
321
|
+
};
|
|
322
|
+
for (const { name, label, help } of supportedProcessing()) {
|
|
323
|
+
const box = element("input");
|
|
324
|
+
box.type = "checkbox";
|
|
325
|
+
box.checked = loadChoices()[name] ?? false;
|
|
326
|
+
box.setAttribute("aria-label", label);
|
|
327
|
+
const got = element("span", "vr-got");
|
|
328
|
+
gotLabels.set(name, got);
|
|
329
|
+
const row = element("label", "vr-choice", box, label, got);
|
|
330
|
+
row.title = help;
|
|
331
|
+
// "change", not "input": each one reopens the mic, so once per click is right.
|
|
332
|
+
box.addEventListener("change", async () => {
|
|
333
|
+
box.blur();
|
|
334
|
+
localStorage.setItem(STORAGE.processing, JSON.stringify({ ...loadChoices(), [name]: box.checked }));
|
|
335
|
+
box.disabled = true;
|
|
336
|
+
try {
|
|
337
|
+
await recorder.setProcessing(name, box.checked);
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
say(`Couldn't change ${label.toLowerCase()}: ${error instanceof Error ? error.message : error}`, true);
|
|
341
|
+
}
|
|
342
|
+
box.disabled = false;
|
|
343
|
+
showSettings();
|
|
344
|
+
});
|
|
345
|
+
choicesBox.append(row);
|
|
346
|
+
}
|
|
347
|
+
showSettings();
|
|
348
|
+
// What we heard of the chirp.
|
|
349
|
+
recorder.onHeard = (result) => {
|
|
350
|
+
if (result.roundTripMs === undefined) {
|
|
351
|
+
say(`Didn't hear the chirp. Are the speakers off, or are you using headphones? ` +
|
|
352
|
+
`Using the last delay measured, ${recorder.micDelayMs.toFixed(0)} ms.`, true);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
localStorage.setItem(STORAGE.chirpLevel, String(result.peakDb));
|
|
356
|
+
placeMark(soundMark, result.peakDb);
|
|
357
|
+
say(`Heard the chirp. Round trip ${result.roundTripMs.toFixed(1)} ms, at ${formatDb(result.peakDb)}. ` +
|
|
358
|
+
`Mic delay ${recorder.micDelayMs.toFixed(0)} ms.`);
|
|
359
|
+
};
|
|
360
|
+
// ● Record and ■ Stop.
|
|
361
|
+
let started = 0;
|
|
362
|
+
let clock = 0;
|
|
363
|
+
const showTime = () => {
|
|
364
|
+
const seconds = Math.floor((performance.now() - started) / 1000);
|
|
365
|
+
time.textContent = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
|
366
|
+
};
|
|
367
|
+
/** What the button says: ■ Stop. That's what a click does, even if the two ever disagree. */
|
|
368
|
+
let showingStop = false;
|
|
369
|
+
record.addEventListener("click", async () => {
|
|
370
|
+
record.blur();
|
|
371
|
+
if (showingStop) {
|
|
372
|
+
options.onStop();
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
record.disabled = true;
|
|
376
|
+
try {
|
|
377
|
+
if (!folder || !(await canWrite(folder, true))) {
|
|
378
|
+
folder = await chooseFolder();
|
|
379
|
+
showFolder();
|
|
380
|
+
}
|
|
381
|
+
if (!folder) {
|
|
382
|
+
say("Choose a folder for the recordings first.", true);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
say("");
|
|
386
|
+
await options.onRecord(recorder, folder);
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
say(error instanceof Error ? error.message : String(error), true);
|
|
390
|
+
}
|
|
391
|
+
finally {
|
|
392
|
+
record.disabled = false;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
const result = {
|
|
396
|
+
recorder,
|
|
397
|
+
setRecording(on) {
|
|
398
|
+
showingStop = on;
|
|
399
|
+
panel.classList.toggle("vr-recording", on);
|
|
400
|
+
record.textContent = on ? "■ Stop" : "● Record";
|
|
401
|
+
window.clearInterval(clock);
|
|
402
|
+
if (on) {
|
|
403
|
+
started = performance.now();
|
|
404
|
+
clock = window.setInterval(showTime, 250);
|
|
405
|
+
showTime();
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
pastEnd.textContent = "";
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
setPastEnd(ms) {
|
|
412
|
+
pastEnd.textContent = ms === undefined ? "" : `+${(ms / 1000).toFixed(1)} s past the end`;
|
|
413
|
+
},
|
|
414
|
+
say,
|
|
415
|
+
setFolder(newFolder) {
|
|
416
|
+
folder = newFolder;
|
|
417
|
+
showFolder();
|
|
418
|
+
},
|
|
419
|
+
async close() {
|
|
420
|
+
window.clearInterval(clock);
|
|
421
|
+
await recorder.close();
|
|
422
|
+
closed();
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
close.addEventListener("click", () => void result.close());
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
//# sourceMappingURL=voice-panel.js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;KACF,CAAC;IACF,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC3D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The voice recorder's engine: the mic, the files, and the chirp. No user interface; see
|
|
3
|
+
* voice-panel.ts. Nothing here knows about the player, except that it shares the player's
|
|
4
|
+
* AudioContext.
|
|
5
|
+
*
|
|
6
|
+
* Sharing the AudioContext means sharing its clock, the one the video plays by. An AudioWorklet
|
|
7
|
+
* copies the mic's samples, and says exactly which frame of that clock each one belongs to. So a
|
|
8
|
+
* clip's place in the video is exact, with no clocks to match up.
|
|
9
|
+
*
|
|
10
|
+
* - A **session** runs from ● Record to the stop. It starts with the chirp.
|
|
11
|
+
* - A session holds one or more **clips**. The player starts one whenever the video starts moving,
|
|
12
|
+
* and ends it whenever the video stops or jumps. So a seek ends one clip and starts the next.
|
|
13
|
+
* - Each clip is its own WAV file (32-bit float, mono, 48 kHz), written as it goes, and kept in memory
|
|
14
|
+
* too. The file holds a little more than the clip at each end: the chirp, or what came between
|
|
15
|
+
* two clips, at the start, and {@link TAIL_S} at the end. The clip's trim hides the extra.
|
|
16
|
+
*
|
|
17
|
+
* Copied from riemann-surfaces-3d's src/recording/voice-recorder.ts (9bbe2f9), without the log or
|
|
18
|
+
* the Stop and Marker sounds. See development-plans/voice-recording.md.
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
/** The browser's voice processing. Each one is a checkbox. */
|
|
22
|
+
export declare const PROCESSING: readonly [{
|
|
23
|
+
readonly name: "echoCancellation";
|
|
24
|
+
readonly label: "Echo cancellation";
|
|
25
|
+
readonly help: "For calls. Removes whatever your own speakers are playing. It would erase the chirp.";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "noiseSuppression";
|
|
28
|
+
readonly label: "Noise suppression";
|
|
29
|
+
readonly help: "Removes steady background noise, like fans and hum, and some clicks.";
|
|
30
|
+
}, {
|
|
31
|
+
readonly name: "autoGainControl";
|
|
32
|
+
readonly label: "Automatic gain control";
|
|
33
|
+
readonly help: "Turns the volume up and down to keep your voice level. It turns background noise up during your pauses.";
|
|
34
|
+
}, {
|
|
35
|
+
readonly name: "voiceIsolation";
|
|
36
|
+
readonly label: "Voice isolation";
|
|
37
|
+
readonly help: "Only in newer browsers. Tries to keep your voice and nothing else.";
|
|
38
|
+
}];
|
|
39
|
+
export type ProcessingName = (typeof PROCESSING)[number]["name"];
|
|
40
|
+
export type ProcessingChoices = Partial<Record<ProcessingName, boolean>>;
|
|
41
|
+
/** Noise suppression on, the rest off. From riemann's feedback: "The helicopter is gone." */
|
|
42
|
+
export declare const DEFAULT_PROCESSING: ProcessingChoices;
|
|
43
|
+
/** The parts of PROCESSING that this browser offers. */
|
|
44
|
+
export declare function supportedProcessing(): ({
|
|
45
|
+
readonly name: "echoCancellation";
|
|
46
|
+
readonly label: "Echo cancellation";
|
|
47
|
+
readonly help: "For calls. Removes whatever your own speakers are playing. It would erase the chirp.";
|
|
48
|
+
} | {
|
|
49
|
+
readonly name: "noiseSuppression";
|
|
50
|
+
readonly label: "Noise suppression";
|
|
51
|
+
readonly help: "Removes steady background noise, like fans and hum, and some clicks.";
|
|
52
|
+
} | {
|
|
53
|
+
readonly name: "autoGainControl";
|
|
54
|
+
readonly label: "Automatic gain control";
|
|
55
|
+
readonly help: "Turns the volume up and down to keep your voice level. It turns background noise up during your pauses.";
|
|
56
|
+
} | {
|
|
57
|
+
readonly name: "voiceIsolation";
|
|
58
|
+
readonly label: "Voice isolation";
|
|
59
|
+
readonly help: "Only in newer browsers. Tries to keep your voice and nothing else.";
|
|
60
|
+
})[];
|
|
61
|
+
export type HeardResult = {
|
|
62
|
+
/** Undefined if the chirp wasn't found: speakers off, or headphones. */
|
|
63
|
+
roundTripMs?: number;
|
|
64
|
+
match: number;
|
|
65
|
+
peakDb: number;
|
|
66
|
+
};
|
|
67
|
+
/** A finished clip: its file, and the part of the file that goes in the video. */
|
|
68
|
+
export type RecordedClip = {
|
|
69
|
+
/** The file's `local:` URL. */
|
|
70
|
+
readonly url: string;
|
|
71
|
+
/** The whole file, mono, at {@link SAMPLE_RATE}. For `Soundtrack.provide()`. */
|
|
72
|
+
readonly buffer: AudioBuffer;
|
|
73
|
+
/** Where in the file the clip starts, in ms. */
|
|
74
|
+
readonly trimMs: number;
|
|
75
|
+
/** How long the clip is, in ms. */
|
|
76
|
+
readonly lengthMs: number;
|
|
77
|
+
};
|
|
78
|
+
/** The clip being recorded now, for the live waveform. */
|
|
79
|
+
export type LiveClip = {
|
|
80
|
+
/** The file so far. It's longer than the recording: it grows by doubling. */
|
|
81
|
+
readonly buffer: AudioBuffer;
|
|
82
|
+
/** Where in `buffer` the clip starts, in ms. */
|
|
83
|
+
readonly trimMs: number;
|
|
84
|
+
/** How long the clip is so far, in ms. */
|
|
85
|
+
readonly lengthMs: number;
|
|
86
|
+
};
|
|
87
|
+
export declare class VoiceRecorder {
|
|
88
|
+
#private;
|
|
89
|
+
readonly context: AudioContext;
|
|
90
|
+
/** How long the mic and the OS take to deliver a sound, in ms. Measured by the chirp. */
|
|
91
|
+
micDelayMs: number;
|
|
92
|
+
/** Called for each block of audio, about 23 times a second, with levels from 0 to 1. */
|
|
93
|
+
onLevel?: (peak: number, rms: number) => void;
|
|
94
|
+
/** Called when the chirp is found in the recording, or isn't. */
|
|
95
|
+
onHeard?: (result: HeardResult) => void;
|
|
96
|
+
private constructor();
|
|
97
|
+
/**
|
|
98
|
+
* Turn on the mic. Call this from a click, so the browser lets the audio start.
|
|
99
|
+
* The browser asks for permission to use the mic the first time.
|
|
100
|
+
*/
|
|
101
|
+
static open(context: AudioContext, choices: ProcessingChoices): Promise<VoiceRecorder>;
|
|
102
|
+
/** What the mic actually got. The browser can quietly ignore a request. */
|
|
103
|
+
actualSettings(): Record<string, unknown>;
|
|
104
|
+
/** The mic's name, like "MacBook Pro Microphone". */
|
|
105
|
+
get micName(): string;
|
|
106
|
+
/**
|
|
107
|
+
* Turn one kind of voice processing on or off. Works in the middle of a recording. First try
|
|
108
|
+
* changing the mic that's already open. If the browser won't, open the mic again. The recording
|
|
109
|
+
* keeps going, on the same clock, with maybe a moment of silence.
|
|
110
|
+
*/
|
|
111
|
+
setProcessing(name: ProcessingName, on: boolean): Promise<void>;
|
|
112
|
+
/** True from {@link start} to {@link stop}. */
|
|
113
|
+
get recording(): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Start a session: play the chirp, and start recording.
|
|
116
|
+
* Resolves a moment after the chirp, when the video should start.
|
|
117
|
+
*
|
|
118
|
+
* @param prefix The start of each file's name, usually the video's name.
|
|
119
|
+
*/
|
|
120
|
+
start(folder: FileSystemDirectoryHandle, prefix: string): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* The video started moving at `contextTime`, on the AudioContext's clock.
|
|
123
|
+
* Resolves when the clip's file is finished and on the `local:` list: {@link TAIL_S} after
|
|
124
|
+
* {@link endClip}. Does nothing (and never resolves) outside a session.
|
|
125
|
+
*/
|
|
126
|
+
beginClip(contextTime: number): Promise<RecordedClip>;
|
|
127
|
+
/** The video stopped or jumped at `contextTime`. Does nothing if no clip is being recorded. */
|
|
128
|
+
endClip(contextTime: number): void;
|
|
129
|
+
/** The clip being recorded now, if there is one. */
|
|
130
|
+
liveClip(): LiveClip | undefined;
|
|
131
|
+
/** End the session. Any clip ends now; its file finishes {@link TAIL_S} later. */
|
|
132
|
+
stop(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Finish every file now, without waiting for the tails. For a page that's closing.
|
|
135
|
+
* Each write still has to reach the disk, so this may not finish in time.
|
|
136
|
+
*/
|
|
137
|
+
flush(): void;
|
|
138
|
+
/** Turn off the mic. Stops recording first, and waits a little for the files to finish. */
|
|
139
|
+
close(): Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=voice-recorder.d.ts.map
|
|
@@ -0,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