Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(transcript): reshape the source transcript modal and wire per-asset regeneration

Etienne Lescot05b87c42a855
diff --git a/electron/ai-edition/provider-registry.ts b/electron/ai-edition/provider-registry.ts
index 34572e311..8fc1bc24a 100644
--- a/electron/ai-edition/provider-registry.ts
+++ b/electron/ai-edition/provider-registry.ts
@@ -113,7 +113,11 @@ export const PROVIDER_DEFINITIONS: ProviderDefinition[] = [
authKind: "api-key",
supportsReasoningEffort: true,
wireProtocol: "anthropic",
- baseUrl: "https://api.minimax.io/anthropic",
+ // ponytail: docs (platform.minimax.io) tell you to set ANTHROPIC_BASE_URL
+ // to https://api.minimax.io/anthropic — but the real `/messages` path
+ // is /anthropic/v1/messages, and `/anthropic/messages` returns a 404
+ // from the upstream gateway. Empirically verified against the live API.
+ baseUrl: "https://api.minimax.io/anthropic/v1",
envKeys: ["MINIMAX_API_KEY"],
setupHint: "Use MINIMAX_API_KEY or paste a MiniMax API key.",
},
@@ -124,7 +128,7 @@ export const PROVIDER_DEFINITIONS: ProviderDefinition[] = [
authKind: "api-key",
supportsReasoningEffort: true,
wireProtocol: "anthropic",
- baseUrl: "https://api.minimax.io/anthropic",
+ baseUrl: "https://api.minimax.io/anthropic/v1",
envKeys: ["MINIMAX_TOKEN_PLAN_API_KEY"],
setupHint: "Use MINIMAX_TOKEN_PLAN_API_KEY or paste a MiniMax token-plan API key.",
},
diff --git a/src/components/ai-edition/LeftPanel.tsx b/src/components/ai-edition/LeftPanel.tsx
index c0a14f781..d791ede49 100644
--- a/src/components/ai-edition/LeftPanel.tsx
+++ b/src/components/ai-edition/LeftPanel.tsx
@@ -28,21 +28,6 @@ const REASONING_EFFORT_LABELS: Record<ReasoningEffort, string> = {
export type LeftTab = "chat" | "media";
-function formatTranscriptText(t: unknown): string {
- if (!t || typeof t !== "object") return "";
- const obj = t as Record<string, unknown>;
- const segments = (obj.segments as Array<Record<string, unknown>>) ?? [];
- if (segments.length === 0) return "";
- return segments
- .map((s, i) => {
- const start = s.startSec ?? s.start ?? "?";
- const end = s.endSec ?? s.end ?? "?";
- const text = s.text ?? "";
- return `[${i + 1}] ${start}s–${end}s: ${text}`;
- })
- .join("\n");
-}
-
const THUMB_PALETTE = ["thumbRed", "thumbGreen", "thumbAmber", "thumbCyan"] as const;
function formatTimecode(sec: number | undefined): string {
@@ -186,8 +171,10 @@ function MediaList({
export function MediaPane({
assetStatuses,
+ onRegenerateAsset,
}: {
assetStatuses?: Record<string, "pending" | "running" | "failed">;
+ onRegenerateAsset?: (assetId: string, language: string) => Promise<void>;
}) {
const projectId = useProjectStore((s) => s.projectId);
const document = useProjectStore((s) => s.document);
@@ -321,14 +308,17 @@ export function MediaPane({
assetLabel={srcTranscriptAsset?.label ?? ""}
assetPath={srcTranscriptAsset?.originalPath ?? ""}
tcFormatted={formatTimecode(srcTranscriptAsset?.durationSec)}
- transcriptText={
+ transcript={
srcTranscriptAsset && document?.transcripts
- ? (() => {
- const t = document.transcripts.find((t) => t.assetId === srcTranscriptAsset.id);
- return t ? formatTranscriptText(t) : null;
- })()
+ ? (document.transcripts.find((t) => t.assetId === srcTranscriptAsset.id) ?? null)
: null
}
+ isTranscribing={assetStatuses?.[srcTranscriptAsset?.id ?? ""] === "running"}
+ isFailed={assetStatuses?.[srcTranscriptAsset?.id ?? ""] === "failed"}
+ onRegenerate={(language) => {
+ if (!srcTranscriptAsset || !onRegenerateAsset) return Promise.resolve();
+ return onRegenerateAsset(srcTranscriptAsset.id, language);
+ }}
/>
</aside>
);
@@ -337,14 +327,16 @@ export function MediaPane({
export function LeftPanel({
active,
assetStatuses,
+ onRegenerateAsset,
}: {
active: LeftTab;
assetStatuses?: Record<string, "pending" | "running" | "failed">;
+ onRegenerateAsset?: (assetId: string, language: string) => Promise<void>;
}) {
return active === "chat" && AI_FEATURES_ENABLED ? (
<ChatStripPanel />
) : (
- <MediaPane assetStatuses={assetStatuses} />
+ <MediaPane assetStatuses={assetStatuses} onRegenerateAsset={onRegenerateAsset} />
);
}
diff --git a/src/components/ai-edition/Modals.tsx b/src/components/ai-edition/Modals.tsx
index db8ae494f..8766fdc30 100644
--- a/src/components/ai-edition/Modals.tsx
+++ b/src/components/ai-edition/Modals.tsx
@@ -1,4 +1,17 @@
-import { AlertTriangle, Crop, FolderOpen, FolderPlus, Pencil, Plus, X } from "lucide-react";
+import {
+ AlertTriangle,
+ Crop,
+ FolderOpen,
+ FolderPlus,
+ Loader2,
+ Maximize2,
+ Pencil,
+ Plus,
+ RefreshCw,
+ RotateCcw,
+ Triangle,
+ X,
+} from "lucide-react";
import {
type ReactNode,
type PointerEvent as ReactPointerEvent,
@@ -6,12 +19,54 @@ import {
useRef,
useState,
} from "react";
+import { toFileUrl } from "@/components/video-editor/projectPersistence";
import type { CropRegion } from "@/components/video-editor/types";
-import type { AxcutClip } from "@/lib/ai-edition/schema";
+import { toAxcutTranscriptDsl } from "@/lib/ai-edition/document/transcribe";
+import type { AxcutClip, AxcutTranscript } from "@/lib/ai-edition/schema";
import { formatSeconds } from "@/lib/ai-edition/timeline/virtual-preview";
import styles from "./NewEditorShell.module.css";
import { type VideoSource, VirtualPreview } from "./VirtualPreview";
+// ponytail: keep the UI's language list literal in one place. Mirrors
+// `transcriptLanguageSchema` in schema/index.ts; if the schema gains a
+// language, add it here too.
+const REGEN_LANGUAGES = [
+ "auto",
+ "en",
+ "fr",
+ "de",
+ "es",
+ "it",
+ "pt",
+ "nl",
+ "ja",
+ "ko",
+ "zh",
+] as const;
+
+type TranscriptLanguage = (typeof REGEN_LANGUAGES)[number];
+
+const LANGUAGE_LABELS: Record<TranscriptLanguage, string> = {
+ auto: "Auto",
+ en: "EN",
+ fr: "FR",
+ de: "DE",
+ es: "ES",
+ it: "IT",
+ pt: "PT",
+ nl: "NL",
+ ja: "JA",
+ ko: "KO",
+ zh: "ZH",
+};
+
+function formatTc(sec: number): string {
+ if (!Number.isFinite(sec) || sec < 0) return "0:00.0";
+ const m = Math.floor(sec / 60);
+ const s = sec - m * 60;
+ return `${m}:${s.toFixed(1).padStart(4, "0")}`;
+}
+
interface BaseModalProps {
open: boolean;
onClose: () => void;
@@ -1075,42 +1130,390 @@ export interface SourceTranscriptModalProps extends BaseModalProps {
assetLabel: string;
assetPath: string;
tcFormatted: string;
- transcriptText: string | null;
+ transcript: AxcutTranscript | null;
+ isTranscribing: boolean;
+ isFailed: boolean;
+ onRegenerate: (language: TranscriptLanguage) => void;
}
export function SourceTranscriptModal({
open,
onClose,
assetLabel,
+ assetPath,
tcFormatted,
- transcriptText,
+ transcript,
+ isTranscribing,
+ isFailed,
+ onRegenerate,
}: SourceTranscriptModalProps) {
+ const videoRef = useRef<HTMLVideoElement | null>(null);
+ const [isPlaying, setIsPlaying] = useState(false);
+ const [playTime, setPlayTime] = useState(0);
+ const [duration, setDuration] = useState<number | null>(null);
+ const [regenLang, setRegenLang] = useState<TranscriptLanguage>(
+ (transcript?.language as TranscriptLanguage) ?? "auto",
+ );
+
+ // ponytail: sync the language picker to whatever the stored transcript was
+ // generated with. Avoids surprising the user with a different selection on
+ // every open after a regenerate.
+ useEffect(() => {
+ if (open) setRegenLang((transcript?.language as TranscriptLanguage) ?? "auto");
+ }, [open, transcript?.language]);
+
+ useEffect(() => {
+ if (!open) {
+ setIsPlaying(false);
+ setPlayTime(0);
+ setDuration(null);
+ const v = videoRef.current;
+ if (v) {
+ v.pause();
+ v.currentTime = 0;
+ }
+ }
+ }, [open]);
+
+ const detectedLanguage =
+ transcript?.language && transcript.language !== "auto" ? transcript.language : null;
+
+ const statusLabel = isTranscribing
+ ? "Generating"
+ : isFailed
+ ? "Generation failed"
+ : transcript
+ ? "Generated"
+ : "Not generated yet";
+
+ const transcriptBody = transcript
+ ? toAxcutTranscriptDsl(transcript, assetLabel || undefined, duration ?? undefined)
+ : null;
+
+ const playLabel = isPlaying ? "Pause" : "Play";
+
+ const togglePlay = () => {
+ const v = videoRef.current;
+ if (!v) return;
+ if (v.paused) {
+ void v.play();
+ } else {
+ v.pause();
+ }
+ };
+
+ const restart = () => {
+ const v = videoRef.current;
+ if (!v) return;
+ v.currentTime = 0;
+ setPlayTime(0);
+ };
+
+ const requestFullscreen = () => {
+ const v = videoRef.current;
+ if (!v) return;
+ void v.requestFullscreen?.();
+ };
+
return (
- <ModalShell open={open} onClose={onClose} title="Source transcript" subtitle={assetLabel} wide>
- <div style={{ display: "flex", gap: 12, marginBottom: 12, flexWrap: "wrap" }}>
- <span
- style={{
- padding: "4px 10px",
- borderRadius: 999,
- background: "var(--success-soft)",
- color: "var(--success)",
- font: "500 12px var(--font-body)",
- border: "1px solid color-mix(in srgb, var(--success) 22%, transparent)",
- }}
- >
- {transcriptText ? "Generated" : "Not generated yet"}
- </span>
- <span
+ <ModalShell open={open} onClose={onClose} title="Source Transcript" subtitle={assetLabel} wide>
+ <div
+ style={{
+ display: "grid",
+ gridTemplateColumns: "minmax(220px, 320px) 1fr",
+ gap: 14,
+ }}
+ >
+ <div
style={{
- font: "500 12px/1.4 var(--font-mono)",
- color: "var(--muted)",
- alignSelf: "center",
+ position: "relative",
+ aspectRatio: "16 / 9",
+ borderRadius: "var(--r-md)",
+ overflow: "hidden",
+ background: "linear-gradient(135deg, #16171d, #16171d)",
+ border: "1px solid var(--border)",
}}
>
- {tcFormatted}
- </span>
+ {assetPath ? (
+ <video
+ ref={videoRef}
+ src={toFileUrl(assetPath)}
+ style={{
+ width: "100%",
+ height: "100%",
+ objectFit: "contain",
+ background: "#16171d",
+ }}
+ preload="metadata"
+ onLoadedMetadata={(e) => setDuration(e.currentTarget.duration)}
+ onTimeUpdate={(e) => setPlayTime(e.currentTarget.currentTime)}
+ onPlay={() => setIsPlaying(true)}
+ onPause={() => setIsPlaying(false)}
+ onEnded={() => setIsPlaying(false)}
+ />
+ ) : (
+ <div
+ style={{
+ width: "100%",
+ height: "100%",
+ display: "grid",
+ placeItems: "center",
+ color: "var(--muted)",
+ font: "500 12px var(--font-body)",
+ }}
+ >
+ No preview available
+ </div>
+ )}
+ <div
+ style={{
+ position: "absolute",
+ left: 0,
+ right: 0,
+ bottom: 0,
+ display: "flex",
+ alignItems: "center",
+ gap: 8,
+ padding: "8px 10px",
+ background: "linear-gradient(180deg, transparent, rgba(22,23,29,.55))",
+ color: "#fff",
+ }}
+ >
+ <button
+ type="button"
+ aria-label={playLabel}
+ title={playLabel}
+ onClick={togglePlay}
+ style={{
+ background: "transparent",
+ border: 0,
+ color: "inherit",
+ cursor: "pointer",
+ padding: 2,
+ borderRadius: 4,
+ display: "inline-flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ {isPlaying ? (
+ <span style={{ display: "inline-flex", gap: 2 }}>
+ <span
+ style={{
+ width: 4,
+ height: 12,
+ background: "currentColor",
+ borderRadius: 1,
+ }}
+ />
+ <span
+ style={{
+ width: 4,
+ height: 12,
+ background: "currentColor",
+ borderRadius: 1,
+ }}
+ />
+ </span>
+ ) : (
+ <Triangle size={12} fill="currentColor" style={{ transform: "rotate(0deg)" }} />
+ )}
+ </button>
+ <button
+ type="button"
+ aria-label="Restart"
+ title="Restart"
+ onClick={restart}
+ style={{
+ background: "transparent",
+ border: 0,
+ color: "inherit",
+ cursor: "pointer",
+ padding: 2,
+ borderRadius: 4,
+ display: "inline-flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ <RotateCcw size={13} />
+ </button>
+ <button
+ type="button"
+ aria-label="Fullscreen"
+ title="Fullscreen"
+ onClick={requestFullscreen}
+ style={{
+ background: "transparent",
+ border: 0,
+ color: "inherit",
+ cursor: "pointer",
+ padding: 2,
+ borderRadius: 4,
+ display: "inline-flex",
+ alignItems: "center",
+ justifyContent: "center",
+ }}
+ >
+ <Maximize2 size={13} />
+ </button>
+ <span
+ style={{
+ marginLeft: "auto",
+ font: "500 12px/1 var(--font-mono)",
+ display: "inline-flex",
+ alignItems: "baseline",
+ gap: 4,
+ }}
+ >
+ <strong>{formatTc(playTime)}</strong>
+ <i style={{ fontStyle: "normal", opacity: 0.55, margin: "0 2px" }}>/</i>
+ <span style={{ opacity: 0.8 }}>{duration ? formatTc(duration) : tcFormatted}</span>
+ </span>
+ {isTranscribing ? (
+ <span
+ style={{
+ width: 8,
+ height: 8,
+ borderRadius: "50%",
+ background: "var(--accent)",
+ boxShadow: "0 0 0 3px var(--accent-soft)",
+ marginLeft: 6,
+ }}
+ aria-label="Transcribing"
+ />
+ ) : (
+ <span
+ style={{
+ width: 8,
+ height: 8,
+ borderRadius: "50%",
+ background: isFailed ? "var(--danger)" : "var(--danger)",
+ boxShadow: isFailed
+ ? "0 0 0 3px var(--danger-soft)"
+ : "0 0 0 3px rgba(239, 68, 68, 0.2)",
+ marginLeft: 6,
+ }}
+ aria-hidden
+ />
+ )}
+ </div>
+ </div>
+ <div style={{ display: "flex", flexDirection: "column", gap: 12, minWidth: 0 }}>
+ <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
+ <span
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ gap: 6,
+ padding: "6px 12px",
+ borderRadius: 999,
+ background: isFailed ? "var(--danger-soft)" : "var(--success-soft)",
+ color: isFailed ? "var(--danger)" : "var(--success)",
+ font: "500 12px var(--font-body)",
+ border: `1px solid color-mix(in srgb, ${isFailed ? "var(--danger)" : "var(--success)"} 22%, transparent)`,
+ }}
+ >
+ {isTranscribing ? (
+ <Loader2 size={11} className="animate-spin" />
+ ) : (
+ <span
+ style={{
+ width: 7,
+ height: 7,
+ borderRadius: "50%",
+ background: isFailed ? "var(--danger)" : "var(--success)",
+ }}
+ />
+ )}
+ {statusLabel}
+ </span>
+ {detectedLanguage ? (
+ <span
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ padding: "6px 12px",
+ borderRadius: 999,
+ background: "var(--success-soft)",
+ color: "var(--success)",
+ font: "500 12px var(--font-body)",
+ border: "1px solid color-mix(in srgb, var(--success) 22%, transparent)",
+ }}
+ >
+ Detected language: {detectedLanguage}
+ </span>
+ ) : null}
+ </div>
+ <div style={{ display: "flex", flexDirection: "column", gap: 6 }}>
+ <label
+ style={{
+ font: "500 12px/1 var(--font-body)",
+ color: "var(--muted)",
+ }}
+ >
+ Regenerate as
+ </label>
+ <div
+ style={{
+ display: "grid",
+ gridTemplateColumns: "1fr auto",
+ gap: 8,
+ alignItems: "center",
+ }}
+ >
+ <select
+ aria-label="Regenerate as"
+ value={regenLang}
+ disabled={isTranscribing}
+ onChange={(e) => setRegenLang(e.target.value as TranscriptLanguage)}
+ style={{
+ width: "100%",
+ padding: "10px 12px",
+ borderRadius: "var(--r-md)",
+ border: "1px solid var(--border)",
+ background: "var(--surface)",
+ color: "var(--fg)",
+ font: "500 13px var(--font-body)",
+ }}
+ >
+ {REGEN_LANGUAGES.map((code) => (
+ <option key={code} value={code}>
+ {LANGUAGE_LABELS[code]}
+ </option>
+ ))}
+ </select>
+ <button
+ type="button"
+ title="Regenerate"
+ aria-label="Regenerate"
+ disabled={isTranscribing}
+ onClick={() => onRegenerate(regenLang)}
+ style={{
+ width: 38,
+ height: 38,
+ borderRadius: "var(--r-md)",
+ border: "1px solid var(--border)",
+ background: "var(--surface)",
+ color: "var(--fg)",
+ cursor: isTranscribing ? "not-allowed" : "pointer",
+ display: "inline-flex",
+ alignItems: "center",
+ justifyContent: "center",
+ opacity: isTranscribing ? 0.6 : 1,
+ }}
+ >
+ {isTranscribing ? (
+ <Loader2 size={15} className="animate-spin" />
+ ) : (
+ <RefreshCw size={15} />
+ )}
+ </button>
+ </div>
+ </div>
+ </div>
</div>
- {transcriptText ? (
+ {transcriptBody ? (
<pre
style={{
margin: 0,
@@ -1122,10 +1525,10 @@ export function SourceTranscriptModal({
color: "var(--fg)",
whiteSpace: "pre",
overflow: "auto",
- maxHeight: "40vh",
+ maxHeight: "38vh",
}}
>
- {transcriptText}
+ {transcriptBody}
</pre>
) : (
<div
@@ -1134,9 +1537,15 @@ export function SourceTranscriptModal({
textAlign: "center",
color: "var(--muted)",
font: "500 13px var(--font-body)",
+ border: "1px dashed var(--border)",
+ borderRadius: "var(--r-md)",
}}
>
- Transcribe the asset first using the Transcript pane on the right.
+ {isFailed
+ ? "Generation failed — pick a language and regenerate."
+ : isTranscribing
+ ? "Transcribing…"
+ : "Not generated yet — pick a language and click regenerate."}
</div>
)}
</ModalShell>
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index e8368d801..b38bc3b75 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -363,6 +363,40 @@ export function NewEditorShell() {
}
}, [document, setTranscript]);
+ // Per-asset regenerate fired from the Source Transcript modal. Same
+ // pipeline as `handleTranscribe` but takes any assetId + a target
+ // language — `transcribeAsset` already accepts `language` and `setTranscript`
+ // replaces the matching entry in `doc.transcripts`.
+ const handleRegenerateAsset = useCallback(
+ async (assetId: string, language: string) => {
+ const doc = useProjectStore.getState().document;
+ if (!doc) return;
+ setAssetStatuses((prev) => ({ ...prev, [assetId]: "running" }));
+ toast.loading(`Regenerating: ${language}`, { id: `regen-${assetId}` });
+ try {
+ const transcript = await transcribeAsset(doc, assetId, {
+ language,
+ onStatus: (s) => toast.loading(`Regenerating: ${s}`, { id: `regen-${assetId}` }),
+ });
+ await setTranscript(transcript);
+ setAssetStatuses((prev) => {
+ const next = { ...prev };
+ delete next[assetId];
+ return next;
+ });
+ toast.dismiss(`regen-${assetId}`);
+ toast.success("Transcript regenerated");
+ } catch (err) {
+ toast.dismiss(`regen-${assetId}`);
+ toast.error("Transcription failed", {
+ description: err instanceof Error ? err.message : String(err),
+ });
+ setAssetStatuses((prev) => ({ ...prev, [assetId]: "failed" }));
+ }
+ },
+ [setTranscript],
+ );
+
const handleLoadLegacyProject = useCallback(async () => {
try {
const result = await window.electronAPI?.loadProjectFile();
@@ -858,7 +892,11 @@ export function NewEditorShell() {
{/* Left content panel */}
{!leftCollapsed ? (
<div className={styles.leftPanel}>
- <LeftPanel active={leftTab} assetStatuses={assetStatuses} />
+ <LeftPanel
+ active={leftTab}
+ assetStatuses={assetStatuses}
+ onRegenerateAsset={handleRegenerateAsset}
+ />
</div>
) : null}
diff --git a/src/lib/ai-edition/document/transcribe.test.ts b/src/lib/ai-edition/document/transcribe.test.ts
new file mode 100644
index 000000000..36938b47c
--- /dev/null
+++ b/src/lib/ai-edition/document/transcribe.test.ts
@@ -0,0 +1,74 @@
+import { describe, expect, it } from "vitest";
+import type { AxcutTranscript } from "../schema";
+import { toAxcutTranscriptDsl } from "./transcribe";
+
+describe("toAxcutTranscriptDsl", () => {
+ it("emits the AXCUT_TRANSCRIPT v1 header + META + segments + words", () => {
+ const transcript: AxcutTranscript = {
+ assetId: "asset_1",
+ language: "en",
+ segments: [
+ {
+ id: "seg_1",
+ kind: "speech",
+ startSec: 0,
+ endSec: 1.2,
+ text: "okay so let's",
+ wordIds: ["word_1", "word_2", "word_3"],
+ },
+ ],
+ words: [
+ { id: "word_1", segmentId: "seg_1", startSec: 0, endSec: 0.4, text: "okay" },
+ { id: "word_2", segmentId: "seg_1", startSec: 0.4, endSec: 0.7, text: "so" },
+ { id: "word_3", segmentId: "seg_1", startSec: 0.7, endSec: 1.2, text: "let's" },
+ ],
+ };
+
+ const dsl = toAxcutTranscriptDsl(transcript, "demo.mp4", 1.2);
+ const lines = dsl.split("\n");
+
+ expect(lines[0]).toBe("AXCUT_TRANSCRIPT v1");
+ expect(lines[1]).toBe(
+ 'META source_video="demo.mp4" duration=1.200 language="en" kind="source"',
+ );
+ expect(lines).toContain(`SEGMENT id=s0001 start=0.000 end=1.200 text="okay so let''s"`);
+ expect(lines).toContain('WORD id=w000001 segment=s0001 start=0.000 end=0.400 text="okay"');
+ expect(lines).toContain('WORD id=w000002 segment=s0001 start=0.400 end=0.700 text="so"');
+ expect(lines).toContain(`WORD id=w000003 segment=s0001 start=0.700 end=1.200 text="let''s"`);
+ expect(lines.at(-1)).toBe("ENDSEGMENT");
+ });
+
+ it("escapes quotes in segment/word text (both kinds)", () => {
+ const transcript: AxcutTranscript = {
+ assetId: "asset_1",
+ language: "auto",
+ segments: [
+ {
+ id: "seg_1",
+ kind: "speech",
+ startSec: 0,
+ endSec: 1,
+ text: 'he said "hi"',
+ wordIds: ["word_1"],
+ },
+ ],
+ words: [{ id: "word_1", segmentId: "seg_1", startSec: 0, endSec: 1, text: "let's" }],
+ };
+
+ const dsl = toAxcutTranscriptDsl(transcript);
+ expect(dsl).toContain(`text="he said ""hi"""`);
+ expect(dsl).toContain(`text="let''s"`);
+ });
+
+ it("omits duration when not provided", () => {
+ const transcript: AxcutTranscript = {
+ assetId: "asset_1",
+ language: "fr",
+ segments: [],
+ words: [],
+ };
+
+ const dsl = toAxcutTranscriptDsl(transcript, "x.mp4");
+ expect(dsl).toBe('AXCUT_TRANSCRIPT v1\nMETA source_video="x.mp4" language="fr" kind="source"');
+ });
+});
diff --git a/src/lib/ai-edition/document/transcribe.ts b/src/lib/ai-edition/document/transcribe.ts
index 725f507d6..cc9cefa25 100644
--- a/src/lib/ai-edition/document/transcribe.ts
+++ b/src/lib/ai-edition/document/transcribe.ts
@@ -82,6 +82,52 @@ export async function transcribeAsset(
};
}
+// ponytail: emit the upstream `AXCUT_TRANSCRIPT v1` plain-text DSL for display
+// in the Source Transcript modal. Mirrors `axcut_core/dsl.py` just enough for
+// the modal's <pre> body — a small segment/word loop, no Python needed. The
+// runtime still uses the structured `AxcutTranscript`; this string is the
+// "what the user reads" view of the same data.
+// Escape both single and double quotes — the DSL wraps every string in
+// double quotes and uses SQL/Python-style `''` doubling for an embedded
+// single quote.
+function escapeDslString(s: string): string {
+ return s.replace(/"/g, '""').replace(/'/g, "''");
+}
+
+export function toAxcutTranscriptDsl(
+ transcript: AxcutTranscript,
+ sourceLabel?: string,
+ durationSec?: number,
+): string {
+ const lines: string[] = ["AXCUT_TRANSCRIPT v1"];
+ const meta: string[] = [];
+ if (sourceLabel) meta.push(`source_video="${sourceLabel}"`);
+ if (typeof durationSec === "number" && Number.isFinite(durationSec)) {
+ meta.push(`duration=${durationSec.toFixed(3)}`);
+ }
+ meta.push(`language="${transcript.language || "auto"}"`, `kind="source"`);
+ lines.push(`META ${meta.join(" ")}`);
+
+ const segIndexById = new Map<string, number>();
+ transcript.segments.forEach((seg, i) => segIndexById.set(seg.id, i + 1));
+
+ for (const seg of transcript.segments) {
+ lines.push(
+ `SEGMENT id=s${String(segIndexById.get(seg.id) ?? 0).padStart(4, "0")} start=${seg.startSec.toFixed(3)} end=${seg.endSec.toFixed(3)} text="${escapeDslString(seg.text)}"`,
+ );
+ for (const wordId of seg.wordIds) {
+ const word = transcript.words.find((w) => w.id === wordId);
+ if (!word) continue;
+ const wSegIdx = segIndexById.get(word.segmentId) ?? 0;
+ lines.push(
+ `WORD id=w${String(transcript.words.indexOf(word) + 1).padStart(6, "0")} segment=s${String(wSegIdx).padStart(4, "0")} start=${word.startSec.toFixed(3)} end=${word.endSec.toFixed(3)} text="${escapeDslString(word.text)}"`,
+ );
+ }
+ lines.push("ENDSEGMENT");
+ }
+ return lines.join("\n");
+}
+
export function withTranscript(
document: AxcutDocument,
transcript: AxcutTranscript,