Multi-mic support and replay mode for Transcribe app

This commit is contained in:
James Babcock committed 2026-11-12 21:54:57 -08:00
1 parent c162c8e633
commit 9372b2742c
45 files changed
+3926 -288

No files matched your search

+15 -1
View File
@@ -2,6 +2,7 @@ import { readTextFile, type DirectoryEntry } from "../../native/file-access";
import { isFontFile } from "../../native/font-files";
import { installFontFile, isFontInstalled } from "../../graphics/installed-fonts";
import { isDecodableImageFile } from "../../native/image-files";
import { isMicRecordingFile } from "../../native/mic-recording";
import { isPlayableVideoFile } from "../../native/video-player";
import { readEvenHubPackageManifest } from "../evenhub/installed-apps";
import { EvenHubPermissionDialogLayer } from "../evenhub/permission-dialog";
@@ -38,6 +39,8 @@ export type FilesAppOptions = InProcessAppOptions & {
openFontWindow: (title: string, path: string) => void;
/** Open a video file's player (settings panel first) as its own shell window. */
openVideoWindow: (title: string, path: string) => void;
/** Replay a recording (.mka) through Transcribe, in a window of its own. */
openRecordingInTranscribe: (title: string, path: string) => void;
};
/**
@@ -50,7 +53,7 @@ export function createFilesAppWindow(options: FilesAppOptions): InProcessWindow
const browser = new FileBrowserLayer({
isSupportedFile: (name) =>
TEXT_FILE.test(name) || isFontFile(name) || EHPK_FILE.test(name) ||
(!global.isIOS && (isDecodableImageFile(name) || isPlayableVideoFile(name))),
(!global.isIOS && (isDecodableImageFile(name) || isPlayableVideoFile(name) || isMicRecordingFile(name))),
// The browser handles double-click itself (up a level), so it is not
// wrapped in YieldAtRootLayer; it yields explicitly from the top level.
onLeave: () => shell.yieldFocusToSidebar(),
@@ -235,6 +238,17 @@ function fileOpenActions(entry: DirectoryEntry, options: FilesAppOptions): FileI
},
];
}
if (isMicRecordingFile(entry.name)) {
return [
{
label: "Open in Transcribe",
onSelect: (ctx) => {
ctx.stack.pop();
options.openRecordingInTranscribe(entry.name, entry.path);
},
},
];
}
if (isPlayableVideoFile(entry.name)) {
return [
{
+4
View File
@@ -14,6 +14,7 @@ import {
FILES_WINDOW_ID,
} from "./files-app";
import { createVideoPlayerWindow } from "./video-window";
import { openRecordingInTranscribe } from "../transcribe";
// Document windows are closeable and non-singleton; the serial keeps their
// windowIds unique.
@@ -91,6 +92,9 @@ const filesApp: AppDefinition = {
},
openFontWindow: (title, path) => openFontDocumentWindow(ctx, title, path),
openVideoWindow: (title, path) => openVideoWindow(ctx, title, path),
openRecordingInTranscribe: (title, path) => {
openRecordingInTranscribe(ctx, path, title);
},
}),
),
// A document arriving via Android's Share intent opens as its own window.
+21
View File
@@ -56,6 +56,27 @@ export function saveMicConfig(config: MicConfig): void {
setStringSetting(CONFIG_SETTING_KEY, JSON.stringify(config));
}
/**
* The configuration a capture of the temples' own microphones arms them
* with: `mics` of 2 is one microphone per temple (the front one), 4 is both
* of each. The front end and direction detection follow Microphone setup
* (the Microphones app), except that both of a temple's microphones only
* come through the codec front end. Always raw PCM16 at 16 kHz, which is
* what the firmware streams and transcription takes.
*/
export function micArrayCaptureConfig(mics: 2 | 4): MicConfig {
const base = loadMicConfig();
return {
...base,
source: mics === 4 ? "codec" : base.source,
channelMask: mics === 4 ? 0b11 : 0b01,
codec: "raw",
format: "pcm16",
sampleRateHz: 16_000,
armHardware: true,
};
}
class MicArrayController {
private readonly statusListeners = new Set<(statuses: MicArrayStatuses) => void>();
private statuses: MicArrayStatuses = { left: null, right: null };
+29 -2
View File
@@ -1,5 +1,32 @@
import { type AppDefinition } from "../app-definition";
import { createTranscribeAppWindow, TRANSCRIBE_SURFACE_ID, TRANSCRIBE_WINDOW_ID } from "./transcribe-app";
import { type AppContext, type AppDefinition } from "../app-definition";
import {
createTranscribeAppWindow,
createTranscribeReplayWindow,
TRANSCRIBE_SURFACE_ID,
TRANSCRIBE_WINDOW_ID,
} from "./transcribe-app";
// Replay windows are closeable and non-singleton; the serial keeps their windowIds unique.
let nextReplaySerial = 1;
/**
* Open a recording (.mka) in Transcribe's replay mode, as a window of its
* own. Returns false where recordings can't be replayed.
*/
export function openRecordingInTranscribe(ctx: AppContext, path: string, name: string): boolean {
if (!ctx.actions.openVoiceReplay) return false;
const windowId = `transcribe:replay:${nextReplaySerial++}`;
void ctx
.launchInProcessApp(windowId, `window:${windowId}`, (options) => {
const window = createTranscribeReplayWindow(windowId, path, name, options);
if (!window) throw new Error("recordings can't be replayed here");
return window;
})
.catch((error) => {
ctx.appendLog(`transcribe replay window failed: ${error}`);
});
return true;
}
const transcribeApp: AppDefinition = {
appId: "transcribe",
+23
View File
@@ -0,0 +1,23 @@
/** A position in a recording as m:ss, or h:mm:ss from an hour on (or when `withHours`). */
export function formatReplayTime(ms: number, withHours = false): string {
const total = Math.max(0, Math.floor(ms / 1000));
const hours = Math.floor(total / 3600);
const minutes = Math.floor((total % 3600) / 60);
const seconds = String(total % 60).padStart(2, "0");
if (hours === 0 && !withHours) return `${minutes}:${seconds}`;
return `${hours}:${String(minutes).padStart(2, "0")}:${seconds}`;
}
/** The time picker's fields, in display and click order. */
export const TIME_FIELDS = ["hours", "minutes", "seconds"] as const;
export type TimeField = (typeof TIME_FIELDS)[number];
const FIELD_SECONDS: Record<TimeField, number> = { hours: 3600, minutes: 60, seconds: 1 };
/**
* Step a position (whole seconds) by `delta` of a field's unit, carrying
* into the neighboring fields, within [0, maxSeconds].
*/
export function stepReplaySeconds(seconds: number, field: TimeField, delta: number, maxSeconds: number): number {
return Math.max(0, Math.min(maxSeconds, seconds + delta * FIELD_SECONDS[field]));
}
+147
View File
@@ -0,0 +1,147 @@
import { GrayImage } from "../../graphics/image";
import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, gestureHints, type InputEvent } from "../../ui/gestures";
import type { Layer, LayerContext, PaintBelow } from "../../ui/layers";
import { CONTEXT_MENU_DIM } from "../../ui/menu";
import { centeredTextY } from "../../ui/metrics";
import { formatReplayTime, stepReplaySeconds, TIME_FIELDS, type TimeField } from "./replay-time";
const PADDING = 12;
const FIELD_GAP = 6;
const FIELD_PAD_X = 6;
/** Fill and outline of the active field (the Timers and date pickers' field style). */
const ACTIVE_FILL = 35;
const ACTIVE_STROKE = 130;
export type TimePickerOptions = {
title: string;
/** Where the picker starts, and the furthest it goes, in ms. */
initialMs: number;
maxMs: number;
onPick: (positionMs: number) => void;
};
/**
* A modal position picker for a recording: hours (when the recording has
* any), minutes and seconds, over the dimmed content beneath. Input follows
* the date picker's: scroll adjusts the active field (up is later, carrying
* into the fields beside it), click moves to the next field and on the last
* one picks, double-click steps back a field and on the first one cancels.
* A watch's swipes move between fields and adjust.
*/
export class TimePickerLayer implements Layer {
readonly acceptsDirectional = true;
readonly dimUnderneath = CONTEXT_MENU_DIM;
private readonly fields: readonly TimeField[];
private readonly maxSeconds: number;
private seconds: number;
private field = 0;
constructor(private readonly options: TimePickerOptions) {
this.maxSeconds = Math.max(0, Math.floor(options.maxMs / 1000));
this.seconds = Math.max(0, Math.min(this.maxSeconds, Math.floor(options.initialMs / 1000)));
this.fields = this.maxSeconds >= 3600 ? TIME_FIELDS : TIME_FIELDS.slice(1);
}
handleInput(event: InputEvent, ctx: LayerContext): void {
switch (event.type) {
case "scroll-up":
case "swipe-up":
this.adjust(1);
return;
case "scroll-down":
case "swipe-down":
this.adjust(-1);
return;
case "swipe-right":
this.field = Math.min(this.fields.length - 1, this.field + 1);
return;
case "swipe-left":
this.field = Math.max(0, this.field - 1);
return;
case "click":
if (this.field < this.fields.length - 1) {
this.field++;
} else {
ctx.stack.pop();
this.options.onPick(this.seconds * 1000);
}
return;
case "double-click":
if (this.field > 0) this.field--;
else ctx.stack.pop();
return;
default:
return;
}
}
private adjust(delta: number): void {
this.seconds = stepReplaySeconds(this.seconds, this.fields[this.field]!, delta, this.maxSeconds);
}
private hints(field: number): string {
return gestureHints([
[GESTURE_SCROLL, "adjust"],
[GESTURE_CLICK, field < this.fields.length - 1 ? "next" : "jump"],
[GESTURE_DOUBLE_CLICK, field > 0 ? "back" : "cancel"],
]);
}
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
const small = getDefaultSmallFont();
const medium = getDefaultMediumFont();
const focused = ctx.stack.isFocused();
const base = ctx.stack.getBaseSize();
const values = [
String(Math.floor(this.seconds / 3600)),
String(Math.floor((this.seconds % 3600) / 60)).padStart(this.fields.length === 3 ? 2 : 1, "0"),
String(this.seconds % 60).padStart(2, "0"),
].slice(TIME_FIELDS.length - this.fields.length);
// Sized for the widest value a field can show, so the dialog holds still while the time changes.
const fieldWidths = this.fields.map(
(field) => Math.max(medium.measureText("000"), small.measureText(field)) + 2 * FIELD_PAD_X,
);
const fieldsWidth = fieldWidths.reduce((sum, width) => sum + width, 0) + FIELD_GAP * (fieldWidths.length - 1);
const boxHeight = medium.lineHeight + 6;
const length = `of ${formatReplayTime(this.maxSeconds * 1000)}`;
const hintsWidth = Math.max(...this.fields.map((_, index) => small.measureText(this.hints(index))));
const width = Math.min(
base.width,
Math.max(fieldsWidth, hintsWidth, small.measureText(this.options.title), small.measureText(length)) + 2 * PADDING,
);
const titleHeight = small.lineHeight + 12;
const bodyHeight = boxHeight + 2 + small.lineHeight + 10 + small.lineHeight;
const height = Math.min(base.height, 8 + titleHeight + bodyHeight + 12 + small.lineHeight + 10);
const x = Math.max(0, Math.floor((base.width - width) / 2));
const y = Math.max(0, Math.floor((base.height - height) / 2));
// Fill 1, not 0: 0 is the transparent color key on the shell surface.
image.fillRoundedRect(x, y, width, height, 1);
image.drawRoundedRect(x, y, width, height, 72);
image.drawText(small, x + PADDING, y + 8, this.options.title, 220);
const top = y + 8 + titleHeight;
let fieldX = x + PADDING;
for (let index = 0; index < this.fields.length; index++) {
const fieldWidth = fieldWidths[index]!;
const active = index === this.field;
if (active) {
if (focused) image.fillRoundedRect(fieldX, top, fieldWidth, boxHeight, ACTIVE_FILL, 6);
image.drawRoundedRect(fieldX, top, fieldWidth, boxHeight, ACTIVE_STROKE, 6);
}
const value = values[index]!;
image.drawText(medium, fieldX + Math.floor((fieldWidth - medium.measureText(value)) / 2),
centeredTextY(medium, top, boxHeight), value, active ? 250 : 170);
const caption = this.fields[index]!;
image.drawText(small, fieldX + Math.floor((fieldWidth - small.measureText(caption)) / 2),
top + boxHeight + 2, caption, active ? 190 : 110);
fieldX += fieldWidth + FIELD_GAP;
}
image.drawText(small, x + PADDING, top + bodyHeight - small.lineHeight, length, 190);
image.drawText(small, x + PADDING, y + height - 10 - small.lineHeight, this.hints(this.field), 110);
return image;
}
}
+101 -4
View File
@@ -1,8 +1,11 @@
import { imageFromAsciiArt, type GrayImage } from "../../graphics/image";
import { voiceControlBridge } from "../../native/voice-control";
import { saveRecordingSetting, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import { enumSettingMenuItem, saveRecordingSetting, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import { type ContinuousCaptureOptions } from "../../ui/layers";
import { withRecordingIcon } from "../../ui/listening-header";
import { TimePickerLayer } from "./time-picker";
import { TranscribeLayer, transcriptTimestamp } from "./transcribe";
import { transcribeMicCount, transcribeMicsSetting } from "./transcribe-settings";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -45,8 +48,8 @@ export function micTrayIcon(recording: boolean): GrayImage {
}
export type TranscribeAppOptions = InProcessAppOptions & {
/** Begin continuous mic capture (kept on while the window is open). */
startContinuousVoiceCapture: (options?: { recordAs?: string }) => void;
/** Begin (or retarget) continuous mic capture, kept on while the window is open. */
startContinuousVoiceCapture: (options?: ContinuousCaptureOptions) => void;
stopContinuousVoiceCapture: () => void;
};
@@ -59,6 +62,10 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
// One timestamp per session names both the audio recording and a saved transcript.
const stamp = transcriptTimestamp();
const layer = new TranscribeLayer(stamp);
// At launch, and again when the Microphones setting changes: a running
// capture moves over to the microphones now asked for.
const startCapture = () =>
options.startContinuousVoiceCapture({ recordAs: `transcribe-${stamp}`, mics: transcribeMicCount() });
const app = createInProcessWindow({
appId: "transcribe",
windowId: TRANSCRIBE_WINDOW_ID,
@@ -78,6 +85,7 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
},
// The controller starts and stops the recording as the setting changes.
toggleSettingMenuItem(saveRecordingSetting),
enumSettingMenuItem(transcribeMicsSetting, { onChange: startCapture }),
],
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
@@ -97,7 +105,96 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
shell.setTrayIcon(TRAY_ICON_ID, micTrayIcon(voiceControlBridge.recording));
app.requestRender();
});
options.startContinuousVoiceCapture({ recordAs: `transcribe-${stamp}` });
startCapture();
shell.setTrayIcon(TRAY_ICON_ID, micTrayIcon(voiceControlBridge.recording));
return app;
}
/**
* Transcribe in replay mode: a window of its own that transcribes a
* recording (a .mka file from Save Recording) in place of the microphones,
* in real time and through the same pipeline. It neither uses the mic nor
* shows the mic tray icon, so it runs beside a live Transcribe window. The
* header shows the position in the recording; a tap pauses and resumes; the
* menu jumps to a time.
*/
export function createTranscribeReplayWindow(
windowId: string,
path: string,
name: string,
options: InProcessAppOptions,
): InProcessWindow | null {
const replay = options.actions.openVoiceReplay?.(path) ?? null;
if (!replay) return null;
// Names a saved transcript after the recording it came from.
const layer = new TranscribeLayer(name.replace(/\.[^.]+$/, ""), replay, name);
const app = createInProcessWindow({
appId: "transcribe",
windowId,
title: name,
iconLetter: "Tr",
icon: "mic",
closeable: true,
// Relaunching Transcribe after a restart would open the microphone, not this recording.
restoresApp: false,
// Like a playing video: something to watch, not to touch.
keepsScreenOn: () => replay.state === "playing",
actions: options.actions,
baseLayer: new YieldAtRootLayer(layer),
menuItems: () => [
{
label: "Jump to time",
// The length isn't known until the recording has been opened.
disabled: () => replay.durationMs <= 0,
onSelect: (ctx) => {
ctx.stack.pop();
ctx.stack.push(
new TimePickerLayer({
title: "Jump to time",
initialMs: replay.positionMs,
maxMs: replay.durationMs,
onPick: (positionMs) => {
replay.jumpTo(positionMs);
app.requestRender();
},
}),
);
},
},
{
label: replay.state === "paused" ? "Resume" : "Pause",
disabled: () => replay.state !== "playing" && replay.state !== "paused",
onSelect: (ctx) => {
ctx.stack.pop();
replay.setPaused(replay.state === "playing");
},
},
{
label: "Restart from 0:00",
onSelect: (ctx) => {
ctx.stack.pop();
replay.jumpTo(0);
},
},
{
label: "Save",
onSelect: (ctx) => {
ctx.stack.pop();
layer.saveTranscript();
},
},
],
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: () => {
layer.onRemoved();
replay.close();
options.onClosed();
},
});
// Started first, so the layer picks its opening status up as it subscribes.
replay.start();
layer.start(app.requestRender, () => shell.isWindowVisible(windowId));
return app;
}
@@ -0,0 +1,40 @@
import { ConfigSettingEnum, glassesTypeSetting } from "../../ui/dashboard-settings";
import { type MicCount } from "../../ui/layers";
import { micControlSupported } from "../microphones/mic-control";
export type TranscribeMics = "1" | "2" | "4";
const MICS_LABELS: Record<TranscribeMics, string> = {
"1": "1 (mixed)",
"2": "2 (one per temple)",
"4": "4 (two per temple)",
};
/** Whether the paired glasses can stream their microphones separately (G2, with the microphone channel in use). */
export function separateMicsSupported(): boolean {
return glassesTypeSetting.get() === "g2" && micControlSupported();
}
/**
* How many of the glasses' microphones Transcribe captures. With more than
* one, the temples stream their own microphones (each temple on its own
* clock) instead of the glasses' mixed stream; a recording keeps every one,
* and what is transcribed is a mix made on the phone.
*/
export const transcribeMicsSetting = new ConfigSettingEnum<TranscribeMics>({
id: "transcribe-mics",
label: "Microphones",
storageKey: "transcribe.mics",
defaultValue: "1",
values: ["1", "2", "4"],
formatValue: (value) => MICS_LABELS[value],
isDisabled: (value) => value !== "1" && !separateMicsSupported(),
description:
"Which of the glasses' microphones to capture. 1 is the glasses' own mixed stream. 2 and 4 stream each temple's microphones separately (custom firmware), so a saved recording has every microphone on its own channel; the transcript then comes from a mix made on the phone.",
});
/** The setting as a capture option; 1 where the glasses can't stream their microphones separately. */
export function transcribeMicCount(): MicCount {
if (!separateMicsSupported()) return 1;
return Number(transcribeMicsSetting.get()) as MicCount;
}
+72 -13
View File
@@ -3,15 +3,20 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { lineStep } from "../../ui/metrics";
import { MicLevelMeter, paintListeningHeader, RECORDING_FAILED_NOTICE } from "../../ui/listening-header";
import { writeTextToDownloads } from "../../native/file-access";
import { voiceControlBridge } from "../../native/voice-control";
import { voiceControlBridge, type VoiceEventSource, type VoiceReplay } from "../../native/voice-control";
import { Layer, type LayerContext } from "../../ui/layers";
import { type InputEvent } from "../../ui/gestures";
import { formatReplayTime } from "./replay-time";
import { TranscriptModel, TranscriptScroll, transcriptLayout, wrapTranscribeText } from "./transcript-model";
/**
* Live transcription view. Continuous mic capture is owned by the app wrapper
* (createTranscribeAppWindow); this layer accumulates the transcript, shows
* it, and saves it to Downloads from the app menu.
*
* Given a replay, it transcribes that recording instead of the microphone:
* the header shows the position in the recording, a tap pauses and resumes,
* and each jump leaves its time as a line in the transcript.
*/
export class TranscribeLayer implements Layer {
private status = "Starting microphone...";
@@ -24,25 +29,67 @@ export class TranscribeLayer implements Layer {
private unsubscribeTranscript: (() => void) | null = null;
private unsubscribePause: (() => void) | null = null;
private unsubscribeStatus: (() => void) | null = null;
private unsubscribeReplay: (() => void) | null = null;
private readonly source: VoiceEventSource;
/** `stamp` names the saved transcript, matching the session's audio recording. */
constructor(private readonly stamp: string = transcriptTimestamp()) {}
/**
* `stamp` names the saved transcript, matching the session's audio
* recording. `replay` is the recording to transcribe in place of the
* microphone; `replayName` is what to call it.
*/
constructor(
private readonly stamp: string = transcriptTimestamp(),
private readonly replay: VoiceReplay | null = null,
private readonly replayName = "",
) {
this.source = replay ? replay.events : voiceControlBridge;
if (replay) this.status = "Opening the recording...";
}
/** `isVisible` says whether the window is on screen (the level meter repaints only then). */
/** `isVisible` says whether the window is on screen (the level meter and replay clock repaint only then). */
start(requestRender: () => void, isVisible: () => boolean): void {
this.meter.start(requestRender, isVisible);
this.unsubscribeTranscript = voiceControlBridge.onTranscript((event) => {
this.meter.start(requestRender, isVisible, this.source);
this.unsubscribeTranscript = this.source.onTranscript((event) => {
this.transcript.accept(event);
requestRender();
});
this.unsubscribePause = voiceControlBridge.onSpeechPause(() => this.transcript.pause());
this.unsubscribeStatus = voiceControlBridge.onStatus((state) => {
this.unsubscribePause = this.source.onSpeechPause(() => this.transcript.pause());
// The current status arrives while subscribing, before the window has a
// surface to render to; the window paints it when it is first shown.
let subscribing = true;
this.unsubscribeStatus = this.source.onStatus((state) => {
this.status = state.status;
this.listening = state.listening;
this.detail = state.detail;
this.saveNotice = "";
requestRender();
if (!subscribing) requestRender();
});
subscribing = false;
const replay = this.replay;
if (replay) {
let shownSecond = -1;
let shownState = replay.state;
this.unsubscribeReplay = replay.onChange((jumpedToMs) => {
if (jumpedToMs !== undefined) this.transcript.mark(`[${formatReplayTime(jumpedToMs)}]`);
// The clock ticks in whole seconds; repaint when what it shows changed.
const second = Math.floor(replay.positionMs / 1000);
if (jumpedToMs === undefined && second === shownSecond && replay.state === shownState) return;
shownSecond = second;
shownState = replay.state;
if (isVisible()) requestRender();
});
}
}
/** The header's status for a replay: where it is in the recording, and anything worth saying beside that. */
private replayStatus(replay: VoiceReplay): string {
if (replay.state === "failed" || (replay.state === "opening" && replay.durationMs === 0)) return this.status;
const withHours = replay.durationMs >= 3_600_000;
const clock = `${formatReplayTime(replay.positionMs, withHours)} / ${formatReplayTime(replay.durationMs, withHours)}`;
if (replay.state === "paused") return `${clock} · Paused`;
if (replay.state === "ended") return `${clock} · Finished`;
// Anything but plain listening is worth showing: the model loading, a provider reconnecting.
return this.listening ? clock : `${clock} · ${this.status}`;
}
paint(ctx: LayerContext): GrayImage {
@@ -50,14 +97,19 @@ export class TranscribeLayer implements Layer {
const viewport = ctx.stack.getBaseSize();
const image = new GrayImage(viewport.width, viewport.height, 0);
const status = voiceControlBridge.recordingFailed ? RECORDING_FAILED_NOTICE : this.status;
const replay = this.replay;
const status = replay
? this.replayStatus(replay)
: this.source.recordingFailed ? RECORDING_FAILED_NOTICE : this.status;
const playing = !replay || replay.state === "playing";
const bodyTop = paintListeningHeader(
image, font, "Transcribe", this.saveNotice || status, this.listening ? this.meter : null, viewport.padding,
voiceControlBridge.recording,
image, font, "Transcribe", this.saveNotice || status, this.listening && playing ? this.meter : null, viewport.padding,
this.source.recording,
);
const step = lineStep(font) + 2;
const layout = transcriptLayout(viewport, bodyTop, font.lineHeight, step);
const text = this.transcript.text || (this.listening ? "Listening..." : this.detail);
const placeholder = replay ? `Replaying ${this.replayName}` : "Listening...";
const text = this.transcript.text || (this.listening ? placeholder : this.detail);
const wrapped = wrapTranscribeText((line) => font.measureText(line), text, layout.textWidth);
const firstLine = this.scroll.layout(wrapped.length, layout.pageLines);
@@ -82,6 +134,11 @@ export class TranscribeLayer implements Layer {
ctx.actions.requestRender();
return;
}
if (event.type === "click" && this.replay) {
this.replay.setPaused(this.replay.state === "playing");
ctx.actions.requestRender();
return;
}
if (event.type === "double-click") {
ctx.stack.pop();
}
@@ -89,6 +146,8 @@ export class TranscribeLayer implements Layer {
onRemoved(): void {
this.meter.stop();
this.unsubscribeReplay?.();
this.unsubscribeReplay = null;
this.unsubscribePause?.();
this.unsubscribePause = null;
this.unsubscribeTranscript?.();
+12
View File
@@ -36,6 +36,18 @@ export class TranscriptModel {
if (this.live) this.breakAfterLive = true;
else if (this.finalized) this.separator = "\n";
}
/**
* A line of its own (where a replay jumped to), ending whatever was in
* progress: what follows it starts a new paragraph.
*/
mark(label: string): void {
const before = this.text;
this.finalized = before ? `${before}\n${label}` : label;
this.live = "";
this.separator = "\n";
this.breakAfterLive = false;
}
}
/** An absolute history position, with an explicit follow-tail mode. */