canvas-recorder-lib 0.7.0 → 0.7.2
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/README.md +38 -8
- package/dev/audio-builder.ts +5 -1
- package/dev/canvas-recorder.css +15 -4
- package/dev/canvas-recorder.ts +276 -88
- package/dev/delay-files.ts +1 -1
- package/dev/format-editor.ts +7 -2
- package/dev/fourier-panel.ts +11 -3
- package/dev/handwriting-panel.ts +14 -9
- package/dev/local-file-row.ts +12 -5
- package/dev/multi-text-dialog.ts +15 -6
- package/dev/multi-text-panel.ts +6 -2
- package/dev/player-body.ts +4 -0
- package/dev/schedule-helpers.ts +11 -4
- package/dev/sound-clips.ts +4 -1
- package/dev/soundtrack.ts +52 -13
- package/dev/split-dialog.ts +49 -19
- package/dev/static-image-panel.ts +17 -5
- package/dev/synced-file.ts +4 -5
- package/dev/timeline-display.ts +152 -50
- package/dev/transcribe-core.ts +48 -17
- package/dev/transcribe-worker.ts +20 -9
- package/dev/transcript-align.ts +95 -20
- package/dev/transcript-export.ts +18 -7
- package/dev/transcript-view.ts +78 -22
- package/dev/transcripts.ts +97 -26
- package/dev/video-clip-panel.ts +64 -18
- package/dev/voice/chirp.ts +21 -5
- package/dev/voice/folder.ts +22 -7
- package/dev/voice/voice-panel.ts +61 -27
- package/dev/voice/voice-recorder.ts +74 -18
- package/dist/dev/audio-builder.js.map +1 -1
- package/dist/dev/canvas-recorder.css +15 -4
- package/dist/dev/canvas-recorder.js +185 -48
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/format-editor.d.ts.map +1 -1
- package/dist/dev/format-editor.js.map +1 -1
- package/dist/dev/fourier-panel.d.ts.map +1 -1
- package/dist/dev/fourier-panel.js.map +1 -1
- package/dist/dev/handwriting-panel.d.ts.map +1 -1
- package/dist/dev/handwriting-panel.js +10 -8
- package/dist/dev/handwriting-panel.js.map +1 -1
- package/dist/dev/local-file-row.d.ts.map +1 -1
- package/dist/dev/local-file-row.js +12 -4
- package/dist/dev/local-file-row.js.map +1 -1
- package/dist/dev/multi-text-dialog.d.ts.map +1 -1
- package/dist/dev/multi-text-dialog.js +4 -2
- package/dist/dev/multi-text-dialog.js.map +1 -1
- package/dist/dev/multi-text-panel.d.ts.map +1 -1
- package/dist/dev/multi-text-panel.js +2 -1
- package/dist/dev/multi-text-panel.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 +4 -0
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/schedule-helpers.d.ts.map +1 -1
- package/dist/dev/schedule-helpers.js +4 -1
- package/dist/dev/schedule-helpers.js.map +1 -1
- package/dist/dev/sound-clips.d.ts.map +1 -1
- package/dist/dev/sound-clips.js.map +1 -1
- package/dist/dev/soundtrack.d.ts +12 -0
- package/dist/dev/soundtrack.d.ts.map +1 -1
- package/dist/dev/soundtrack.js +42 -9
- package/dist/dev/soundtrack.js.map +1 -1
- package/dist/dev/split-dialog.d.ts.map +1 -1
- package/dist/dev/split-dialog.js +17 -10
- package/dist/dev/split-dialog.js.map +1 -1
- package/dist/dev/static-image-panel.d.ts.map +1 -1
- package/dist/dev/static-image-panel.js +7 -3
- package/dist/dev/static-image-panel.js.map +1 -1
- package/dist/dev/synced-file.d.ts.map +1 -1
- package/dist/dev/synced-file.js.map +1 -1
- package/dist/dev/timeline-display.d.ts.map +1 -1
- package/dist/dev/timeline-display.js +62 -17
- package/dist/dev/timeline-display.js.map +1 -1
- package/dist/dev/transcribe-core.d.ts.map +1 -1
- package/dist/dev/transcribe-core.js +13 -3
- package/dist/dev/transcribe-core.js.map +1 -1
- package/dist/dev/transcribe-worker.d.ts.map +1 -1
- package/dist/dev/transcribe-worker.js +9 -3
- package/dist/dev/transcribe-worker.js.map +1 -1
- package/dist/dev/transcript-align.d.ts.map +1 -1
- package/dist/dev/transcript-align.js +52 -9
- package/dist/dev/transcript-align.js.map +1 -1
- package/dist/dev/transcript-export.d.ts.map +1 -1
- package/dist/dev/transcript-export.js +10 -4
- package/dist/dev/transcript-export.js.map +1 -1
- package/dist/dev/transcript-view.d.ts +2 -0
- package/dist/dev/transcript-view.d.ts.map +1 -1
- package/dist/dev/transcript-view.js +32 -11
- package/dist/dev/transcript-view.js.map +1 -1
- package/dist/dev/transcripts.d.ts +5 -0
- package/dist/dev/transcripts.d.ts.map +1 -1
- package/dist/dev/transcripts.js +54 -6
- package/dist/dev/transcripts.js.map +1 -1
- package/dist/dev/video-clip-panel.d.ts.map +1 -1
- package/dist/dev/video-clip-panel.js +25 -8
- package/dist/dev/video-clip-panel.js.map +1 -1
- package/dist/dev/voice/chirp.d.ts.map +1 -1
- package/dist/dev/voice/chirp.js +5 -1
- package/dist/dev/voice/chirp.js.map +1 -1
- package/dist/dev/voice/folder.d.ts.map +1 -1
- package/dist/dev/voice/folder.js +1 -1
- package/dist/dev/voice/folder.js.map +1 -1
- package/dist/dev/voice/voice-panel.d.ts.map +1 -1
- package/dist/dev/voice/voice-panel.js +42 -23
- package/dist/dev/voice/voice-panel.js.map +1 -1
- package/dist/dev/voice/voice-recorder.d.ts.map +1 -1
- package/dist/dev/voice/voice-recorder.js +34 -9
- package/dist/dev/voice/voice-recorder.js.map +1 -1
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js.map +1 -1
- package/dist/src/corner-rounder.d.ts.map +1 -1
- package/dist/src/corner-rounder.js +1 -1
- package/dist/src/corner-rounder.js.map +1 -1
- package/dist/src/local-files.d.ts.map +1 -1
- package/dist/src/local-files.js +5 -2
- package/dist/src/local-files.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts +7 -0
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +8 -1
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +12 -4
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/image.d.ts.map +1 -1
- package/dist/src/slide-components/image.js +1 -1
- package/dist/src/slide-components/image.js.map +1 -1
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +1 -1
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/rectangle.d.ts.map +1 -1
- package/dist/src/slide-components/rectangle.js +1 -1
- package/dist/src/slide-components/rectangle.js.map +1 -1
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/serialize.d.ts.map +1 -1
- package/dist/src/slide-components/serialize.js +2 -1
- package/dist/src/slide-components/serialize.js.map +1 -1
- package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/split-video-clip.js +4 -1
- package/dist/src/slide-components/split-video-clip.js.map +1 -1
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +7 -4
- package/dist/src/slide-components/video-clip.js.map +1 -1
- package/dist/src/slide-components/video-info.d.ts.map +1 -1
- package/dist/src/slide-components/video-info.js.map +1 -1
- package/dist/src/slow-image-sources.d.ts.map +1 -1
- package/dist/src/slow-image-sources.js +1 -1
- package/dist/src/slow-image-sources.js.map +1 -1
- package/dist/src/snapshot.d.ts.map +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot.js.map +1 -1
- package/dist/src/utility.d.ts.map +1 -1
- package/dist/src/utility.js +1 -3
- package/dist/src/utility.js.map +1 -1
- package/lib/main-control.ts +3 -1
- package/package.json +4 -1
- package/src/corner-rounder.ts +5 -12
- package/src/glib/letters-base.ts +1 -1
- package/src/local-files.ts +19 -6
- package/src/peano-fourier/fourier-shared.ts +8 -1
- package/src/slide-components/fourier.ts +32 -10
- package/src/slide-components/image.ts +4 -1
- package/src/slide-components/in-parallel.ts +1 -2
- package/src/slide-components/multi-text.ts +17 -4
- package/src/slide-components/rectangle.ts +4 -1
- package/src/slide-components/registry.ts +1 -1
- package/src/slide-components/serialize.ts +4 -1
- package/src/slide-components/split-video-clip.ts +4 -1
- package/src/slide-components/video-clip.ts +21 -8
- package/src/slide-components/video-info.ts +4 -1
- package/src/slow-image-sources.ts +5 -1
- package/src/snapshot.ts +13 -4
- package/src/utility.ts +70 -33
package/dev/transcript-align.ts
CHANGED
|
@@ -78,11 +78,39 @@ export type RoughWord = {
|
|
|
78
78
|
// MARK: Words to letters
|
|
79
79
|
|
|
80
80
|
const ONES = [
|
|
81
|
-
"ZERO",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
81
|
+
"ZERO",
|
|
82
|
+
"ONE",
|
|
83
|
+
"TWO",
|
|
84
|
+
"THREE",
|
|
85
|
+
"FOUR",
|
|
86
|
+
"FIVE",
|
|
87
|
+
"SIX",
|
|
88
|
+
"SEVEN",
|
|
89
|
+
"EIGHT",
|
|
90
|
+
"NINE",
|
|
91
|
+
"TEN",
|
|
92
|
+
"ELEVEN",
|
|
93
|
+
"TWELVE",
|
|
94
|
+
"THIRTEEN",
|
|
95
|
+
"FOURTEEN",
|
|
96
|
+
"FIFTEEN",
|
|
97
|
+
"SIXTEEN",
|
|
98
|
+
"SEVENTEEN",
|
|
99
|
+
"EIGHTEEN",
|
|
100
|
+
"NINETEEN",
|
|
101
|
+
];
|
|
102
|
+
const TENS = [
|
|
103
|
+
"",
|
|
104
|
+
"",
|
|
105
|
+
"TWENTY",
|
|
106
|
+
"THIRTY",
|
|
107
|
+
"FORTY",
|
|
108
|
+
"FIFTY",
|
|
109
|
+
"SIXTY",
|
|
110
|
+
"SEVENTY",
|
|
111
|
+
"EIGHTY",
|
|
112
|
+
"NINETY",
|
|
84
113
|
];
|
|
85
|
-
const TENS = ["", "", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"];
|
|
86
114
|
|
|
87
115
|
/**
|
|
88
116
|
* A whole number as English words, the way it's usually said: 1981 is
|
|
@@ -92,7 +120,8 @@ const TENS = ["", "", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY",
|
|
|
92
120
|
export function spellNumber(n: number): string {
|
|
93
121
|
if (!Number.isInteger(n) || n < 0) return "";
|
|
94
122
|
if (n < 20) return ONES[n];
|
|
95
|
-
if (n < 100)
|
|
123
|
+
if (n < 100)
|
|
124
|
+
return TENS[Math.floor(n / 10)] + (n % 10 ? " " + ONES[n % 10] : "");
|
|
96
125
|
if (n < 1000) {
|
|
97
126
|
return `${ONES[Math.floor(n / 100)]} HUNDRED${n % 100 ? " " + spellNumber(n % 100) : ""}`;
|
|
98
127
|
}
|
|
@@ -206,7 +235,12 @@ export function forcedAlign(
|
|
|
206
235
|
move = 1;
|
|
207
236
|
}
|
|
208
237
|
// Skip a blank, unless that would merge two identical letters.
|
|
209
|
-
if (
|
|
238
|
+
if (
|
|
239
|
+
s >= 2 &&
|
|
240
|
+
s % 2 === 1 &&
|
|
241
|
+
stateToken(s) !== stateToken(s - 2) &&
|
|
242
|
+
previous[s - 2] > best
|
|
243
|
+
) {
|
|
210
244
|
best = previous[s - 2];
|
|
211
245
|
move = 2;
|
|
212
246
|
}
|
|
@@ -218,9 +252,14 @@ export function forcedAlign(
|
|
|
218
252
|
}
|
|
219
253
|
|
|
220
254
|
// End on the last token or the blank after it.
|
|
221
|
-
let s =
|
|
255
|
+
let s =
|
|
256
|
+
previous[states - 1] >= previous[states - 2] ? states - 1 : states - 2;
|
|
222
257
|
if (previous[s] === NEG) return undefined;
|
|
223
|
-
const result = tokens.map(() => ({
|
|
258
|
+
const result = tokens.map(() => ({
|
|
259
|
+
first: Infinity,
|
|
260
|
+
last: -Infinity,
|
|
261
|
+
logProb: 0,
|
|
262
|
+
}));
|
|
224
263
|
const counts = new Array<number>(tokens.length).fill(0);
|
|
225
264
|
for (let t = frames - 1; t >= 0; t--) {
|
|
226
265
|
if (s % 2 === 1) {
|
|
@@ -272,7 +311,8 @@ export function alignWords(
|
|
|
272
311
|
let groupStart = 0;
|
|
273
312
|
for (let i = 1; i <= words.length; i++) {
|
|
274
313
|
const tooLong =
|
|
275
|
-
i < words.length &&
|
|
314
|
+
i < words.length &&
|
|
315
|
+
words[i].endMs - words[groupStart].startMs > MAX_WINDOW_MS;
|
|
276
316
|
if (i === words.length || tooLong) {
|
|
277
317
|
if (tooLong) {
|
|
278
318
|
// Split at the biggest gap in this group, so no word is cut in two.
|
|
@@ -395,7 +435,11 @@ export function lettersHeard(
|
|
|
395
435
|
frames = 0;
|
|
396
436
|
};
|
|
397
437
|
let previous = blank;
|
|
398
|
-
for (
|
|
438
|
+
for (
|
|
439
|
+
let t = Math.max(0, firstFrame);
|
|
440
|
+
t < Math.min(endFrame, emissions.frameCount);
|
|
441
|
+
t++
|
|
442
|
+
) {
|
|
399
443
|
let best = 0;
|
|
400
444
|
let bestLogProb = -Infinity;
|
|
401
445
|
for (let token = 0; token < vocabularySize; token++) {
|
|
@@ -430,7 +474,11 @@ export function lettersHeard(
|
|
|
430
474
|
* What the letter model heard from `fromMs` to `toMs`, as one string: the
|
|
431
475
|
* words separated by spaces, or "" for nothing.
|
|
432
476
|
*/
|
|
433
|
-
export function heardBetween(
|
|
477
|
+
export function heardBetween(
|
|
478
|
+
emissions: CtcEmissions,
|
|
479
|
+
fromMs: number,
|
|
480
|
+
toMs: number,
|
|
481
|
+
): string {
|
|
434
482
|
return lettersHeard(
|
|
435
483
|
emissions,
|
|
436
484
|
Math.floor(fromMs / emissions.frameMs),
|
|
@@ -477,8 +525,14 @@ export function recoverSkippedSpeech(
|
|
|
477
525
|
const { frameMs, frameCount } = emissions;
|
|
478
526
|
const covered = new Uint8Array(frameCount);
|
|
479
527
|
for (const { startMs, endMs } of times) {
|
|
480
|
-
const from = Math.max(
|
|
481
|
-
|
|
528
|
+
const from = Math.max(
|
|
529
|
+
0,
|
|
530
|
+
Math.floor(startMs / frameMs) - RECOVER_CLEARANCE_FRAMES,
|
|
531
|
+
);
|
|
532
|
+
const to = Math.min(
|
|
533
|
+
frameCount,
|
|
534
|
+
Math.ceil(endMs / frameMs) + RECOVER_CLEARANCE_FRAMES,
|
|
535
|
+
);
|
|
482
536
|
covered.fill(1, from, to);
|
|
483
537
|
}
|
|
484
538
|
const result: { word: RoughWord; times: AlignedTimes }[] = [];
|
|
@@ -492,13 +546,20 @@ export function recoverSkippedSpeech(
|
|
|
492
546
|
while (t < frameCount && !covered[t]) t++;
|
|
493
547
|
for (const heard of lettersHeard(emissions, gapStart, t)) {
|
|
494
548
|
const needed =
|
|
495
|
-
heard.text.length === 1
|
|
549
|
+
heard.text.length === 1
|
|
550
|
+
? RECOVER_MIN_PROBABILITY_ONE_LETTER
|
|
551
|
+
: RECOVER_MIN_PROBABILITY;
|
|
496
552
|
if (heard.probability < needed) continue;
|
|
497
553
|
const startMs = heard.firstFrame * frameMs;
|
|
498
554
|
const endMs = (heard.lastFrame + 1) * frameMs;
|
|
499
555
|
result.push({
|
|
500
556
|
word: { text: heard.text, startMs, endMs },
|
|
501
|
-
times: {
|
|
557
|
+
times: {
|
|
558
|
+
startMs,
|
|
559
|
+
endMs,
|
|
560
|
+
timing: "letters",
|
|
561
|
+
confidence: heard.probability,
|
|
562
|
+
},
|
|
502
563
|
});
|
|
503
564
|
}
|
|
504
565
|
}
|
|
@@ -521,7 +582,9 @@ const squash = (s: string) => s.toLowerCase().replace(/[^a-z']/g, "");
|
|
|
521
582
|
* or something that doesn't even start the same way. Rough, but in testing
|
|
522
583
|
* it found real misreadings ("and pairs" for "in pairs").
|
|
523
584
|
*/
|
|
524
|
-
export function wordFlag(
|
|
585
|
+
export function wordFlag(
|
|
586
|
+
word: TranscriptWord,
|
|
587
|
+
): "left out" | "doubtful" | undefined {
|
|
525
588
|
if (word.timing === "letters") return "left out";
|
|
526
589
|
const text = squash(word.text);
|
|
527
590
|
// `heard` is missing from transcripts made before it existed.
|
|
@@ -565,13 +628,17 @@ export function quietestMoment(
|
|
|
565
628
|
const windowLength = Math.max(1, Math.round(CUT_WINDOW_MS * perMs));
|
|
566
629
|
const step = Math.max(1, Math.round(windowLength / 2));
|
|
567
630
|
const first = Math.max(0, Math.floor(fromMs * perMs));
|
|
568
|
-
const last = Math.min(
|
|
631
|
+
const last = Math.min(
|
|
632
|
+
samples.length - windowLength,
|
|
633
|
+
Math.ceil(toMs * perMs) - windowLength,
|
|
634
|
+
);
|
|
569
635
|
if (last < first) return (fromMs + toMs) / 2;
|
|
570
636
|
let bestStart = first;
|
|
571
637
|
let bestEnergy = Infinity;
|
|
572
638
|
for (let start = first; start <= last; start += step) {
|
|
573
639
|
let energy = 0;
|
|
574
|
-
for (let i = start; i < start + windowLength; i++)
|
|
640
|
+
for (let i = start; i < start + windowLength; i++)
|
|
641
|
+
energy += samples[i] * samples[i];
|
|
575
642
|
if (energy < bestEnergy) {
|
|
576
643
|
bestEnergy = energy;
|
|
577
644
|
bestStart = start;
|
|
@@ -601,7 +668,12 @@ export function withCutPoints(
|
|
|
601
668
|
): TranscriptWord[] {
|
|
602
669
|
const fileMs = (samples.length / sampleRate) * 1000;
|
|
603
670
|
const quietest = (from: number, to: number) =>
|
|
604
|
-
quietestMoment(
|
|
671
|
+
quietestMoment(
|
|
672
|
+
samples,
|
|
673
|
+
sampleRate,
|
|
674
|
+
Math.max(0, from),
|
|
675
|
+
Math.min(fileMs, to),
|
|
676
|
+
);
|
|
605
677
|
const cutBefore: number[] = [];
|
|
606
678
|
const cutAfter: number[] = [];
|
|
607
679
|
for (let i = 0; i <= times.length; i++) {
|
|
@@ -623,7 +695,10 @@ export function withCutPoints(
|
|
|
623
695
|
} else if (gap <= 2 * CUT_REACH_MS) {
|
|
624
696
|
cutAfter[i - 1] = cutBefore[i] = quietest(previous.endMs, next.startMs);
|
|
625
697
|
} else {
|
|
626
|
-
cutAfter[i - 1] = quietest(
|
|
698
|
+
cutAfter[i - 1] = quietest(
|
|
699
|
+
previous.endMs,
|
|
700
|
+
previous.endMs + CUT_REACH_MS,
|
|
701
|
+
);
|
|
627
702
|
cutBefore[i] = quietest(next.startMs - CUT_REACH_MS, next.startMs);
|
|
628
703
|
}
|
|
629
704
|
}
|
package/dev/transcript-export.ts
CHANGED
|
@@ -28,21 +28,29 @@ const ms = (n: number) => Math.round(n * 10) / 10;
|
|
|
28
28
|
|
|
29
29
|
/** Whisper's words as they are; speech it left out in [brackets]. */
|
|
30
30
|
function asText(words: readonly TranscriptWord[]): string {
|
|
31
|
-
return words
|
|
31
|
+
return words
|
|
32
|
+
.map((w) => (w.timing === "letters" ? `[${w.text}]` : w.text))
|
|
33
|
+
.join(" ");
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/**
|
|
35
37
|
* The JSON text to save. Each word is on its own line, so the file reads
|
|
36
38
|
* well and diffs and greps by word.
|
|
37
39
|
*/
|
|
38
|
-
export function transcriptJson(
|
|
40
|
+
export function transcriptJson(
|
|
41
|
+
transcript: Transcript,
|
|
42
|
+
context: ClipContext,
|
|
43
|
+
): string {
|
|
39
44
|
const { clip } = context;
|
|
40
45
|
const fromMs = clip.startMsIntoClip ?? 0;
|
|
41
|
-
const toMs =
|
|
46
|
+
const toMs =
|
|
47
|
+
context.lengthMs === undefined ? undefined : fromMs + context.lengthMs;
|
|
42
48
|
const inClip = (w: TranscriptWord) =>
|
|
43
49
|
w.endMs > fromMs && (toMs === undefined || w.startMs < toMs);
|
|
44
50
|
const clipWords = transcript.words.filter(inClip);
|
|
45
|
-
const first = clipWords.length
|
|
51
|
+
const first = clipWords.length
|
|
52
|
+
? transcript.words.indexOf(clipWords[0])
|
|
53
|
+
: undefined;
|
|
46
54
|
const last = clipWords.length
|
|
47
55
|
? transcript.words.indexOf(clipWords[clipWords.length - 1])
|
|
48
56
|
: undefined;
|
|
@@ -79,8 +87,10 @@ export function transcriptJson(transcript: Transcript, context: ClipContext): st
|
|
|
79
87
|
pipelineVersion: PIPELINE_VERSION,
|
|
80
88
|
models: MODELS,
|
|
81
89
|
wordCount: transcript.words.length,
|
|
82
|
-
recoveredCount: transcript.words.filter((w) => w.timing === "letters")
|
|
83
|
-
|
|
90
|
+
recoveredCount: transcript.words.filter((w) => w.timing === "letters")
|
|
91
|
+
.length,
|
|
92
|
+
doubtfulCount: transcript.words.filter((w) => wordFlag(w) === "doubtful")
|
|
93
|
+
.length,
|
|
84
94
|
text: asText(transcript.words),
|
|
85
95
|
},
|
|
86
96
|
words: "@@WORDS@@",
|
|
@@ -109,6 +119,7 @@ export function transcriptJson(transcript: Transcript, context: ClipContext): st
|
|
|
109
119
|
|
|
110
120
|
/** A file name for the saved transcript: the sound file's name, with `.transcript.json`. */
|
|
111
121
|
export function transcriptFileName(source: string): string {
|
|
112
|
-
const name =
|
|
122
|
+
const name =
|
|
123
|
+
decodeURIComponent(source.split("/").pop() ?? "sound") || "sound";
|
|
113
124
|
return name.replace(/\.[^.]*$/, "") + ".transcript.json";
|
|
114
125
|
}
|
package/dev/transcript-view.ts
CHANGED
|
@@ -23,7 +23,12 @@ export type TranscriptViewHooks = {
|
|
|
23
23
|
*/
|
|
24
24
|
transcript(
|
|
25
25
|
source: string,
|
|
26
|
-
):
|
|
26
|
+
):
|
|
27
|
+
| { readonly words: readonly TranscriptWord[]; readonly madeAt: number }
|
|
28
|
+
| string
|
|
29
|
+
| undefined;
|
|
30
|
+
/** Why this clip's file can't be played, if it can't. Shown above its words. */
|
|
31
|
+
problem(clip: SoundClip): string | undefined;
|
|
27
32
|
/** Put the playhead here, in the root's time. */
|
|
28
33
|
seek(rootMs: number): void;
|
|
29
34
|
/** Select this clip, as clicking it on the timeline does. */
|
|
@@ -34,7 +39,12 @@ export type TranscriptViewHooks = {
|
|
|
34
39
|
* Cut `fromMs`–`toMs` (the owner's time) out of `clip`. See
|
|
35
40
|
* `cutOutOfSoundClip()`.
|
|
36
41
|
*/
|
|
37
|
-
cutOut(
|
|
42
|
+
cutOut(
|
|
43
|
+
target: TranscriptViewClip,
|
|
44
|
+
fromMs: number,
|
|
45
|
+
toMs: number,
|
|
46
|
+
closeGap: boolean,
|
|
47
|
+
): void;
|
|
38
48
|
};
|
|
39
49
|
|
|
40
50
|
/** One word on screen. */
|
|
@@ -92,7 +102,8 @@ function describe(view: Omit<ViewWord, "element">): string {
|
|
|
92
102
|
: word.timing === "whisper"
|
|
93
103
|
? "Whisper's word and Whisper's rough times"
|
|
94
104
|
: "Whisper's word, timed by the letter model";
|
|
95
|
-
const owner =
|
|
105
|
+
const owner =
|
|
106
|
+
target.owner.userEditableDescription ?? target.owner.description;
|
|
96
107
|
const flag = wordFlag(word);
|
|
97
108
|
return [
|
|
98
109
|
`“${word.text}” ${played ? "" : "(not played: trimmed or cut out)"}`.trim(),
|
|
@@ -267,10 +278,14 @@ export class TranscriptView {
|
|
|
267
278
|
this.#drawSelectedClip();
|
|
268
279
|
const { anchor, side } = this.#wordAt(playMs);
|
|
269
280
|
const className = side && PLAYHEAD_CLASSES[side];
|
|
270
|
-
if (
|
|
281
|
+
if (
|
|
282
|
+
anchor !== this.#marked?.view ||
|
|
283
|
+
className !== this.#marked?.className
|
|
284
|
+
) {
|
|
271
285
|
this.#marked?.view.element.classList.remove(this.#marked.className);
|
|
272
286
|
if (anchor && className) anchor.element.classList.add(className);
|
|
273
|
-
this.#marked =
|
|
287
|
+
this.#marked =
|
|
288
|
+
anchor && className ? { view: anchor, className } : undefined;
|
|
274
289
|
}
|
|
275
290
|
this.#current = anchor;
|
|
276
291
|
if (!anchor) {
|
|
@@ -295,7 +310,10 @@ export class TranscriptView {
|
|
|
295
310
|
|
|
296
311
|
#rebuildIfNeeded(): void {
|
|
297
312
|
const clips = this.hooks.clips();
|
|
298
|
-
const transcripts = clips.map(({ clip }) =>
|
|
313
|
+
const transcripts = clips.map(({ clip }) =>
|
|
314
|
+
this.hooks.transcript(clip.source),
|
|
315
|
+
);
|
|
316
|
+
const problems = clips.map(({ clip }) => this.hooks.problem(clip));
|
|
299
317
|
const key = JSON.stringify([
|
|
300
318
|
this.#showCut.checked,
|
|
301
319
|
clips.map(({ clip, startMs, lengthMs }, i) => {
|
|
@@ -307,17 +325,19 @@ export class TranscriptView {
|
|
|
307
325
|
lengthMs ?? null,
|
|
308
326
|
clip.notes ?? "",
|
|
309
327
|
typeof t === "object" ? t.madeAt : (t ?? null),
|
|
328
|
+
problems[i] ?? null,
|
|
310
329
|
];
|
|
311
330
|
}),
|
|
312
331
|
]);
|
|
313
332
|
if (key === this.#key) return;
|
|
314
333
|
this.#key = key;
|
|
315
|
-
this.#build(clips, transcripts);
|
|
334
|
+
this.#build(clips, transcripts, problems);
|
|
316
335
|
}
|
|
317
336
|
|
|
318
337
|
#build(
|
|
319
338
|
clips: readonly TranscriptViewClip[],
|
|
320
339
|
transcripts: ReturnType<TranscriptViewHooks["transcript"]>[],
|
|
340
|
+
problems: readonly (string | undefined)[],
|
|
321
341
|
): void {
|
|
322
342
|
this.#scroll.replaceChildren();
|
|
323
343
|
this.#played = [];
|
|
@@ -340,7 +360,10 @@ export class TranscriptView {
|
|
|
340
360
|
/** The file range each clip plays. */
|
|
341
361
|
const range = (target: TranscriptViewClip) => {
|
|
342
362
|
const from = target.clip.startMsIntoClip ?? 0;
|
|
343
|
-
return {
|
|
363
|
+
return {
|
|
364
|
+
from,
|
|
365
|
+
to: target.lengthMs === undefined ? Infinity : from + target.lengthMs,
|
|
366
|
+
};
|
|
344
367
|
};
|
|
345
368
|
const plays = (target: TranscriptViewClip, word: TranscriptWord) => {
|
|
346
369
|
const { from, to } = range(target);
|
|
@@ -351,7 +374,10 @@ export class TranscriptView {
|
|
|
351
374
|
// words of its file that no clip plays. Each of those is shown once:
|
|
352
375
|
// just before the first clip (in the file) that starts after it, or else
|
|
353
376
|
// after the clip that ends last before it.
|
|
354
|
-
const wordsFor = new Map<
|
|
377
|
+
const wordsFor = new Map<
|
|
378
|
+
TranscriptViewClip,
|
|
379
|
+
{ word: TranscriptWord; played: boolean }[]
|
|
380
|
+
>();
|
|
355
381
|
for (const target of clips) wordsFor.set(target, []);
|
|
356
382
|
const sources = new Set(clips.map(({ clip }) => clip.source));
|
|
357
383
|
for (const source of sources) {
|
|
@@ -361,7 +387,8 @@ export class TranscriptView {
|
|
|
361
387
|
const ofFile = clips.filter(({ clip }) => clip.source === source);
|
|
362
388
|
for (const word of transcript.words) {
|
|
363
389
|
const playing = ofFile.filter((target) => plays(target, word));
|
|
364
|
-
for (const target of playing)
|
|
390
|
+
for (const target of playing)
|
|
391
|
+
wordsFor.get(target)!.push({ word, played: true });
|
|
365
392
|
if (playing.length > 0 || !this.#showCut.checked) continue;
|
|
366
393
|
const after = ofFile
|
|
367
394
|
.filter((target) => range(target).from >= word.endMs)
|
|
@@ -379,14 +406,25 @@ export class TranscriptView {
|
|
|
379
406
|
section.className = "tv-clip";
|
|
380
407
|
const head = document.createElement("div");
|
|
381
408
|
head.className = "tv-clip-head";
|
|
382
|
-
const owner =
|
|
383
|
-
|
|
409
|
+
const owner =
|
|
410
|
+
target.owner.userEditableDescription ?? target.owner.description;
|
|
411
|
+
const name =
|
|
412
|
+
target.clip.notes ||
|
|
413
|
+
decodeURIComponent(target.clip.source.split("/").pop() ?? "");
|
|
384
414
|
head.textContent = `${seconds(target.startMs)} s · ${owner} · ${name}`;
|
|
385
415
|
head.title = "Click to select this clip.";
|
|
386
416
|
head.addEventListener("click", () => this.hooks.selectClip(target.clip));
|
|
387
417
|
section.append(head);
|
|
388
418
|
this.#clipElements.set(target.clip, section);
|
|
389
419
|
|
|
420
|
+
const problem = problems[i];
|
|
421
|
+
if (problem !== undefined) {
|
|
422
|
+
const warning = document.createElement("div");
|
|
423
|
+
warning.className = "tv-problem";
|
|
424
|
+
warning.textContent = `⚠ ${problem}`;
|
|
425
|
+
section.append(warning);
|
|
426
|
+
}
|
|
427
|
+
|
|
390
428
|
const transcript = transcripts[i];
|
|
391
429
|
if (typeof transcript !== "object") {
|
|
392
430
|
const note = document.createElement("div");
|
|
@@ -396,7 +434,9 @@ export class TranscriptView {
|
|
|
396
434
|
this.#scroll.append(section);
|
|
397
435
|
return;
|
|
398
436
|
}
|
|
399
|
-
const words = wordsFor
|
|
437
|
+
const words = wordsFor
|
|
438
|
+
.get(target)!
|
|
439
|
+
.sort((a, b) => a.word.startMs - b.word.startMs);
|
|
400
440
|
if (words.length === 0) {
|
|
401
441
|
const note = document.createElement("div");
|
|
402
442
|
note.className = "tv-note";
|
|
@@ -421,7 +461,8 @@ export class TranscriptView {
|
|
|
421
461
|
if (flag === "left out") element.classList.add("recovered");
|
|
422
462
|
if (flag === "doubtful") element.classList.add("doubtful");
|
|
423
463
|
if (!played) element.classList.add("cut");
|
|
424
|
-
element.textContent =
|
|
464
|
+
element.textContent =
|
|
465
|
+
word.timing === "letters" ? `[${word.text}]` : word.text;
|
|
425
466
|
const view = {
|
|
426
467
|
word,
|
|
427
468
|
target,
|
|
@@ -461,7 +502,10 @@ export class TranscriptView {
|
|
|
461
502
|
* * `side`: whether `ms` is inside the anchor, in the pause after it, or
|
|
462
503
|
* before it (only before the very first word).
|
|
463
504
|
*/
|
|
464
|
-
#wordAt(ms: number): {
|
|
505
|
+
#wordAt(ms: number): {
|
|
506
|
+
anchor?: ViewWord;
|
|
507
|
+
side?: keyof typeof PLAYHEAD_CLASSES;
|
|
508
|
+
} {
|
|
465
509
|
const words = this.#played;
|
|
466
510
|
let low = 0;
|
|
467
511
|
let high = words.length - 1;
|
|
@@ -486,7 +530,10 @@ export class TranscriptView {
|
|
|
486
530
|
}
|
|
487
531
|
|
|
488
532
|
#isAbove(view: ViewWord): boolean {
|
|
489
|
-
return
|
|
533
|
+
return (
|
|
534
|
+
view.element.getBoundingClientRect().top <
|
|
535
|
+
this.#scroll.getBoundingClientRect().top
|
|
536
|
+
);
|
|
490
537
|
}
|
|
491
538
|
|
|
492
539
|
/** Bring a word into sight, a third of the way down, so there's room to read ahead. */
|
|
@@ -513,10 +560,13 @@ export class TranscriptView {
|
|
|
513
560
|
/** The played words the selection touches. */
|
|
514
561
|
#selectedWords(): ViewWord[] {
|
|
515
562
|
const selection = document.getSelection();
|
|
516
|
-
if (!selection || selection.isCollapsed || selection.rangeCount === 0)
|
|
563
|
+
if (!selection || selection.isCollapsed || selection.rangeCount === 0)
|
|
564
|
+
return [];
|
|
517
565
|
const range = selection.getRangeAt(0);
|
|
518
566
|
if (!this.#scroll.contains(range.commonAncestorContainer)) return [];
|
|
519
|
-
return this.#all.filter(
|
|
567
|
+
return this.#all.filter(
|
|
568
|
+
(view) => view.played && range.intersectsNode(view.element),
|
|
569
|
+
);
|
|
520
570
|
}
|
|
521
571
|
|
|
522
572
|
#drawCutButton(): void {
|
|
@@ -525,10 +575,12 @@ export class TranscriptView {
|
|
|
525
575
|
const button = this.#cutButton;
|
|
526
576
|
if (words.length === 0) {
|
|
527
577
|
button.disabled = true;
|
|
528
|
-
button.title =
|
|
578
|
+
button.title =
|
|
579
|
+
"Select some words, then click here to cut them out of their clip.";
|
|
529
580
|
} else if (clips.size > 1) {
|
|
530
581
|
button.disabled = true;
|
|
531
|
-
button.title =
|
|
582
|
+
button.title =
|
|
583
|
+
"The selection covers more than one clip. Cut one clip at a time.";
|
|
532
584
|
} else {
|
|
533
585
|
button.disabled = false;
|
|
534
586
|
button.title = `Cut ${words.length} word${words.length === 1 ? "" : "s"} out of this clip, quiet moment to quiet moment.`;
|
|
@@ -544,7 +596,8 @@ export class TranscriptView {
|
|
|
544
596
|
const last = words[words.length - 1];
|
|
545
597
|
const { clip } = target;
|
|
546
598
|
// Owner time: where the clip starts in its owner, plus how far into the clip.
|
|
547
|
-
const toOwner = (fileMs: number) =>
|
|
599
|
+
const toOwner = (fileMs: number) =>
|
|
600
|
+
clip.startMsIntoScene + (fileMs - (clip.startMsIntoClip ?? 0));
|
|
548
601
|
const fromMs = toOwner(first.word.cutBeforeMs);
|
|
549
602
|
const toMs = toOwner(last.word.cutAfterMs);
|
|
550
603
|
const closeGap = await askHowToCut(
|
|
@@ -563,7 +616,10 @@ export class TranscriptView {
|
|
|
563
616
|
* Confirm a cut, and ask whether to close the gap.
|
|
564
617
|
* @returns true to close the gap, false to leave it, undefined to cancel.
|
|
565
618
|
*/
|
|
566
|
-
function askHowToCut(
|
|
619
|
+
function askHowToCut(
|
|
620
|
+
text: string,
|
|
621
|
+
lengthMs: number,
|
|
622
|
+
): Promise<boolean | undefined> {
|
|
567
623
|
const dialog = document.createElement("dialog");
|
|
568
624
|
dialog.style.cssText = "min-width:26em;max-width:40em;padding:1em";
|
|
569
625
|
const heading = document.createElement("h3");
|