canvas-recorder-lib 0.7.1 → 0.7.3
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 +51 -8
- package/dev/audio-builder.ts +5 -1
- package/dev/canvas-recorder.css +15 -4
- package/dev/canvas-recorder.ts +518 -131
- 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 +42 -11
- 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 +43 -23
- 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 +34 -10
- 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 +375 -85
- 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 +33 -7
- 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.map +1 -1
- package/dist/dev/transcripts.js +5 -3
- 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 +15 -6
- 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 +35 -1
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js +76 -0
- 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/showable.d.ts +74 -0
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.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 +95 -2
- 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/showable.ts +79 -0
- 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/timeline-display.ts
CHANGED
|
@@ -98,10 +98,10 @@ const SOUND_ROW_H_CSS = 58;
|
|
|
98
98
|
const WORD_STRIP_CSS = 16;
|
|
99
99
|
/** How close, in CSS px, a dragged edge must come to a snap point to land on it. */
|
|
100
100
|
const SNAP_PX = 8;
|
|
101
|
-
const BLOCK_PAD_CSS = 3;
|
|
102
|
-
const HANDLE_PX = 8;
|
|
103
|
-
const MIN_WINDOW_MS = 50;
|
|
104
|
-
const BOTTOM_PAD_CSS = Math.round(ROW_H_CSS / 3);
|
|
101
|
+
const BLOCK_PAD_CSS = 3; // gap above/below block within its row
|
|
102
|
+
const HANDLE_PX = 8; // pixel zone at block edges that triggers a drag cursor
|
|
103
|
+
const MIN_WINDOW_MS = 50; // smallest zoom window allowed
|
|
104
|
+
const BOTTOM_PAD_CSS = Math.round(ROW_H_CSS / 3); // always-blank seek strip at the bottom
|
|
105
105
|
|
|
106
106
|
// ── TimelineDisplay ───────────────────────────────────────────────────────────
|
|
107
107
|
|
|
@@ -306,7 +306,10 @@ export class TimelineDisplay {
|
|
|
306
306
|
const rows: number[] = new Array(n).fill(0);
|
|
307
307
|
const all = Array.from({ length: n }, (_, i) => i);
|
|
308
308
|
const isSound = (i: number) => this._blocks[i]!.lane === "sound";
|
|
309
|
-
const componentRows = this._assignLane(
|
|
309
|
+
const componentRows = this._assignLane(
|
|
310
|
+
all.filter((i) => !isSound(i)),
|
|
311
|
+
rows,
|
|
312
|
+
);
|
|
310
313
|
const soundIndices = all.filter(isSound);
|
|
311
314
|
const soundRows = this._assignLane(soundIndices, rows);
|
|
312
315
|
for (const i of soundIndices) rows[i]! += componentRows;
|
|
@@ -361,7 +364,12 @@ export class TimelineDisplay {
|
|
|
361
364
|
);
|
|
362
365
|
if (firstSoundRow !== Infinity) {
|
|
363
366
|
ctx.fillStyle = "#e3eee3";
|
|
364
|
-
ctx.fillRect(
|
|
367
|
+
ctx.fillRect(
|
|
368
|
+
0,
|
|
369
|
+
tops[firstSoundRow]! * dpr,
|
|
370
|
+
pxW,
|
|
371
|
+
(rowsHeight - tops[firstSoundRow]!) * dpr,
|
|
372
|
+
);
|
|
365
373
|
}
|
|
366
374
|
|
|
367
375
|
for (let i = 0; i < this._blocks.length; i++) {
|
|
@@ -398,7 +406,18 @@ export class TimelineDisplay {
|
|
|
398
406
|
this._drawWaveform(ctx, wave, durMs, x0, bw, y0, bh - stripH, pxW);
|
|
399
407
|
}
|
|
400
408
|
if (transcript !== undefined && bw > 2 * dpr) {
|
|
401
|
-
this._drawWords(
|
|
409
|
+
this._drawWords(
|
|
410
|
+
ctx,
|
|
411
|
+
b,
|
|
412
|
+
transcript,
|
|
413
|
+
x0,
|
|
414
|
+
x0 + bw,
|
|
415
|
+
y1 - stripH,
|
|
416
|
+
stripH,
|
|
417
|
+
msToX,
|
|
418
|
+
pxW,
|
|
419
|
+
dpr,
|
|
420
|
+
);
|
|
402
421
|
}
|
|
403
422
|
if (isSound && selected) {
|
|
404
423
|
ctx.strokeStyle = "#fff";
|
|
@@ -532,7 +551,12 @@ export class TimelineDisplay {
|
|
|
532
551
|
if (msToX(word.endMs) < left) continue;
|
|
533
552
|
if (x - lastTickX >= 3 * dpr) {
|
|
534
553
|
ctx.fillStyle = "rgba(255, 255, 255, 0.5)";
|
|
535
|
-
ctx.fillRect(
|
|
554
|
+
ctx.fillRect(
|
|
555
|
+
Math.round(x),
|
|
556
|
+
top,
|
|
557
|
+
Math.max(1, Math.round(dpr / 2)),
|
|
558
|
+
height,
|
|
559
|
+
);
|
|
536
560
|
lastTickX = x;
|
|
537
561
|
}
|
|
538
562
|
const textX = Math.max(x, left) + 2 * dpr;
|
|
@@ -648,10 +672,23 @@ export class TimelineDisplay {
|
|
|
648
672
|
|
|
649
673
|
type DragState =
|
|
650
674
|
| { kind: "idle" }
|
|
651
|
-
| {
|
|
675
|
+
| {
|
|
676
|
+
kind: "potential";
|
|
677
|
+
x0: number;
|
|
678
|
+
y0: number;
|
|
679
|
+
msAtDown: number;
|
|
680
|
+
bodyBlock?: { block: TimelineBlock; startMsAtDown: number };
|
|
681
|
+
leftBlock?: TimelineBlock;
|
|
682
|
+
rightBlock?: TimelineBlock;
|
|
683
|
+
}
|
|
652
684
|
| { kind: "pan"; x0: number; viewStart0: number; viewEnd0: number }
|
|
653
685
|
| { kind: "drag-left"; block: TimelineBlock }
|
|
654
|
-
| {
|
|
686
|
+
| {
|
|
687
|
+
kind: "drag-body";
|
|
688
|
+
block: TimelineBlock;
|
|
689
|
+
startMsAtDown: number;
|
|
690
|
+
msAtDown: number;
|
|
691
|
+
}
|
|
655
692
|
| { kind: "drag-right"; block: TimelineBlock }
|
|
656
693
|
| { kind: "seek" };
|
|
657
694
|
|
|
@@ -664,8 +701,16 @@ export class TimelineDisplay {
|
|
|
664
701
|
|
|
665
702
|
const clampMs = (ms: number) => Math.max(0, Math.min(this._durationMs, ms));
|
|
666
703
|
|
|
667
|
-
type HitInput = {
|
|
668
|
-
|
|
704
|
+
type HitInput = {
|
|
705
|
+
clientX: number;
|
|
706
|
+
clientY: number;
|
|
707
|
+
shiftKey?: boolean;
|
|
708
|
+
altKey?: boolean;
|
|
709
|
+
};
|
|
710
|
+
const hitTest = (
|
|
711
|
+
e: HitInput,
|
|
712
|
+
):
|
|
713
|
+
{ block: TimelineBlock; zone: "left" | "right" | "body" } | undefined => {
|
|
669
714
|
const rect = canvas.getBoundingClientRect();
|
|
670
715
|
const cx = e.clientX - rect.left;
|
|
671
716
|
const cy = e.clientY - rect.top;
|
|
@@ -687,13 +732,16 @@ export class TimelineDisplay {
|
|
|
687
732
|
const markerMs = b.handleEndMs?.() ?? endMs;
|
|
688
733
|
|
|
689
734
|
const inLeftZone = !!b.onDragLeft && Math.abs(ms - startMs) <= handleMs;
|
|
690
|
-
const inRightZone =
|
|
735
|
+
const inRightZone =
|
|
736
|
+
!!(b.onDragRight || b.onCommitRight) &&
|
|
737
|
+
Math.abs(ms - markerMs) <= handleMs;
|
|
691
738
|
const inBody = ms >= startMs && ms <= endMs;
|
|
692
739
|
if (!inLeftZone && !inRightZone && !inBody) continue;
|
|
693
740
|
|
|
694
741
|
// Modifier overrides — resolve ambiguity on small/zero-duration blocks:
|
|
695
742
|
// Shift → force right-edge (change duration / minDuration)
|
|
696
|
-
if (e.shiftKey && (b.onDragRight || b.onCommitRight))
|
|
743
|
+
if (e.shiftKey && (b.onDragRight || b.onCommitRight))
|
|
744
|
+
return { block: b, zone: "right" };
|
|
697
745
|
// Ctrl → force body (select without dragging)
|
|
698
746
|
if (e.altKey) return { block: b, zone: "body" };
|
|
699
747
|
|
|
@@ -709,21 +757,34 @@ export class TimelineDisplay {
|
|
|
709
757
|
|
|
710
758
|
const updateHoverCursor = (e: HitInput) => {
|
|
711
759
|
const hit = hitTest(e);
|
|
712
|
-
const isDurationZone =
|
|
760
|
+
const isDurationZone =
|
|
761
|
+
hit?.zone === "right" &&
|
|
762
|
+
!!(hit.block.onDragRight || hit.block.onCommitRight);
|
|
713
763
|
const isStartTimeZone = hit?.zone === "left" && !!hit.block.onDragLeft;
|
|
714
764
|
const isBodyDraggable = hit?.zone === "body" && !!hit.block.onDragBody;
|
|
715
765
|
const isCtrlSelect = !!e.altKey && !!hit;
|
|
716
|
-
canvas.style.cursor = isDurationZone
|
|
717
|
-
|
|
718
|
-
:
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
766
|
+
canvas.style.cursor = isDurationZone
|
|
767
|
+
? "ew-resize"
|
|
768
|
+
: // A sound clip's left edge trims; anything else's moves the start.
|
|
769
|
+
isStartTimeZone
|
|
770
|
+
? hit.block.lane === "sound"
|
|
771
|
+
? "ew-resize"
|
|
772
|
+
: "grab"
|
|
773
|
+
: isCtrlSelect
|
|
774
|
+
? "pointer"
|
|
775
|
+
: isBodyDraggable
|
|
776
|
+
? "grab"
|
|
777
|
+
: "crosshair";
|
|
722
778
|
};
|
|
723
779
|
|
|
724
780
|
const onKey = (e: KeyboardEvent) => {
|
|
725
781
|
if (drag.kind === "idle" || drag.kind === "potential") {
|
|
726
|
-
updateHoverCursor({
|
|
782
|
+
updateHoverCursor({
|
|
783
|
+
clientX: lastClientX,
|
|
784
|
+
clientY: lastClientY,
|
|
785
|
+
shiftKey: e.shiftKey,
|
|
786
|
+
altKey: e.altKey,
|
|
787
|
+
});
|
|
727
788
|
}
|
|
728
789
|
};
|
|
729
790
|
window.addEventListener("keydown", onKey);
|
|
@@ -744,16 +805,35 @@ export class TimelineDisplay {
|
|
|
744
805
|
}
|
|
745
806
|
// Ctrl on any block → potential so the mouseup triggers selection, not a drag
|
|
746
807
|
if (e.altKey && hit) {
|
|
747
|
-
drag = {
|
|
808
|
+
drag = {
|
|
809
|
+
kind: "potential",
|
|
810
|
+
x0: e.clientX,
|
|
811
|
+
y0: e.clientY,
|
|
812
|
+
msAtDown: toLocalMs(e),
|
|
813
|
+
};
|
|
748
814
|
return;
|
|
749
815
|
}
|
|
750
816
|
const msAtDown = toLocalMs(e);
|
|
751
|
-
const leftBlock =
|
|
752
|
-
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
817
|
+
const leftBlock =
|
|
818
|
+
hit?.zone === "left" && hit.block.onDragLeft ? hit.block : undefined;
|
|
819
|
+
const rightBlock =
|
|
820
|
+
hit?.zone === "right" &&
|
|
821
|
+
(hit.block.onDragRight || hit.block.onCommitRight)
|
|
822
|
+
? hit.block
|
|
823
|
+
: undefined;
|
|
824
|
+
const bodyBlock =
|
|
825
|
+
hit?.zone === "body" && hit.block.onDragBody
|
|
826
|
+
? { block: hit.block, startMsAtDown: hit.block.startMs() }
|
|
827
|
+
: undefined;
|
|
828
|
+
drag = {
|
|
829
|
+
kind: "potential",
|
|
830
|
+
x0: e.clientX,
|
|
831
|
+
y0: e.clientY,
|
|
832
|
+
msAtDown,
|
|
833
|
+
leftBlock,
|
|
834
|
+
rightBlock,
|
|
835
|
+
bodyBlock,
|
|
836
|
+
};
|
|
757
837
|
});
|
|
758
838
|
|
|
759
839
|
canvas.addEventListener("pointermove", (e) => {
|
|
@@ -778,7 +858,9 @@ export class TimelineDisplay {
|
|
|
778
858
|
break;
|
|
779
859
|
case "drag-left": {
|
|
780
860
|
const width = canvas.getBoundingClientRect().width;
|
|
781
|
-
const ms = e.altKey
|
|
861
|
+
const ms = e.altKey
|
|
862
|
+
? toLocalMs(e)
|
|
863
|
+
: this._snap(drag.block, toLocalMs(e), width);
|
|
782
864
|
if (e.altKey) this._snapMs = undefined;
|
|
783
865
|
drag.block.onDragLeft!(ms);
|
|
784
866
|
this._draw();
|
|
@@ -792,7 +874,9 @@ export class TimelineDisplay {
|
|
|
792
874
|
}
|
|
793
875
|
case "drag-right": {
|
|
794
876
|
const width = canvas.getBoundingClientRect().width;
|
|
795
|
-
const ms = e.altKey
|
|
877
|
+
const ms = e.altKey
|
|
878
|
+
? toLocalMs(e)
|
|
879
|
+
: this._snap(drag.block, toLocalMs(e), width);
|
|
796
880
|
if (e.altKey) this._snapMs = undefined;
|
|
797
881
|
drag.block.onDragRight?.(ms);
|
|
798
882
|
this._draw();
|
|
@@ -805,9 +889,19 @@ export class TimelineDisplay {
|
|
|
805
889
|
} else if (drag.rightBlock) {
|
|
806
890
|
drag = { kind: "drag-right", block: drag.rightBlock };
|
|
807
891
|
} else if (drag.bodyBlock) {
|
|
808
|
-
drag = {
|
|
892
|
+
drag = {
|
|
893
|
+
kind: "drag-body",
|
|
894
|
+
block: drag.bodyBlock.block,
|
|
895
|
+
startMsAtDown: drag.bodyBlock.startMsAtDown,
|
|
896
|
+
msAtDown: drag.msAtDown,
|
|
897
|
+
};
|
|
809
898
|
} else {
|
|
810
|
-
drag = {
|
|
899
|
+
drag = {
|
|
900
|
+
kind: "pan",
|
|
901
|
+
x0: drag.x0,
|
|
902
|
+
viewStart0: this._viewStartMs,
|
|
903
|
+
viewEnd0: this._viewEndMs,
|
|
904
|
+
};
|
|
811
905
|
}
|
|
812
906
|
}
|
|
813
907
|
break;
|
|
@@ -838,7 +932,11 @@ export class TimelineDisplay {
|
|
|
838
932
|
const saved = drag;
|
|
839
933
|
drag = { kind: "idle" };
|
|
840
934
|
|
|
841
|
-
if (
|
|
935
|
+
if (
|
|
936
|
+
saved.kind === "drag-left" ||
|
|
937
|
+
saved.kind === "drag-right" ||
|
|
938
|
+
saved.kind === "drag-body"
|
|
939
|
+
) {
|
|
842
940
|
if (saved.kind === "drag-right") saved.block.onCommitRight?.();
|
|
843
941
|
this._snapMs = undefined;
|
|
844
942
|
this._draw();
|
|
@@ -861,21 +959,25 @@ export class TimelineDisplay {
|
|
|
861
959
|
}
|
|
862
960
|
});
|
|
863
961
|
|
|
864
|
-
canvas.addEventListener(
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
this.
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
962
|
+
canvas.addEventListener(
|
|
963
|
+
"wheel",
|
|
964
|
+
(e) => {
|
|
965
|
+
e.preventDefault();
|
|
966
|
+
const rect = canvas.getBoundingClientRect();
|
|
967
|
+
const cursorMs = this._xToMs(e.clientX - rect.left, rect.width);
|
|
968
|
+
const factor = e.deltaY > 0 ? 1.5 ** (1 / 7) : 1.5 ** (-1 / 7);
|
|
969
|
+
let s = cursorMs + (this._viewStartMs - cursorMs) * factor;
|
|
970
|
+
let end = cursorMs + (this._viewEndMs - cursorMs) * factor;
|
|
971
|
+
s = Math.max(0, s);
|
|
972
|
+
end = Math.min(this._durationMs, end);
|
|
973
|
+
if (end - s >= MIN_WINDOW_MS) {
|
|
974
|
+
this._viewStartMs = s;
|
|
975
|
+
this._viewEndMs = end;
|
|
976
|
+
this._userMovedView();
|
|
977
|
+
this._draw();
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
{ passive: false },
|
|
981
|
+
);
|
|
880
982
|
}
|
|
881
983
|
}
|
package/dev/transcribe-core.ts
CHANGED
|
@@ -84,8 +84,12 @@ const ALIGNER_OVERLAP_FRAMES = 50;
|
|
|
84
84
|
const ALIGNER_HOP_SAMPLES = 320;
|
|
85
85
|
|
|
86
86
|
type Aligner = {
|
|
87
|
-
readonly processor: Awaited<
|
|
88
|
-
|
|
87
|
+
readonly processor: Awaited<
|
|
88
|
+
ReturnType<Transformers["AutoProcessor"]["from_pretrained"]>
|
|
89
|
+
>;
|
|
90
|
+
readonly model: Awaited<
|
|
91
|
+
ReturnType<Transformers["AutoModelForCTC"]["from_pretrained"]>
|
|
92
|
+
>;
|
|
89
93
|
readonly vocabulary: ReadonlyMap<string, number>;
|
|
90
94
|
};
|
|
91
95
|
|
|
@@ -119,15 +123,22 @@ export class Transcriber {
|
|
|
119
123
|
sumLoaded += d.loaded;
|
|
120
124
|
sumTotal += d.total;
|
|
121
125
|
}
|
|
122
|
-
this.#onProgress?.({
|
|
126
|
+
this.#onProgress?.({
|
|
127
|
+
stage: "downloading models",
|
|
128
|
+
fraction: sumLoaded / sumTotal,
|
|
129
|
+
});
|
|
123
130
|
};
|
|
124
131
|
|
|
125
132
|
private loadWhisper() {
|
|
126
|
-
return this.transformers.pipeline(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
return this.transformers.pipeline(
|
|
134
|
+
"automatic-speech-recognition",
|
|
135
|
+
MODELS.whisper,
|
|
136
|
+
{
|
|
137
|
+
device: this.device,
|
|
138
|
+
dtype: WHISPER_DTYPE,
|
|
139
|
+
progress_callback: this.#downloadProgress,
|
|
140
|
+
},
|
|
141
|
+
);
|
|
131
142
|
}
|
|
132
143
|
|
|
133
144
|
#loadAligner(): Promise<Aligner> {
|
|
@@ -143,8 +154,10 @@ export class Transcriber {
|
|
|
143
154
|
AutoTokenizer.from_pretrained(MODELS.aligner, options),
|
|
144
155
|
]).then(([processor, model, tokenizer]) => {
|
|
145
156
|
// A Map in Transformers.js 4, a plain object in 3.
|
|
146
|
-
const raw = tokenizer.get_vocab() as
|
|
147
|
-
|
|
157
|
+
const raw = tokenizer.get_vocab() as
|
|
158
|
+
Map<string, number> | Record<string, number>;
|
|
159
|
+
const vocabulary =
|
|
160
|
+
raw instanceof Map ? raw : new Map(Object.entries(raw));
|
|
148
161
|
return { processor, model, vocabulary };
|
|
149
162
|
});
|
|
150
163
|
}
|
|
@@ -190,20 +203,29 @@ export class Transcriber {
|
|
|
190
203
|
const boundaries = pieceBoundaries(samples);
|
|
191
204
|
const words: RoughWord[] = [];
|
|
192
205
|
for (let i = 0; i + 1 < boundaries.length; i++) {
|
|
193
|
-
onProgress?.({
|
|
206
|
+
onProgress?.({
|
|
207
|
+
stage: "transcribing",
|
|
208
|
+
fraction: boundaries[i] / samples.length,
|
|
209
|
+
});
|
|
194
210
|
const piece = samples.subarray(boundaries[i], boundaries[i + 1]);
|
|
195
211
|
const offsetMs = (boundaries[i] / SAMPLE_RATE) * 1000;
|
|
196
212
|
const pieceMs = (piece.length / SAMPLE_RATE) * 1000;
|
|
197
213
|
const result = (await asr(piece, {
|
|
198
214
|
return_timestamps: "word",
|
|
199
215
|
chunk_length_s: 30,
|
|
200
|
-
})) as {
|
|
216
|
+
})) as {
|
|
217
|
+
chunks?: { text: string; timestamp: [number, number | null] }[];
|
|
218
|
+
};
|
|
201
219
|
for (const { text, timestamp } of result.chunks ?? []) {
|
|
202
220
|
const startMs = timestamp[0] * 1000;
|
|
203
221
|
// Whisper sometimes leaves the last word open-ended.
|
|
204
222
|
const endMs = timestamp[1] === null ? pieceMs : timestamp[1] * 1000;
|
|
205
223
|
if (text.trim() === "") continue;
|
|
206
|
-
words.push({
|
|
224
|
+
words.push({
|
|
225
|
+
text,
|
|
226
|
+
startMs: offsetMs + startMs,
|
|
227
|
+
endMs: offsetMs + endMs,
|
|
228
|
+
});
|
|
207
229
|
}
|
|
208
230
|
}
|
|
209
231
|
return words;
|
|
@@ -219,7 +241,8 @@ export class Transcriber {
|
|
|
219
241
|
this.#aligner ??= this.#loadAligner();
|
|
220
242
|
const { processor, model, vocabulary } = await this.#aligner;
|
|
221
243
|
const frameCount = Math.floor(samples.length / ALIGNER_HOP_SAMPLES);
|
|
222
|
-
const step =
|
|
244
|
+
const step =
|
|
245
|
+
ALIGNER_WINDOW_SAMPLES - 2 * ALIGNER_OVERLAP_FRAMES * ALIGNER_HOP_SAMPLES;
|
|
223
246
|
let vocabularySize = 0;
|
|
224
247
|
let logProbs = new Float32Array(0);
|
|
225
248
|
/** Frames filled in so far, from the start. */
|
|
@@ -237,7 +260,10 @@ export class Transcriber {
|
|
|
237
260
|
const data = logits.data as Float32Array;
|
|
238
261
|
const base = offset / ALIGNER_HOP_SAMPLES;
|
|
239
262
|
// Keep the middle of each window; the edges are only there for context.
|
|
240
|
-
const from = Math.max(
|
|
263
|
+
const from = Math.max(
|
|
264
|
+
offset === 0 ? 0 : ALIGNER_OVERLAP_FRAMES,
|
|
265
|
+
written - base,
|
|
266
|
+
);
|
|
241
267
|
const to = isLast ? frames : frames - ALIGNER_OVERLAP_FRAMES;
|
|
242
268
|
for (let k = from; k < to && base + k < frameCount; k++) {
|
|
243
269
|
logSoftmax(data, k * size, size, logProbs, (base + k) * size);
|
|
@@ -275,7 +301,8 @@ function logSoftmax(
|
|
|
275
301
|
let max = -Infinity;
|
|
276
302
|
for (let v = 0; v < size; v++) max = Math.max(max, source[sourceOffset + v]);
|
|
277
303
|
let sum = 0;
|
|
278
|
-
for (let v = 0; v < size; v++)
|
|
304
|
+
for (let v = 0; v < size; v++)
|
|
305
|
+
sum += Math.exp(source[sourceOffset + v] - max);
|
|
279
306
|
const logSum = max + Math.log(sum);
|
|
280
307
|
for (let v = 0; v < size; v++) {
|
|
281
308
|
destination[destinationOffset + v] = source[sourceOffset + v] - logSum;
|
|
@@ -291,7 +318,11 @@ function logSoftmax(
|
|
|
291
318
|
export function pieceBoundaries(samples: Float32Array): number[] {
|
|
292
319
|
const totalMs = (samples.length / SAMPLE_RATE) * 1000;
|
|
293
320
|
const boundaries = [0];
|
|
294
|
-
for (
|
|
321
|
+
for (
|
|
322
|
+
let target = PIECE_MS;
|
|
323
|
+
target < totalMs - PIECE_MS / 2;
|
|
324
|
+
target += PIECE_MS
|
|
325
|
+
) {
|
|
295
326
|
const cutMs = quietestMoment(
|
|
296
327
|
samples,
|
|
297
328
|
SAMPLE_RATE,
|
package/dev/transcribe-worker.ts
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
// the models run. Started by transcripts.ts; it does nothing on its own.
|
|
3
3
|
|
|
4
4
|
import * as transformers from "@huggingface/transformers";
|
|
5
|
-
import {
|
|
6
|
-
Device,
|
|
7
|
-
Transcriber,
|
|
8
|
-
TranscribeProgress,
|
|
9
|
-
} from "./transcribe-core.ts";
|
|
5
|
+
import { Device, Transcriber, TranscribeProgress } from "./transcribe-core.ts";
|
|
10
6
|
import type { TranscriptWord } from "./transcript-align.ts";
|
|
11
7
|
|
|
12
8
|
export type TranscribeRequest = {
|
|
@@ -41,7 +37,9 @@ const transcribers = new Map<Device, Transcriber>();
|
|
|
41
37
|
let webGpuFailed = false;
|
|
42
38
|
|
|
43
39
|
function post(reply: TranscribeReply): void {
|
|
44
|
-
(
|
|
40
|
+
(
|
|
41
|
+
globalThis as unknown as { postMessage(message: unknown): void }
|
|
42
|
+
).postMessage(reply);
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
function devicesToTry(forced?: Device): Device[] {
|
|
@@ -57,7 +55,11 @@ globalThis.addEventListener("message", (event) => {
|
|
|
57
55
|
queue = queue.then(() => handle(request));
|
|
58
56
|
});
|
|
59
57
|
|
|
60
|
-
async function handle({
|
|
58
|
+
async function handle({
|
|
59
|
+
id,
|
|
60
|
+
samples,
|
|
61
|
+
device: forced,
|
|
62
|
+
}: TranscribeRequest): Promise<void> {
|
|
61
63
|
let lastError: unknown;
|
|
62
64
|
for (const device of devicesToTry(forced)) {
|
|
63
65
|
try {
|
|
@@ -70,13 +72,22 @@ async function handle({ id, samples, device: forced }: TranscribeRequest): Promi
|
|
|
70
72
|
const words = await transcriber.transcribe(samples, (progress) =>
|
|
71
73
|
post({ id, kind: "progress", progress, device }),
|
|
72
74
|
);
|
|
73
|
-
post({
|
|
75
|
+
post({
|
|
76
|
+
id,
|
|
77
|
+
kind: "done",
|
|
78
|
+
words,
|
|
79
|
+
device,
|
|
80
|
+
elapsedMs: performance.now() - start,
|
|
81
|
+
});
|
|
74
82
|
return;
|
|
75
83
|
} catch (error) {
|
|
76
84
|
lastError = error;
|
|
77
85
|
transcribers.delete(device);
|
|
78
86
|
if (device === "webgpu") webGpuFailed = true;
|
|
79
|
-
console.warn(
|
|
87
|
+
console.warn(
|
|
88
|
+
`Transcription on ${device} failed; trying the next device.`,
|
|
89
|
+
error,
|
|
90
|
+
);
|
|
80
91
|
}
|
|
81
92
|
}
|
|
82
93
|
post({ id, kind: "error", message: String(lastError) });
|