// Dev sanity check for the audio segmenter. Run: npx tsx scripts/test-segment.ts import { segmentTurns, splitLongText, flattenTurns } from "@/lib/ai/pipeline/segment"; import type { StructuredScript } from "@/lib/ai/types"; const turns = [ { text: "Hello and welcome to the show.", voiceId: "A" }, { text: "x".repeat(2500), voiceId: "B" }, // oversized single turn { text: "Thanks for having me.", voiceId: "A" }, { text: "Let's dive in.", voiceId: "A" }, ]; const segs = segmentTurns(turns, 1800); console.log(`segmentTurns -> ${segs.length} segments`); segs.forEach((s, i) => console.log(` #${i}: chars=${s.characters} voices=${s.uniqueVoices} turns=${s.turns.length}`) ); const parts = splitLongText("One. Two. Three. " + "w".repeat(40), 15); console.log(`splitLongText -> ${parts.length} parts (max len ${Math.max(...parts.map((p) => p.length))})`); const script: StructuredScript = { title: "T", sections: [ { id: "a", title: "A", turns: [{ speakerKey: "host", text: "Hi" }, { speakerKey: "ghost", text: "" }] }, { id: "b", title: "B", turns: [{ speakerKey: "guest", text: "Hello" }] }, ], }; const flat = flattenTurns(script, { host: "V1", guest: "V2" }, "V1"); console.log(`flattenTurns -> ${flat.length} turns (empty dropped), voices: ${flat.map((t) => t.voiceId).join(",")}`); const allUnder = segs.every((s) => s.characters <= 1800); console.log(allUnder ? "PASS: all segments within limit" : "FAIL: a segment exceeds the limit");