Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor media transcription logic to simplify parameters and improve clarity

konstantin-paulus5da1a203a867
diff --git a/apps/cli/src/cli-channels.ts b/apps/cli/src/cli-channels.ts
index 50043d32..44fa2809 100644
--- a/apps/cli/src/cli-channels.ts
+++ b/apps/cli/src/cli-channels.ts
@@ -120,7 +120,7 @@ export type MediaFrameRequest = AssetRef & {
};
export type MediaFrameResult = Array<{ time: number; base64: string }>;
-export type MediaTranscribeRequest = AssetRef & { start?: number; end?: number };
+export type MediaTranscribeRequest = AssetRef;
export type TranscriptWord = { text: string; start: number; end: number };
export type TranscriptSegment = { text: string; words: TranscriptWord[] };
export type MediaTranscribeResult = { segments: TranscriptSegment[] };
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts
index 781244e8..2619b2c1 100644
--- a/apps/cli/src/index.ts
+++ b/apps/cli/src/index.ts
@@ -552,20 +552,11 @@ async function mediaProbe(ref: string): Promise<void> {
}
}
-type MediaTranscribeOptions = { start?: string; end?: string };
-
-async function mediaTranscribe(ref: string, opts: MediaTranscribeOptions): Promise<void> {
- const start = opts.start !== undefined ? parseTimeArg(opts.start, "--start") : undefined;
- const end = opts.end !== undefined ? parseTimeArg(opts.end, "--end") : undefined;
- if (start !== undefined && end !== undefined && start >= end) {
- console.error(`--start (${start}s) must be less than --end (${end}s).`);
- process.exit(1);
- }
-
+async function mediaTranscribe(ref: string): Promise<void> {
const target = resolveAssetRef(ref);
const stop = startSpinner("Transcribing asset");
try {
- const result = await editor.media.transcribe.query({ ...target, start, end }, GENERATE);
+ const result = await editor.media.transcribe.query(target, GENERATE);
stop();
console.log(JSON.stringify(result));
} catch (e) {
@@ -1219,9 +1210,7 @@ media
`Transcribe the speech in a video or audio file and print the timed transcript, with word-level start/end times in seconds. Commonly useful for footage with speakers (talking head, interview), where the word times let you cut on a line. A transcript marks only speech; the gaps are not necessarily silent (music, score, applause).`,
)
.argument("<id|path>", "video or audio asset id, or a local file")
- .option("-s, --start <time>", `start of the range to print — seconds, "45f" frames, or "MM:SS" (default: 0); --start/--end only limit which words print, the whole asset is always transcribed`)
- .option("-e, --end <time>", `end of the range to print — seconds, "45f" frames, or "MM:SS" (default: asset duration)`)
- .action((ref: string, opts: MediaTranscribeOptions) => mediaTranscribe(ref, opts));
+ .action((ref: string) => mediaTranscribe(ref));
media
.command("grab")
diff --git a/apps/web/src/context/editor-api/media.ts b/apps/web/src/context/editor-api/media.ts
index 550c7c76..35bcc4c1 100644
--- a/apps/web/src/context/editor-api/media.ts
+++ b/apps/web/src/context/editor-api/media.ts
@@ -211,7 +211,6 @@ const transcripts = new Map<string, TranscriptSegment[]>();
export function handleMediaTranscribe(engine: Accessor<Engine>) {
return async (req: MediaTranscribeRequest): Promise<MediaTranscribeResult> => {
- const { start, end } = req;
const { world } = engine();
const asset = await resolveAssetRef(world, req);
const id = asset.id;
@@ -235,27 +234,10 @@ export function handleMediaTranscribe(engine: Accessor<Engine>) {
transcripts.set(asset.hash, transcript);
}
- return { segments: sliceTranscript(transcript, start, end) };
+ return { segments: transcript };
};
}
-function sliceTranscript(segments: TranscriptSegment[], start?: number, end?: number): TranscriptSegment[] {
- if (start === undefined && end === undefined) return segments;
- const from = start ?? 0;
- const to = end ?? Infinity;
- const sliced: TranscriptSegment[] = [];
- for (const segment of segments) {
- const words = segment.words.filter((w) => w.end > from && w.start < to);
- if (!words.length) continue;
- sliced.push(
- words.length === segment.words.length
- ? segment
- : { text: words.map((w) => w.text).join(" "), words },
- );
- }
- return sliced;
-}
-
export function handleMediaFilmstrip(engine: Accessor<Engine>) {
return async (req: MediaFilmstripRequest): Promise<MediaFilmstripResult> => {
const { world } = engine();
diff --git a/reference/media/transcribe.md b/reference/media/transcribe.md
index 0a0b28ee..5b1655b2 100644
--- a/reference/media/transcribe.md
+++ b/reference/media/transcribe.md
@@ -1,4 +1,4 @@
-# `dapi media transcribe [options] <id|path>`
+# `dapi media transcribe <id|path>`
Transcribes the speech in a video or audio asset and returns the timed transcript. Word-level start/end times are in **seconds** (source/content time).
@@ -6,12 +6,7 @@ Transcribes the speech in a video or audio asset and returns the timed transcrip
- `<id|path>`: a video or audio asset id, or a local file to transcribe in place without adding it to the library (required).
-## Options
-
-- `-s, --start <time>`: start of the range to print — seconds (`"1.5"`), frames (`"45f"`), or `"MM:SS"` (default: `0`).
-- `-e, --end <time>`: end of the range to print — same formats (default: the asset duration).
-
-The whole asset is always transcribed once per app session (cached in memory, keyed by file content, for ids and paths alike; an app restart or an edited file re-transcribes); the range only limits which words are printed. Words keep their absolute source-time timestamps, and segments that straddle a range boundary are trimmed to the words inside it. A range with no speech yields `segments: []`.
+The whole asset is transcribed once per app session (cached in memory, keyed by file content, for ids and paths alike; an app restart or an edited file re-transcribes).
## Output
@@ -28,4 +23,4 @@ One JSON object, the transcript:
## Errors
-Exits non-zero if the id is unknown or the asset is not a video/audio asset, if `--start`/`--end` are malformed or `--start >= --end`, or if no speech is detected in the audio at all (`No speech detected`).
+Exits non-zero if the id is unknown or the asset is not a video/audio asset, or if no speech is detected in the audio at all (`No speech detected`).